@graphql-tools/schema 7.1.0-alpha-796c16fa.0 → 7.1.2
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/buildSchemaFromTypeDefinitions.d.ts +1 -2
- package/checkForResolveTypeResolver.d.ts +1 -1
- package/concatenateTypeDefs.d.ts +1 -1
- package/es5/buildSchemaFromTypeDefinitions.d.ts +1 -2
- package/es5/checkForResolveTypeResolver.d.ts +1 -1
- package/es5/concatenateTypeDefs.d.ts +1 -1
- package/es5/extensionDefinitions.d.ts +14 -2
- package/es5/index.cjs.js +86 -64
- package/es5/index.cjs.js.map +1 -1
- package/es5/index.d.ts +1 -1
- package/es5/index.esm.js +86 -65
- package/es5/index.esm.js.map +1 -1
- package/es5/makeExecutableSchema.d.ts +1 -1
- package/es5/package.json +2 -2
- package/es5/types.d.ts +10 -1
- package/extensionDefinitions.d.ts +14 -2
- package/index.cjs.js +85 -63
- package/index.cjs.js.map +1 -1
- package/index.d.ts +1 -1
- package/index.esm.js +85 -64
- package/index.esm.js.map +1 -1
- package/makeExecutableSchema.d.ts +1 -1
- package/package.json +2 -2
- package/types.d.ts +10 -1
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { GraphQLSchema, DocumentNode } from 'graphql';
|
|
2
2
|
import { ITypeDefinitions, GraphQLParseOptions } from '@graphql-tools/utils';
|
|
3
|
-
export declare function buildSchemaFromTypeDefinitions(typeDefinitions: ITypeDefinitions, parseOptions?: GraphQLParseOptions): GraphQLSchema;
|
|
4
|
-
export declare function isDocumentNode(typeDefinitions: ITypeDefinitions): typeDefinitions is DocumentNode;
|
|
3
|
+
export declare function buildSchemaFromTypeDefinitions(typeDefinitions: ITypeDefinitions, parseOptions?: GraphQLParseOptions, noExtensionExtraction?: boolean): GraphQLSchema;
|
|
5
4
|
export declare function buildDocumentFromTypeDefinitions(typeDefinitions: ITypeDefinitions, parseOptions?: GraphQLParseOptions): DocumentNode;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { GraphQLSchema } from 'graphql';
|
|
2
2
|
import { ValidatorBehavior } from '@graphql-tools/utils';
|
|
3
|
-
export declare function checkForResolveTypeResolver(schema: GraphQLSchema, requireResolversForResolveType
|
|
3
|
+
export declare function checkForResolveTypeResolver(schema: GraphQLSchema, requireResolversForResolveType: ValidatorBehavior): void;
|
package/concatenateTypeDefs.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { ITypedef } from '@graphql-tools/utils';
|
|
2
|
-
export declare function concatenateTypeDefs(typeDefinitionsAry: Array<ITypedef>, calledFunctionRefs?:
|
|
2
|
+
export declare function concatenateTypeDefs(typeDefinitionsAry: Array<ITypedef>, calledFunctionRefs?: Set<ITypedef>): string;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { GraphQLSchema, DocumentNode } from 'graphql';
|
|
2
2
|
import { ITypeDefinitions, GraphQLParseOptions } from '@graphql-tools/utils';
|
|
3
|
-
export declare function buildSchemaFromTypeDefinitions(typeDefinitions: ITypeDefinitions, parseOptions?: GraphQLParseOptions): GraphQLSchema;
|
|
4
|
-
export declare function isDocumentNode(typeDefinitions: ITypeDefinitions): typeDefinitions is DocumentNode;
|
|
3
|
+
export declare function buildSchemaFromTypeDefinitions(typeDefinitions: ITypeDefinitions, parseOptions?: GraphQLParseOptions, noExtensionExtraction?: boolean): GraphQLSchema;
|
|
5
4
|
export declare function buildDocumentFromTypeDefinitions(typeDefinitions: ITypeDefinitions, parseOptions?: GraphQLParseOptions): DocumentNode;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { GraphQLSchema } from 'graphql';
|
|
2
2
|
import { ValidatorBehavior } from '@graphql-tools/utils';
|
|
3
|
-
export declare function checkForResolveTypeResolver(schema: GraphQLSchema, requireResolversForResolveType
|
|
3
|
+
export declare function checkForResolveTypeResolver(schema: GraphQLSchema, requireResolversForResolveType: ValidatorBehavior): void;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { ITypedef } from '@graphql-tools/utils';
|
|
2
|
-
export declare function concatenateTypeDefs(typeDefinitionsAry: Array<ITypedef>, calledFunctionRefs?:
|
|
2
|
+
export declare function concatenateTypeDefs(typeDefinitionsAry: Array<ITypedef>, calledFunctionRefs?: Set<ITypedef>): string;
|
|
@@ -1,10 +1,22 @@
|
|
|
1
1
|
import { DocumentNode, DefinitionNode } from 'graphql';
|
|
2
|
-
export declare function
|
|
2
|
+
export declare function filterAndExtractExtensionDefinitions(ast: DocumentNode): {
|
|
3
|
+
typesAst: {
|
|
4
|
+
definitions: DefinitionNode[];
|
|
5
|
+
kind: "Document";
|
|
6
|
+
loc?: import("graphql").Location;
|
|
7
|
+
};
|
|
8
|
+
extensionsAst: {
|
|
9
|
+
definitions: DefinitionNode[];
|
|
10
|
+
kind: "Document";
|
|
11
|
+
loc?: import("graphql").Location;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
export declare function filterExtensionDefinitions(ast: DocumentNode): {
|
|
3
15
|
definitions: DefinitionNode[];
|
|
4
16
|
kind: "Document";
|
|
5
17
|
loc?: import("graphql").Location;
|
|
6
18
|
};
|
|
7
|
-
export declare function
|
|
19
|
+
export declare function extractExtensionDefinitions(ast: DocumentNode): {
|
|
8
20
|
definitions: DefinitionNode[];
|
|
9
21
|
kind: "Document";
|
|
10
22
|
loc?: import("graphql").Location;
|
package/es5/index.cjs.js
CHANGED
|
@@ -146,74 +146,77 @@ function attachDirectiveResolvers(schema, directiveResolvers) {
|
|
|
146
146
|
_a));
|
|
147
147
|
}
|
|
148
148
|
|
|
149
|
-
function
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
149
|
+
var isExtensionNode = function (def) {
|
|
150
|
+
return def.kind === graphql.Kind.OBJECT_TYPE_EXTENSION ||
|
|
151
|
+
def.kind === graphql.Kind.INTERFACE_TYPE_EXTENSION ||
|
|
152
|
+
def.kind === graphql.Kind.INPUT_OBJECT_TYPE_EXTENSION ||
|
|
153
|
+
def.kind === graphql.Kind.UNION_TYPE_EXTENSION ||
|
|
154
|
+
def.kind === graphql.Kind.ENUM_TYPE_EXTENSION ||
|
|
155
|
+
def.kind === graphql.Kind.SCALAR_TYPE_EXTENSION ||
|
|
156
|
+
def.kind === graphql.Kind.SCHEMA_EXTENSION;
|
|
157
|
+
};
|
|
158
|
+
function filterAndExtractExtensionDefinitions(ast) {
|
|
159
|
+
var extensionDefs = [];
|
|
160
|
+
var typesDefs = [];
|
|
161
|
+
ast.definitions.forEach(function (def) {
|
|
162
|
+
if (isExtensionNode(def)) {
|
|
163
|
+
extensionDefs.push(def);
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
typesDefs.push(def);
|
|
167
|
+
}
|
|
158
168
|
});
|
|
159
|
-
return
|
|
169
|
+
return {
|
|
170
|
+
typesAst: tslib.__assign(tslib.__assign({}, ast), { definitions: typesDefs }),
|
|
171
|
+
extensionsAst: tslib.__assign(tslib.__assign({}, ast), { definitions: extensionDefs }),
|
|
172
|
+
};
|
|
160
173
|
}
|
|
161
174
|
function filterExtensionDefinitions(ast) {
|
|
162
|
-
var
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
def.kind !== graphql.Kind.SCALAR_TYPE_EXTENSION &&
|
|
169
|
-
def.kind !== graphql.Kind.SCHEMA_EXTENSION;
|
|
170
|
-
});
|
|
171
|
-
return tslib.__assign(tslib.__assign({}, ast), { definitions: extensionDefs });
|
|
175
|
+
var typesAst = filterAndExtractExtensionDefinitions(ast).typesAst;
|
|
176
|
+
return typesAst;
|
|
177
|
+
}
|
|
178
|
+
function extractExtensionDefinitions(ast) {
|
|
179
|
+
var extensionsAst = filterAndExtractExtensionDefinitions(ast).extensionsAst;
|
|
180
|
+
return extensionsAst;
|
|
172
181
|
}
|
|
173
182
|
|
|
174
183
|
function concatenateTypeDefs(typeDefinitionsAry, calledFunctionRefs) {
|
|
175
|
-
if (calledFunctionRefs === void 0) { calledFunctionRefs =
|
|
176
|
-
var resolvedTypeDefinitions =
|
|
184
|
+
if (calledFunctionRefs === void 0) { calledFunctionRefs = new Set(); }
|
|
185
|
+
var resolvedTypeDefinitions = new Set();
|
|
177
186
|
typeDefinitionsAry.forEach(function (typeDef) {
|
|
178
187
|
if (typeof typeDef === 'function') {
|
|
179
|
-
if (calledFunctionRefs.
|
|
180
|
-
calledFunctionRefs.
|
|
181
|
-
resolvedTypeDefinitions
|
|
188
|
+
if (!calledFunctionRefs.has(typeDef)) {
|
|
189
|
+
calledFunctionRefs.add(typeDef);
|
|
190
|
+
resolvedTypeDefinitions.add(concatenateTypeDefs(typeDef(), calledFunctionRefs));
|
|
182
191
|
}
|
|
183
192
|
}
|
|
184
193
|
else if (typeof typeDef === 'string') {
|
|
185
|
-
resolvedTypeDefinitions.
|
|
194
|
+
resolvedTypeDefinitions.add(typeDef.trim());
|
|
186
195
|
}
|
|
187
196
|
else if (typeDef.kind !== undefined) {
|
|
188
|
-
resolvedTypeDefinitions.
|
|
197
|
+
resolvedTypeDefinitions.add(graphql.print(typeDef).trim());
|
|
189
198
|
}
|
|
190
199
|
else {
|
|
191
200
|
var type = typeof typeDef;
|
|
192
201
|
throw new Error("typeDef array must contain only strings, documents, or functions, got " + type);
|
|
193
202
|
}
|
|
194
203
|
});
|
|
195
|
-
return
|
|
196
|
-
}
|
|
197
|
-
function uniq(array) {
|
|
198
|
-
return array.reduce(function (accumulator, currentValue) {
|
|
199
|
-
return accumulator.indexOf(currentValue) === -1 ? tslib.__spread(accumulator, [currentValue]) : accumulator;
|
|
200
|
-
}, []);
|
|
204
|
+
return tslib.__spread(resolvedTypeDefinitions).join('\n');
|
|
201
205
|
}
|
|
202
206
|
|
|
203
|
-
function buildSchemaFromTypeDefinitions(typeDefinitions, parseOptions) {
|
|
207
|
+
function buildSchemaFromTypeDefinitions(typeDefinitions, parseOptions, noExtensionExtraction) {
|
|
204
208
|
var document = buildDocumentFromTypeDefinitions(typeDefinitions, parseOptions);
|
|
205
|
-
|
|
209
|
+
if (noExtensionExtraction) {
|
|
210
|
+
return graphql.buildASTSchema(document);
|
|
211
|
+
}
|
|
212
|
+
var _a = filterAndExtractExtensionDefinitions(document), typesAst = _a.typesAst, extensionsAst = _a.extensionsAst;
|
|
206
213
|
var backcompatOptions = { commentDescriptions: true };
|
|
207
214
|
var schema = graphql.buildASTSchema(typesAst, backcompatOptions);
|
|
208
|
-
var extensionsAst = extractExtensionDefinitions(document);
|
|
209
215
|
if (extensionsAst.definitions.length > 0) {
|
|
210
216
|
schema = graphql.extendSchema(schema, extensionsAst, backcompatOptions);
|
|
211
217
|
}
|
|
212
218
|
return schema;
|
|
213
219
|
}
|
|
214
|
-
function isDocumentNode(typeDefinitions) {
|
|
215
|
-
return typeDefinitions.kind !== undefined;
|
|
216
|
-
}
|
|
217
220
|
function buildDocumentFromTypeDefinitions(typeDefinitions, parseOptions) {
|
|
218
221
|
var document;
|
|
219
222
|
if (typeof typeDefinitions === 'string') {
|
|
@@ -222,7 +225,7 @@ function buildDocumentFromTypeDefinitions(typeDefinitions, parseOptions) {
|
|
|
222
225
|
else if (Array.isArray(typeDefinitions)) {
|
|
223
226
|
document = utils.parseGraphQLSDL('', concatenateTypeDefs(typeDefinitions), parseOptions).document;
|
|
224
227
|
}
|
|
225
|
-
else if (isDocumentNode(typeDefinitions)) {
|
|
228
|
+
else if (utils.isDocumentNode(typeDefinitions)) {
|
|
226
229
|
document = typeDefinitions;
|
|
227
230
|
}
|
|
228
231
|
else {
|
|
@@ -289,7 +292,7 @@ function checkForResolveTypeResolver(schema, requireResolversForResolveType) {
|
|
|
289
292
|
var _a;
|
|
290
293
|
utils.mapSchema(schema, (_a = {},
|
|
291
294
|
_a[utils.MapperKind.ABSTRACT_TYPE] = function (type) {
|
|
292
|
-
if (!type.resolveType
|
|
295
|
+
if (!type.resolveType) {
|
|
293
296
|
var message = "Type \"" + type.name + "\" is missing a \"__resolveType\" resolver. Pass 'ignore' into " +
|
|
294
297
|
'"resolverValidationOptions.requireResolversForResolveType" to disable this error.';
|
|
295
298
|
if (requireResolversForResolveType === 'error') {
|
|
@@ -419,7 +422,9 @@ function addResolversToSchema(schemaOrOptions, legacyInputResolvers, legacyInput
|
|
|
419
422
|
schema = updateResolversInPlace
|
|
420
423
|
? addResolversToExistingSchema(schema, resolvers, defaultFieldResolver)
|
|
421
424
|
: createNewSchemaWithResolvers(schema, resolvers, defaultFieldResolver);
|
|
422
|
-
|
|
425
|
+
if (requireResolversForResolveType || requireResolversForResolveType !== 'ignore') {
|
|
426
|
+
checkForResolveTypeResolver(schema, requireResolversForResolveType);
|
|
427
|
+
}
|
|
423
428
|
return schema;
|
|
424
429
|
}
|
|
425
430
|
function addResolversToExistingSchema(schema, resolvers, defaultFieldResolver) {
|
|
@@ -720,7 +725,7 @@ function addCatchUndefinedToSchema(schema) {
|
|
|
720
725
|
* ```
|
|
721
726
|
*/
|
|
722
727
|
function makeExecutableSchema(_a) {
|
|
723
|
-
var typeDefs = _a.typeDefs, _b = _a.resolvers, resolvers = _b === void 0 ? {} : _b, logger = _a.logger, _c = _a.allowUndefinedInResolve, allowUndefinedInResolve = _c === void 0 ? true : _c, _d = _a.resolverValidationOptions, resolverValidationOptions = _d === void 0 ? {} : _d, directiveResolvers = _a.directiveResolvers, schemaDirectives = _a.schemaDirectives,
|
|
728
|
+
var typeDefs = _a.typeDefs, _b = _a.resolvers, resolvers = _b === void 0 ? {} : _b, logger = _a.logger, _c = _a.allowUndefinedInResolve, allowUndefinedInResolve = _c === void 0 ? true : _c, _d = _a.resolverValidationOptions, resolverValidationOptions = _d === void 0 ? {} : _d, directiveResolvers = _a.directiveResolvers, schemaDirectives = _a.schemaDirectives, userProvidedSchemaTransforms = _a.schemaTransforms, _e = _a.parseOptions, parseOptions = _e === void 0 ? {} : _e, _f = _a.inheritResolversFromInterfaces, inheritResolversFromInterfaces = _f === void 0 ? false : _f, pruningOptions = _a.pruningOptions, _g = _a.updateResolversInPlace, updateResolversInPlace = _g === void 0 ? false : _g, _h = _a.noExtensionExtraction, noExtensionExtraction = _h === void 0 ? false : _h;
|
|
724
729
|
// Validate and clean up arguments
|
|
725
730
|
if (typeof resolverValidationOptions !== 'object') {
|
|
726
731
|
throw new Error('Expected `resolverValidationOptions` to be an object');
|
|
@@ -728,42 +733,58 @@ function makeExecutableSchema(_a) {
|
|
|
728
733
|
if (!typeDefs) {
|
|
729
734
|
throw new Error('Must provide typeDefs');
|
|
730
735
|
}
|
|
731
|
-
// We allow passing in an array of resolver maps, in which case we merge them
|
|
732
|
-
var resolverMap = Array.isArray(resolvers) ? resolvers.reduce(utils.mergeDeep, {}) : resolvers;
|
|
733
736
|
// Arguments are now validated and cleaned up
|
|
734
|
-
var
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
737
|
+
var schemaTransforms = [
|
|
738
|
+
function (schema) {
|
|
739
|
+
// We allow passing in an array of resolver maps, in which case we merge them
|
|
740
|
+
var resolverMap = Array.isArray(resolvers) ? resolvers.reduce(utils.mergeDeep, {}) : resolvers;
|
|
741
|
+
var schemaWithResolvers = addResolversToSchema({
|
|
742
|
+
schema: schema,
|
|
743
|
+
resolvers: resolverMap,
|
|
744
|
+
resolverValidationOptions: resolverValidationOptions,
|
|
745
|
+
inheritResolversFromInterfaces: inheritResolversFromInterfaces,
|
|
746
|
+
updateResolversInPlace: updateResolversInPlace,
|
|
747
|
+
});
|
|
748
|
+
if (Object.keys(resolverValidationOptions).length > 0) {
|
|
749
|
+
assertResolversPresent(schemaWithResolvers, resolverValidationOptions);
|
|
750
|
+
}
|
|
751
|
+
return schemaWithResolvers;
|
|
752
|
+
},
|
|
753
|
+
];
|
|
744
754
|
if (!allowUndefinedInResolve) {
|
|
745
|
-
|
|
755
|
+
schemaTransforms.push(addCatchUndefinedToSchema);
|
|
746
756
|
}
|
|
747
757
|
if (logger != null) {
|
|
748
|
-
schema
|
|
758
|
+
schemaTransforms.push(function (schema) { return addErrorLoggingToSchema(schema, logger); });
|
|
749
759
|
}
|
|
750
760
|
if (typeof resolvers['__schema'] === 'function') {
|
|
751
761
|
// TODO a bit of a hack now, better rewrite generateSchema to attach it there.
|
|
752
762
|
// not doing that now, because I'd have to rewrite a lot of tests.
|
|
753
|
-
|
|
763
|
+
schemaTransforms.push(function (schema) {
|
|
764
|
+
return addSchemaLevelResolver(schema, resolvers['__schema']);
|
|
765
|
+
});
|
|
766
|
+
}
|
|
767
|
+
if (userProvidedSchemaTransforms) {
|
|
768
|
+
schemaTransforms.push(function (schema) {
|
|
769
|
+
return userProvidedSchemaTransforms.reduce(function (s, schemaTransform) { return schemaTransform(s); }, schema);
|
|
770
|
+
});
|
|
754
771
|
}
|
|
755
|
-
schemaTransforms.forEach(function (schemaTransform) {
|
|
756
|
-
schema = schemaTransform(schema);
|
|
757
|
-
});
|
|
758
772
|
// directive resolvers are implemented using SchemaDirectiveVisitor.visitSchemaDirectives
|
|
759
773
|
// schema visiting modifies the schema in place
|
|
760
774
|
if (directiveResolvers != null) {
|
|
761
|
-
schema
|
|
775
|
+
schemaTransforms.push(function (schema) { return attachDirectiveResolvers(schema, directiveResolvers); });
|
|
762
776
|
}
|
|
763
777
|
if (schemaDirectives != null) {
|
|
764
|
-
|
|
778
|
+
schemaTransforms.push(function (schema) {
|
|
779
|
+
utils.SchemaDirectiveVisitor.visitSchemaDirectives(schema, schemaDirectives);
|
|
780
|
+
return schema;
|
|
781
|
+
});
|
|
782
|
+
}
|
|
783
|
+
if (pruningOptions) {
|
|
784
|
+
schemaTransforms.push(utils.pruneSchema);
|
|
765
785
|
}
|
|
766
|
-
|
|
786
|
+
var schemaFromTypeDefs = buildSchemaFromTypeDefinitions(typeDefs, parseOptions, noExtensionExtraction);
|
|
787
|
+
return schemaTransforms.reduce(function (schema, schemaTransform) { return schemaTransform(schema); }, schemaFromTypeDefs);
|
|
767
788
|
}
|
|
768
789
|
|
|
769
790
|
exports.addCatchUndefinedToSchema = addCatchUndefinedToSchema;
|
|
@@ -780,6 +801,7 @@ exports.concatenateTypeDefs = concatenateTypeDefs;
|
|
|
780
801
|
exports.decorateWithLogger = decorateWithLogger;
|
|
781
802
|
exports.extendResolversFromInterfaces = extendResolversFromInterfaces;
|
|
782
803
|
exports.extractExtensionDefinitions = extractExtensionDefinitions;
|
|
804
|
+
exports.filterAndExtractExtensionDefinitions = filterAndExtractExtensionDefinitions;
|
|
783
805
|
exports.filterExtensionDefinitions = filterExtensionDefinitions;
|
|
784
806
|
exports.makeExecutableSchema = makeExecutableSchema;
|
|
785
807
|
//# sourceMappingURL=index.cjs.js.map
|