You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+16-16
Original file line number
Diff line number
Diff line change
@@ -17,11 +17,11 @@ You may find a simple GraphQL server example in the following folder: [examples/
17
17
18
18
## GraphQL schema entrypoints from a file structure
19
19
20
-
When you are using code-first approach in GraphQL Schema construction you may meet with problem when you cannot understand what entrypoints has your schema. And where exactly placed the code which serves this or that entrypoint.
20
+
When you are using code-first approach in GraphQL Schema construction you may face problem when you cannot understand which entrypoints your schema has. And where exactly the code is placed which serve this or that entrypoint.
21
21
22
22

23
23
24
-
`graphql-compose-modules` uses a file-system based schema entrypoint definition (something like does NextJS with its pages concept for routing). You just create folder `schema/` and put inside it the following sub-folders (root directories): `query`, `mutation` and `subscription`. Inside these folders you may put `.js` or `.ts` files with FieldConfigs. Assume you create the following directory structure:
24
+
`graphql-compose-modules` uses a file-system based schema entrypoint definition (something like NextJS does with its pages concept for routing). You just create folder `schema/` and put inside it the following sub-folders (root directories): `query`, `mutation` and `subscription`. Inside these folders you may put `.js` or `.ts` files with FieldConfigs which describes entrypoints. Assume you create the following directory structure:
25
25
26
26
```bash
27
27
schema/
@@ -55,11 +55,11 @@ type Subscription {
55
55
}
56
56
```
57
57
58
-
Ifyouwantrenamefield `articlesList` to `articleList` inyourschema just rename `articlesList.ts` file. If you want to add a new field to Schema – just add a new file to `Query`, `Mutation`, `Subscription` folders. **This simple approach helps you understand entrypoints of your schema without launching the GraphQL server – what you see in folders that you get in GraphQL Schema**.
58
+
Ifyouwantrenamefield `articlesList` to `articles` inyourschema just rename `articlesList.ts` file. If you want to add a new field to Schema – just add a new file to `Query`, `Mutation`, `Subscription` folders. **This simple approach helps you understand entrypoints of your schema without launching the GraphQL server – what you see in folders that you get in GraphQL Schema**.
59
59
60
60
## Describing Entrypoints in files
61
61
62
-
Every Entrypoint (FieldConfig definition) is described in separate file. This file contains all information about input args, output type, resolve function and additional fields like description & deprecationReason. As an example let's create `schema/Query/sum.ts` and put inside the following content:
62
+
Every Entrypoint (FieldConfig definition) is described in a separate file. This file contains information about input args, output type, resolve function and additional fields like description, deprecationReason, extensions. As an example let's create `schema/Query/sum.ts` and put inside the following content:
63
63
64
64
```ts
65
65
export default {
@@ -79,11 +79,11 @@ export default {
79
79
};
80
80
```
81
81
82
-
If you familiar with [graphql-js FieldConfig definition](https://graphql.org/graphql-js/type/#examples) then you may notice that `type` & `args` properties are defined in SDL format. This syntax sugar provided by [graphql-compose](https://github.com/graphql-compose/graphql-compose#examples) package.
82
+
If you are familiar with [graphql-js FieldConfig definition](https://graphql.org/graphql-js/type/#examples) then you may notice that `type` & `args` properties are defined in SDL format. This syntax sugar is provided by [graphql-compose](https://github.com/graphql-compose/graphql-compose#examples) package.
83
83
84
84
## Entrypoints with namespaces for big schemas
85
85
86
-
If your GraphQL Schema has a lot of methods you may create sub-folders for grouping some entrypoints fields according to some Entity or Namespace:
86
+
If your GraphQL Schema has a lot of entrypoints you may create sub-folders for grouping them under Namespaces:
87
87
88
88
```bash
89
89
schema/
@@ -100,7 +100,7 @@ schema/
100
100
...
101
101
```
102
102
103
-
With such structure you will get the following schema. Namespace types `QueryArticles` & `MutationArticles` are created automatically:
103
+
With such structure you will get the following schema – namespace types `QueryArticles` & `MutationArticles` are created automatically:
In `schema` folder create a file `index.ts` with the following content which traverses `query`, `mutation`, `subscription` folders and create `GraphQLSchema` instance for you:
130
+
In `schema` folder create a file `index.ts` with the following content which traverses `query`, `mutation`, `subscription` folders and creates a `GraphQLSchema` instance for you:
131
131
132
132
```ts
133
133
import { buildSchema } from 'graphql-compose-modules';
If you want transform AST of entrypoints (e.g. for adding authorization, logging, tracing) and for merging with another schemas distributed via npm packages – you may use the following advanced way:
153
+
If you want transform AST of entrypoints (e.g. for adding authorization, logging, tracing) and for merging with another schemas distributed via npm packages – you may use the following advanced way for schema construction:
For writing your own transformers you need to use `astVisitor()` method. As an example let's implement `addQueryToMutations` transformer which adds `query: Query` field to all your mutations:
178
+
For writing your own transformers you need to use `astVisitor()` method. For instance let's implement `addQueryToMutations` transformer which adds `query: Query` field to all your mutations:
-`directoryToAst(module: NodeModule, options: DirectoryToAstOptions): AstRootNode` – traverses directories and construct AST for your graphql entrypoints
-`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.
0 commit comments