Skip to content

Commit c6c0ae0

Browse files
committed
feat: add graphql-compose@^8.0.0 to peer dependencies and update other dependencies
1 parent 1e32112 commit c6c0ae0

File tree

7 files changed

+1855
-1378
lines changed

7 files changed

+1855
-1378
lines changed

.eslintrc

-48
This file was deleted.

.eslintrc.js

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
const path = require('path');
2+
3+
module.exports = {
4+
parser: '@typescript-eslint/parser',
5+
plugins: ['@typescript-eslint', 'prettier'],
6+
extends: ['plugin:@typescript-eslint/recommended', 'prettier', 'plugin:prettier/recommended'],
7+
parserOptions: {
8+
sourceType: 'module',
9+
useJSXTextNode: true,
10+
project: [path.resolve(__dirname, 'tsconfig.json')],
11+
},
12+
rules: {
13+
'no-underscore-dangle': 0,
14+
'arrow-body-style': 0,
15+
'no-unused-expressions': 0,
16+
'no-plusplus': 0,
17+
'no-console': 0,
18+
'func-names': 0,
19+
'comma-dangle': [
20+
'error',
21+
{
22+
arrays: 'always-multiline',
23+
objects: 'always-multiline',
24+
imports: 'always-multiline',
25+
exports: 'always-multiline',
26+
functions: 'ignore',
27+
},
28+
],
29+
'no-prototype-builtins': 0,
30+
'prefer-destructuring': 0,
31+
'no-else-return': 0,
32+
'lines-between-class-members': ['error', 'always', { exceptAfterSingleLine: true }],
33+
'@typescript-eslint/explicit-member-accessibility': 0,
34+
'@typescript-eslint/no-explicit-any': 0,
35+
'@typescript-eslint/no-inferrable-types': 0,
36+
'@typescript-eslint/explicit-function-return-type': 0,
37+
'@typescript-eslint/no-use-before-define': 0,
38+
'@typescript-eslint/no-empty-function': 0,
39+
'@typescript-eslint/camelcase': 0,
40+
'@typescript-eslint/ban-ts-comment': 0,
41+
},
42+
env: {
43+
jasmine: true,
44+
jest: true,
45+
},
46+
};

README.md

+16-16
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ You may find a simple GraphQL server example in the following folder: [examples/
1717

1818
## GraphQL schema entrypoints from a file structure
1919

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.
2121

2222
![overview](./docs/diagrams/overview.drawio.svg)
2323

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:
2525

2626
```bash
2727
schema/
@@ -55,11 +55,11 @@ type Subscription {
5555
}
5656
```
5757

58-
If you want rename field `articlesList` to `articleList` in your schema 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+
If you want rename field `articlesList` to `articles` in your schema 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**.
5959

6060
## Describing Entrypoints in files
6161

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:
6363

6464
```ts
6565
export default {
@@ -79,11 +79,11 @@ export default {
7979
};
8080
```
8181

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.
8383

8484
## Entrypoints with namespaces for big schemas
8585

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:
8787

8888
```bash
8989
schema/
@@ -100,7 +100,7 @@ schema/
100100
...
101101
```
102102

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:
104104

105105
```graphql
106106
type Query {
@@ -123,11 +123,11 @@ type MutationArticles {
123123
}
124124
```
125125

126-
You may use sub-folders for `Query` & `Mutation` and all servers supports this feature. But for `Subscription` most current server implementations (eg. [apollo-server](https://www.apollographql.com/docs/apollo-server/data/subscriptions/)) does not support this yet.
126+
You may use namespaces (sub-folders) for `Query` & `Mutation` and all servers supports this feature. But for `Subscription` most current server implementations (eg. [apollo-server](https://www.apollographql.com/docs/apollo-server/data/subscriptions/)) does not support this yet.
127127

128128
## GraphQLSchema construction
129129

130-
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:
131131

132132
```ts
133133
import { buildSchema } from 'graphql-compose-modules';
@@ -150,7 +150,7 @@ server.listen().then(({ url }) => {
150150

151151
## Advanced GraphQLSchema construction
152152

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:
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:
154154

155155
```ts
156156
import { directoryToAst, astToSchema, astMerge } from 'graphql-compose-modules';
@@ -175,7 +175,7 @@ export const schema = sc.buildSchema();
175175

176176
## Writing own transformer for entrypoints
177177

178-
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:
179179

180180
```ts
181181
import { astVisitor, VISITOR_SKIP_CHILDREN, AstRootNode } from 'graphql-compose-modules';
@@ -227,19 +227,19 @@ export function addQueryToMutations(
227227

228228
## API
229229

230-
For now I provide basic overview of available API methods and I will describe them later.
230+
For now here is provided basic overview of the available API methods. Then detailed information will be provided later.
231231

232232
### Main API method:
233233

234-
- `buildSchema(module: NodeModule, opts: BuildOptions): GraphQLSchema` – use this method for creating graphql schema from folder
234+
- `buildSchema(module: NodeModule, opts: BuildOptions): GraphQLSchema` – use this method for creating graphql schema from directory
235235

236236
### Advanced API methods:
237237

238-
The following methods helps to use schema composition, applying middlewares and schema transformation via visitor pattern:
238+
The following methods help to use schema composition, applying middlewares and schema transformation via visitor pattern:
239239

240240
![overview](./docs/diagrams/ast-transformation.drawio.svg)
241241

242242
- `directoryToAst(module: NodeModule, options: DirectoryToAstOptions): AstRootNode` – traverses directories and construct AST for your graphql entrypoints
243243
- `astToSchema(ast: AstRootNode, opts: AstToSchemaOptions): SchemaComposer` – converts AST to GraphQL Schema
244-
- `astMerge(...asts: Array<AstRootNode>): AstRootNode` – combines several ASTs to one AST (helps compose several graphql schemas)
245-
- `astVisitor(ast: AstRootNode, visitor: AstVisitor): void` – modify AST via visitor pattern
244+
- `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

Comments
 (0)