@graphql-codegen/schema-ast 2.3.0 → 2.4.1
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 +20 -3
- package/index.js +20 -6
- package/index.mjs +21 -7
- package/package.json +4 -3
package/index.d.ts
CHANGED
|
@@ -22,7 +22,24 @@ export interface SchemaASTConfig {
|
|
|
22
22
|
*/
|
|
23
23
|
includeDirectives?: boolean;
|
|
24
24
|
/**
|
|
25
|
-
* @description
|
|
25
|
+
* @description Include introspection types to Schema output.
|
|
26
|
+
* @default false
|
|
27
|
+
*
|
|
28
|
+
* @exampleMarkdown
|
|
29
|
+
* ```yml
|
|
30
|
+
* schema:
|
|
31
|
+
* - './src/schema.graphql'
|
|
32
|
+
* generates:
|
|
33
|
+
* path/to/file.graphql:
|
|
34
|
+
* plugins:
|
|
35
|
+
* - schema-ast
|
|
36
|
+
* config:
|
|
37
|
+
* includeIntrospectionTypes: true
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
includeIntrospectionTypes?: boolean;
|
|
41
|
+
/**
|
|
42
|
+
* @description Set to true in order to print description as comments (using `#` instead of `"""`)
|
|
26
43
|
* @default false
|
|
27
44
|
*
|
|
28
45
|
* @exampleMarkdown
|
|
@@ -38,8 +55,8 @@ export interface SchemaASTConfig {
|
|
|
38
55
|
*/
|
|
39
56
|
commentDescriptions?: boolean;
|
|
40
57
|
/**
|
|
41
|
-
* @description Set to
|
|
42
|
-
* @default
|
|
58
|
+
* @description Set to false to disable sorting
|
|
59
|
+
* @default true
|
|
43
60
|
*/
|
|
44
61
|
sort?: boolean;
|
|
45
62
|
federation?: boolean;
|
package/index.js
CHANGED
|
@@ -6,12 +6,16 @@ const graphql = require('graphql');
|
|
|
6
6
|
const pluginHelpers = require('@graphql-codegen/plugin-helpers');
|
|
7
7
|
const path = require('path');
|
|
8
8
|
|
|
9
|
-
const plugin = async (schema, _documents, { commentDescriptions = false, includeDirectives = false, sort = false, federation }) => {
|
|
10
|
-
const transformedSchemaAndAst = transformSchemaAST(schema, { sort, federation });
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
const plugin = async (schema, _documents, { commentDescriptions = false, includeDirectives = false, includeIntrospectionTypes = false, sort = false, federation, }) => {
|
|
10
|
+
const transformedSchemaAndAst = transformSchemaAST(schema, { sort, federation, includeIntrospectionTypes });
|
|
11
|
+
return [
|
|
12
|
+
includeIntrospectionTypes ? graphql.printIntrospectionSchema(transformedSchemaAndAst.schema) : null,
|
|
13
|
+
includeDirectives
|
|
14
|
+
? graphql.print(transformedSchemaAndAst.ast)
|
|
15
|
+
: graphql.printSchema(transformedSchemaAndAst.schema, { commentDescriptions }),
|
|
16
|
+
]
|
|
17
|
+
.filter(Boolean)
|
|
18
|
+
.join('\n');
|
|
15
19
|
};
|
|
16
20
|
const validate = async (_schema, _documents, _config, outputFile, allPlugins) => {
|
|
17
21
|
const singlePlugin = allPlugins.length === 1;
|
|
@@ -21,6 +25,16 @@ const validate = async (_schema, _documents, _config, outputFile, allPlugins) =>
|
|
|
21
25
|
};
|
|
22
26
|
function transformSchemaAST(schema, config) {
|
|
23
27
|
schema = config.federation ? pluginHelpers.removeFederation(schema) : schema;
|
|
28
|
+
if (config.includeIntrospectionTypes) {
|
|
29
|
+
// See: https://spec.graphql.org/June2018/#sec-Schema-Introspection
|
|
30
|
+
const introspectionAST = graphql.parse(`
|
|
31
|
+
extend type Query {
|
|
32
|
+
__schema: __Schema!
|
|
33
|
+
__type(name: String!): __Type
|
|
34
|
+
}
|
|
35
|
+
`);
|
|
36
|
+
schema = graphql.extendSchema(schema, introspectionAST);
|
|
37
|
+
}
|
|
24
38
|
let ast = pluginHelpers.getCachedDocumentNodeFromSchema(schema);
|
|
25
39
|
ast = config.disableDescriptions
|
|
26
40
|
? graphql.visit(ast, {
|
package/index.mjs
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
|
-
import { print, printSchema, visit, buildASTSchema } from 'graphql';
|
|
1
|
+
import { printIntrospectionSchema, print, printSchema, parse, extendSchema, visit, buildASTSchema } from 'graphql';
|
|
2
2
|
import { removeFederation, getCachedDocumentNodeFromSchema } from '@graphql-codegen/plugin-helpers';
|
|
3
3
|
import { extname } from 'path';
|
|
4
4
|
|
|
5
|
-
const plugin = async (schema, _documents, { commentDescriptions = false, includeDirectives = false, sort = false, federation }) => {
|
|
6
|
-
const transformedSchemaAndAst = transformSchemaAST(schema, { sort, federation });
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
const plugin = async (schema, _documents, { commentDescriptions = false, includeDirectives = false, includeIntrospectionTypes = false, sort = false, federation, }) => {
|
|
6
|
+
const transformedSchemaAndAst = transformSchemaAST(schema, { sort, federation, includeIntrospectionTypes });
|
|
7
|
+
return [
|
|
8
|
+
includeIntrospectionTypes ? printIntrospectionSchema(transformedSchemaAndAst.schema) : null,
|
|
9
|
+
includeDirectives
|
|
10
|
+
? print(transformedSchemaAndAst.ast)
|
|
11
|
+
: printSchema(transformedSchemaAndAst.schema, { commentDescriptions }),
|
|
12
|
+
]
|
|
13
|
+
.filter(Boolean)
|
|
14
|
+
.join('\n');
|
|
11
15
|
};
|
|
12
16
|
const validate = async (_schema, _documents, _config, outputFile, allPlugins) => {
|
|
13
17
|
const singlePlugin = allPlugins.length === 1;
|
|
@@ -17,6 +21,16 @@ const validate = async (_schema, _documents, _config, outputFile, allPlugins) =>
|
|
|
17
21
|
};
|
|
18
22
|
function transformSchemaAST(schema, config) {
|
|
19
23
|
schema = config.federation ? removeFederation(schema) : schema;
|
|
24
|
+
if (config.includeIntrospectionTypes) {
|
|
25
|
+
// See: https://spec.graphql.org/June2018/#sec-Schema-Introspection
|
|
26
|
+
const introspectionAST = parse(`
|
|
27
|
+
extend type Query {
|
|
28
|
+
__schema: __Schema!
|
|
29
|
+
__type(name: String!): __Type
|
|
30
|
+
}
|
|
31
|
+
`);
|
|
32
|
+
schema = extendSchema(schema, introspectionAST);
|
|
33
|
+
}
|
|
20
34
|
let ast = getCachedDocumentNodeFromSchema(schema);
|
|
21
35
|
ast = config.disableDescriptions
|
|
22
36
|
? visit(ast, {
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-codegen/schema-ast",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.1",
|
|
4
4
|
"description": "GraphQL Code Generator plugin for generating a .graphql file from a given schema",
|
|
5
5
|
"peerDependencies": {
|
|
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"
|
|
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 || ^16.0.0"
|
|
7
7
|
},
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@graphql-codegen/plugin-helpers": "^2.3.
|
|
9
|
+
"@graphql-codegen/plugin-helpers": "^2.3.2",
|
|
10
10
|
"@graphql-tools/utils": "^8.1.1",
|
|
11
11
|
"tslib": "~2.3.0"
|
|
12
12
|
},
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
"definition": "index.d.ts"
|
|
24
24
|
},
|
|
25
25
|
"exports": {
|
|
26
|
+
"./package.json": "./package.json",
|
|
26
27
|
".": {
|
|
27
28
|
"require": "./index.js",
|
|
28
29
|
"import": "./index.mjs"
|