@graphql-codegen/schema-ast 2.1.1-alpha-4c7432d34.0 → 2.2.1-alpha-16421e2d7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.d.ts +1 -1
- package/index.js +11 -12
- package/index.mjs +12 -13
- package/package.json +2 -2
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -5,15 +5,13 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
const graphql = require('graphql');
|
|
6
6
|
const pluginHelpers = require('@graphql-codegen/plugin-helpers');
|
|
7
7
|
const path = require('path');
|
|
8
|
-
const utils = require('@graphql-tools/utils');
|
|
9
8
|
|
|
10
9
|
const plugin = async (schema, _documents, { commentDescriptions = false, includeDirectives = false, sort = false, federation }) => {
|
|
11
|
-
|
|
12
|
-
outputSchema = sort ? graphql.lexicographicSortSchema(outputSchema) : outputSchema;
|
|
10
|
+
const transformedSchemaAndAst = transformSchemaAST(schema, { sort, federation });
|
|
13
11
|
if (includeDirectives) {
|
|
14
|
-
return
|
|
12
|
+
return graphql.print(transformedSchemaAndAst.ast);
|
|
15
13
|
}
|
|
16
|
-
return graphql.printSchema(
|
|
14
|
+
return graphql.printSchema(transformedSchemaAndAst.schema, { commentDescriptions: commentDescriptions });
|
|
17
15
|
};
|
|
18
16
|
const validate = async (_schema, _documents, _config, outputFile, allPlugins) => {
|
|
19
17
|
const singlePlugin = allPlugins.length === 1;
|
|
@@ -22,19 +20,20 @@ const validate = async (_schema, _documents, _config, outputFile, allPlugins) =>
|
|
|
22
20
|
}
|
|
23
21
|
};
|
|
24
22
|
function transformSchemaAST(schema, config) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
23
|
+
schema = config.federation ? pluginHelpers.removeFederation(schema) : schema;
|
|
24
|
+
let ast = pluginHelpers.getCachedDocumentNodeFromSchema(schema);
|
|
25
|
+
ast = config.disableDescriptions
|
|
26
|
+
? graphql.visit(ast, {
|
|
28
27
|
leave: node => ({
|
|
29
28
|
...node,
|
|
30
29
|
description: undefined,
|
|
31
30
|
}),
|
|
32
31
|
})
|
|
33
|
-
:
|
|
34
|
-
|
|
32
|
+
: ast;
|
|
33
|
+
schema = config.disableDescriptions ? graphql.buildASTSchema(ast) : schema;
|
|
35
34
|
return {
|
|
36
|
-
schema
|
|
37
|
-
ast
|
|
35
|
+
schema,
|
|
36
|
+
ast,
|
|
38
37
|
};
|
|
39
38
|
}
|
|
40
39
|
|
package/index.mjs
CHANGED
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { print, printSchema, visit, buildASTSchema } from 'graphql';
|
|
2
2
|
import { removeFederation, getCachedDocumentNodeFromSchema } from '@graphql-codegen/plugin-helpers';
|
|
3
3
|
import { extname } from 'path';
|
|
4
|
-
import { printSchemaWithDirectives } from '@graphql-tools/utils';
|
|
5
4
|
|
|
6
5
|
const plugin = async (schema, _documents, { commentDescriptions = false, includeDirectives = false, sort = false, federation }) => {
|
|
7
|
-
|
|
8
|
-
outputSchema = sort ? lexicographicSortSchema(outputSchema) : outputSchema;
|
|
6
|
+
const transformedSchemaAndAst = transformSchemaAST(schema, { sort, federation });
|
|
9
7
|
if (includeDirectives) {
|
|
10
|
-
return
|
|
8
|
+
return print(transformedSchemaAndAst.ast);
|
|
11
9
|
}
|
|
12
|
-
return printSchema(
|
|
10
|
+
return printSchema(transformedSchemaAndAst.schema, { commentDescriptions: commentDescriptions });
|
|
13
11
|
};
|
|
14
12
|
const validate = async (_schema, _documents, _config, outputFile, allPlugins) => {
|
|
15
13
|
const singlePlugin = allPlugins.length === 1;
|
|
@@ -18,19 +16,20 @@ const validate = async (_schema, _documents, _config, outputFile, allPlugins) =>
|
|
|
18
16
|
}
|
|
19
17
|
};
|
|
20
18
|
function transformSchemaAST(schema, config) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
19
|
+
schema = config.federation ? removeFederation(schema) : schema;
|
|
20
|
+
let ast = getCachedDocumentNodeFromSchema(schema);
|
|
21
|
+
ast = config.disableDescriptions
|
|
22
|
+
? visit(ast, {
|
|
24
23
|
leave: node => ({
|
|
25
24
|
...node,
|
|
26
25
|
description: undefined,
|
|
27
26
|
}),
|
|
28
27
|
})
|
|
29
|
-
:
|
|
30
|
-
|
|
28
|
+
: ast;
|
|
29
|
+
schema = config.disableDescriptions ? buildASTSchema(ast) : schema;
|
|
31
30
|
return {
|
|
32
|
-
schema
|
|
33
|
-
ast
|
|
31
|
+
schema,
|
|
32
|
+
ast,
|
|
34
33
|
};
|
|
35
34
|
}
|
|
36
35
|
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-codegen/schema-ast",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.1-alpha-16421e2d7.0",
|
|
4
4
|
"description": "GraphQL Code Generator plugin for generating a .graphql file from a given schema",
|
|
5
5
|
"peerDependencies": {
|
|
6
6
|
"graphql": "^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0"
|
|
7
7
|
},
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@graphql-codegen/plugin-helpers": "2.
|
|
9
|
+
"@graphql-codegen/plugin-helpers": "2.2.0-alpha-16421e2d7.0",
|
|
10
10
|
"@graphql-tools/utils": "^8.1.1",
|
|
11
11
|
"tslib": "~2.3.0"
|
|
12
12
|
},
|