@graphql-codegen/schema-ast 2.4.2-alpha-4a7e799f2.0 → 2.4.2-alpha-2ada7b533.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.js → cjs/index.js} +18 -21
- package/cjs/package.json +1 -0
- package/{index.mjs → esm/index.js} +5 -8
- package/package.json +23 -16
- package/{index.d.ts → typings/index.d.ts} +3 -3
|
@@ -1,56 +1,53 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const path = require('path');
|
|
8
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.transformSchemaAST = exports.validate = exports.plugin = void 0;
|
|
4
|
+
const graphql_1 = require("graphql");
|
|
5
|
+
const plugin_helpers_1 = require("@graphql-codegen/plugin-helpers");
|
|
6
|
+
const path_1 = require("path");
|
|
9
7
|
const plugin = async (schema, _documents, { commentDescriptions = false, includeDirectives = false, includeIntrospectionTypes = false, sort = false, federation, }) => {
|
|
10
8
|
const transformedSchemaAndAst = transformSchemaAST(schema, { sort, federation, includeIntrospectionTypes });
|
|
11
9
|
return [
|
|
12
|
-
includeIntrospectionTypes ?
|
|
10
|
+
includeIntrospectionTypes ? (0, graphql_1.printIntrospectionSchema)(transformedSchemaAndAst.schema) : null,
|
|
13
11
|
includeDirectives
|
|
14
|
-
?
|
|
15
|
-
:
|
|
12
|
+
? (0, graphql_1.print)(transformedSchemaAndAst.ast)
|
|
13
|
+
: graphql_1.printSchema(transformedSchemaAndAst.schema, { commentDescriptions }),
|
|
16
14
|
]
|
|
17
15
|
.filter(Boolean)
|
|
18
16
|
.join('\n');
|
|
19
17
|
};
|
|
18
|
+
exports.plugin = plugin;
|
|
20
19
|
const validate = async (_schema, _documents, _config, outputFile, allPlugins) => {
|
|
21
20
|
const singlePlugin = allPlugins.length === 1;
|
|
22
|
-
if (singlePlugin &&
|
|
21
|
+
if (singlePlugin && (0, path_1.extname)(outputFile) !== '.graphql') {
|
|
23
22
|
throw new Error(`Plugin "schema-ast" requires extension to be ".graphql"!`);
|
|
24
23
|
}
|
|
25
24
|
};
|
|
25
|
+
exports.validate = validate;
|
|
26
26
|
function transformSchemaAST(schema, config) {
|
|
27
|
-
schema = config.federation ?
|
|
27
|
+
schema = config.federation ? (0, plugin_helpers_1.removeFederation)(schema) : schema;
|
|
28
28
|
if (config.includeIntrospectionTypes) {
|
|
29
29
|
// See: https://spec.graphql.org/June2018/#sec-Schema-Introspection
|
|
30
|
-
const introspectionAST =
|
|
30
|
+
const introspectionAST = (0, graphql_1.parse)(`
|
|
31
31
|
extend type Query {
|
|
32
32
|
__schema: __Schema!
|
|
33
33
|
__type(name: String!): __Type
|
|
34
34
|
}
|
|
35
35
|
`);
|
|
36
|
-
schema =
|
|
36
|
+
schema = (0, graphql_1.extendSchema)(schema, introspectionAST);
|
|
37
37
|
}
|
|
38
|
-
let ast =
|
|
38
|
+
let ast = (0, plugin_helpers_1.getCachedDocumentNodeFromSchema)(schema);
|
|
39
39
|
ast = config.disableDescriptions
|
|
40
|
-
?
|
|
40
|
+
? (0, graphql_1.visit)(ast, {
|
|
41
41
|
leave: node => ({
|
|
42
42
|
...node,
|
|
43
43
|
description: undefined,
|
|
44
44
|
}),
|
|
45
45
|
})
|
|
46
46
|
: ast;
|
|
47
|
-
schema = config.disableDescriptions ?
|
|
47
|
+
schema = config.disableDescriptions ? (0, graphql_1.buildASTSchema)(ast) : schema;
|
|
48
48
|
return {
|
|
49
49
|
schema,
|
|
50
50
|
ast,
|
|
51
51
|
};
|
|
52
52
|
}
|
|
53
|
-
|
|
54
|
-
exports.plugin = plugin;
|
|
55
53
|
exports.transformSchemaAST = transformSchemaAST;
|
|
56
|
-
exports.validate = validate;
|
package/cjs/package.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"commonjs"}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { removeFederation, getCachedDocumentNodeFromSchema } from '@graphql-codegen/plugin-helpers';
|
|
1
|
+
import { parse, extendSchema, printIntrospectionSchema, printSchema, visit, buildASTSchema, print, } from 'graphql';
|
|
2
|
+
import { removeFederation, getCachedDocumentNodeFromSchema, } from '@graphql-codegen/plugin-helpers';
|
|
3
3
|
import { extname } from 'path';
|
|
4
|
-
|
|
5
|
-
const plugin = async (schema, _documents, { commentDescriptions = false, includeDirectives = false, includeIntrospectionTypes = false, sort = false, federation, }) => {
|
|
4
|
+
export const plugin = async (schema, _documents, { commentDescriptions = false, includeDirectives = false, includeIntrospectionTypes = false, sort = false, federation, }) => {
|
|
6
5
|
const transformedSchemaAndAst = transformSchemaAST(schema, { sort, federation, includeIntrospectionTypes });
|
|
7
6
|
return [
|
|
8
7
|
includeIntrospectionTypes ? printIntrospectionSchema(transformedSchemaAndAst.schema) : null,
|
|
@@ -13,13 +12,13 @@ const plugin = async (schema, _documents, { commentDescriptions = false, include
|
|
|
13
12
|
.filter(Boolean)
|
|
14
13
|
.join('\n');
|
|
15
14
|
};
|
|
16
|
-
const validate = async (_schema, _documents, _config, outputFile, allPlugins) => {
|
|
15
|
+
export const validate = async (_schema, _documents, _config, outputFile, allPlugins) => {
|
|
17
16
|
const singlePlugin = allPlugins.length === 1;
|
|
18
17
|
if (singlePlugin && extname(outputFile) !== '.graphql') {
|
|
19
18
|
throw new Error(`Plugin "schema-ast" requires extension to be ".graphql"!`);
|
|
20
19
|
}
|
|
21
20
|
};
|
|
22
|
-
function transformSchemaAST(schema, config) {
|
|
21
|
+
export function transformSchemaAST(schema, config) {
|
|
23
22
|
schema = config.federation ? removeFederation(schema) : schema;
|
|
24
23
|
if (config.includeIntrospectionTypes) {
|
|
25
24
|
// See: https://spec.graphql.org/June2018/#sec-Schema-Introspection
|
|
@@ -46,5 +45,3 @@ function transformSchemaAST(schema, config) {
|
|
|
46
45
|
ast,
|
|
47
46
|
};
|
|
48
47
|
}
|
|
49
|
-
|
|
50
|
-
export { plugin, transformSchemaAST, validate };
|
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-codegen/schema-ast",
|
|
3
|
-
"version": "2.4.2-alpha-
|
|
3
|
+
"version": "2.4.2-alpha-2ada7b533.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 || ^16.0.0"
|
|
7
7
|
},
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@graphql-codegen/plugin-helpers": "2.
|
|
10
|
-
"@graphql-tools/utils": "^8.
|
|
11
|
-
"tslib": "~2.
|
|
9
|
+
"@graphql-codegen/plugin-helpers": "^2.5.0-alpha-2ada7b533.0",
|
|
10
|
+
"@graphql-tools/utils": "^8.8.0",
|
|
11
|
+
"tslib": "~2.4.0"
|
|
12
12
|
},
|
|
13
13
|
"repository": {
|
|
14
14
|
"type": "git",
|
|
@@ -16,21 +16,28 @@
|
|
|
16
16
|
"directory": "packages/plugins/other/schema-ast"
|
|
17
17
|
},
|
|
18
18
|
"license": "MIT",
|
|
19
|
-
"main": "index.js",
|
|
20
|
-
"module": "index.
|
|
21
|
-
"typings": "index.d.ts",
|
|
19
|
+
"main": "cjs/index.js",
|
|
20
|
+
"module": "esm/index.js",
|
|
21
|
+
"typings": "typings/index.d.ts",
|
|
22
22
|
"typescript": {
|
|
23
|
-
"definition": "index.d.ts"
|
|
23
|
+
"definition": "typings/index.d.ts"
|
|
24
24
|
},
|
|
25
|
+
"type": "module",
|
|
25
26
|
"exports": {
|
|
26
|
-
"./package.json": "./package.json",
|
|
27
27
|
".": {
|
|
28
|
-
"require":
|
|
29
|
-
|
|
28
|
+
"require": {
|
|
29
|
+
"types": "./typings/index.d.ts",
|
|
30
|
+
"default": "./cjs/index.js"
|
|
31
|
+
},
|
|
32
|
+
"import": {
|
|
33
|
+
"types": "./typings/index.d.ts",
|
|
34
|
+
"default": "./esm/index.js"
|
|
35
|
+
},
|
|
36
|
+
"default": {
|
|
37
|
+
"types": "./typings/index.d.ts",
|
|
38
|
+
"default": "./esm/index.js"
|
|
39
|
+
}
|
|
30
40
|
},
|
|
31
|
-
"
|
|
32
|
-
"require": "./*.js",
|
|
33
|
-
"import": "./*.mjs"
|
|
34
|
-
}
|
|
41
|
+
"./package.json": "./package.json"
|
|
35
42
|
}
|
|
36
|
-
}
|
|
43
|
+
}
|
|
@@ -9,7 +9,7 @@ export interface SchemaASTConfig {
|
|
|
9
9
|
* @default false
|
|
10
10
|
*
|
|
11
11
|
* @exampleMarkdown
|
|
12
|
-
* ```
|
|
12
|
+
* ```yaml
|
|
13
13
|
* schema:
|
|
14
14
|
* - './src/schema.graphql'
|
|
15
15
|
* generates:
|
|
@@ -26,7 +26,7 @@ export interface SchemaASTConfig {
|
|
|
26
26
|
* @default false
|
|
27
27
|
*
|
|
28
28
|
* @exampleMarkdown
|
|
29
|
-
* ```
|
|
29
|
+
* ```yaml
|
|
30
30
|
* schema:
|
|
31
31
|
* - './src/schema.graphql'
|
|
32
32
|
* generates:
|
|
@@ -43,7 +43,7 @@ export interface SchemaASTConfig {
|
|
|
43
43
|
* @default false
|
|
44
44
|
*
|
|
45
45
|
* @exampleMarkdown
|
|
46
|
-
* ```
|
|
46
|
+
* ```yaml
|
|
47
47
|
* schema: http://localhost:3000/graphql
|
|
48
48
|
* generates:
|
|
49
49
|
* schema.graphql:
|