Skip to content

Commit d4df44a

Browse files
committed
docs: update examples according to v2.0.0
1 parent fb15aff commit d4df44a

File tree

1 file changed

+13
-16
lines changed

1 file changed

+13
-16
lines changed

README.md

+13-16
Original file line numberDiff line numberDiff line change
@@ -185,28 +185,27 @@ export function addQueryToMutations(
185185
ast: AstRootNode,
186186
schemaComposer: SchemaComposer<any>
187187
): void {
188-
astVisitor(ast, {
188+
astVisitor(ast, schemaComposer, {
189189
// skip `query` & `subscriptions` root types
190-
ROOT_TYPE: (node) => {
191-
if (node.name !== 'mutation') {
190+
ROOT_TYPE: (info) => {
191+
if (!info.isMutation) {
192192
return VISITOR_SKIP_CHILDREN;
193193
}
194194
return;
195195
},
196196
// for every file in `mutation` folder try to add `query` field if it does not exists
197-
FILE: (node, nodeInfo) => {
198-
const fieldConfig = node.code.default || {};
197+
FILE: (info) => {
198+
// get FieldConfig from loaded file in `schema` folder
199+
const fieldConfig = info.fieldConfig || {};
200+
201+
// if `resolve` method does not exist then skip this transformation
199202
const next = fieldConfig.resolve;
200203
if (!next) return;
201204

202-
const outputType = fieldConfig.type;
203-
if (!outputType) return;
204-
const outputTC = schemaComposer.typeMapper.convertOutputTypeDefinition(
205-
outputType,
206-
nodeInfo.name,
207-
nodeInfo?.parent?.name
208-
);
209-
if (!(outputTC instanceof ObjectTypeComposer)) return;
205+
// if output type isn't an object then skip this transformation
206+
if (!info.isOutputTypeIsObject()) return;
207+
208+
const outputTC = info.getOutputUnwrappedOTC();
210209
if (outputTC.hasField('query')) return;
211210
outputTC.setField('query', {
212211
description: 'Sub-query which have to be executed after mutation.',
@@ -227,8 +226,6 @@ export function addQueryToMutations(
227226

228227
## API
229228

230-
For now here is provided basic overview of the available API methods. Then detailed information will be provided later.
231-
232229
### Main API method:
233230

234231
- `buildSchema(module: NodeModule, opts: BuildOptions): GraphQLSchema` – use this method for creating graphql schema from directory
@@ -242,4 +239,4 @@ The following methods help to use schema composition, applying middlewares and s
242239
- `directoryToAst(module: NodeModule, options: DirectoryToAstOptions): AstRootNode` – traverses directories and construct AST for your graphql entrypoints
243240
- `astToSchema(ast: AstRootNode, opts: AstToSchemaOptions): SchemaComposer` – converts AST to GraphQL Schema
244241
- `astMerge(...asts: Array<AstRootNode>): AstRootNode` – combines several ASTs to one AST (helps compose several graphql schemas which may be distributed via npm packages)
245-
- `astVisitor(ast: AstRootNode, visitor: AstVisitor): void` – modify AST via visitor pattern. This method is used for construction of your AST transformers.
242+
- `astVisitor(ast: AstRootNode, schemaComposer: SchemaComposer, visitor: AstVisitor): void` – modify AST via visitor pattern. This method is used for construction of your AST transformers.

0 commit comments

Comments
 (0)