@graphql-tools/utils 7.7.0-alpha-e3d43765.0 → 7.7.3
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/create-schema-definition.d.ts +8 -0
- package/es5/create-schema-definition.d.ts +8 -0
- package/es5/index.cjs.js +43 -19
- package/es5/index.cjs.js.map +1 -1
- package/es5/index.d.ts +1 -0
- package/es5/index.esm.js +44 -21
- package/es5/index.esm.js.map +1 -1
- package/es5/package.json +2 -2
- package/index.cjs.js +33 -9
- package/index.cjs.js.map +1 -1
- package/index.d.ts +1 -0
- package/index.esm.js +34 -11
- package/index.esm.js.map +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { GraphQLObjectType } from 'graphql';
|
|
2
|
+
export declare function createSchemaDefinition(def: {
|
|
3
|
+
query: string | GraphQLObjectType | null;
|
|
4
|
+
mutation: string | GraphQLObjectType | null;
|
|
5
|
+
subscription: string | GraphQLObjectType | null;
|
|
6
|
+
}, config?: {
|
|
7
|
+
force?: boolean;
|
|
8
|
+
}): string;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { GraphQLObjectType } from 'graphql';
|
|
2
|
+
export declare function createSchemaDefinition(def: {
|
|
3
|
+
query: string | GraphQLObjectType | null;
|
|
4
|
+
mutation: string | GraphQLObjectType | null;
|
|
5
|
+
subscription: string | GraphQLObjectType | null;
|
|
6
|
+
}, config?: {
|
|
7
|
+
force?: boolean;
|
|
8
|
+
}): string;
|
package/es5/index.cjs.js
CHANGED
|
@@ -503,6 +503,23 @@ function getDocumentNodeFromSchema(schema, options) {
|
|
|
503
503
|
var typesMap = schema.getTypeMap();
|
|
504
504
|
var schemaNode = astFromSchema(schema, pathToDirectivesInExtensions);
|
|
505
505
|
var definitions = schemaNode != null ? [schemaNode] : [];
|
|
506
|
+
var directives = schema.getDirectives();
|
|
507
|
+
try {
|
|
508
|
+
for (var directives_1 = tslib.__values(directives), directives_1_1 = directives_1.next(); !directives_1_1.done; directives_1_1 = directives_1.next()) {
|
|
509
|
+
var directive = directives_1_1.value;
|
|
510
|
+
if (graphql.isSpecifiedDirective(directive)) {
|
|
511
|
+
continue;
|
|
512
|
+
}
|
|
513
|
+
definitions.push(astFromDirective(directive, schema, pathToDirectivesInExtensions));
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
517
|
+
finally {
|
|
518
|
+
try {
|
|
519
|
+
if (directives_1_1 && !directives_1_1.done && (_a = directives_1.return)) _a.call(directives_1);
|
|
520
|
+
}
|
|
521
|
+
finally { if (e_1) throw e_1.error; }
|
|
522
|
+
}
|
|
506
523
|
for (var typeName in typesMap) {
|
|
507
524
|
var type = typesMap[typeName];
|
|
508
525
|
var isPredefinedScalar = graphql.isSpecifiedScalarType(type);
|
|
@@ -532,23 +549,6 @@ function getDocumentNodeFromSchema(schema, options) {
|
|
|
532
549
|
throw new Error("Unknown type " + type + ".");
|
|
533
550
|
}
|
|
534
551
|
}
|
|
535
|
-
var directives = schema.getDirectives();
|
|
536
|
-
try {
|
|
537
|
-
for (var directives_1 = tslib.__values(directives), directives_1_1 = directives_1.next(); !directives_1_1.done; directives_1_1 = directives_1.next()) {
|
|
538
|
-
var directive = directives_1_1.value;
|
|
539
|
-
if (graphql.isSpecifiedDirective(directive)) {
|
|
540
|
-
continue;
|
|
541
|
-
}
|
|
542
|
-
definitions.push(astFromDirective(directive, schema, pathToDirectivesInExtensions));
|
|
543
|
-
}
|
|
544
|
-
}
|
|
545
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
546
|
-
finally {
|
|
547
|
-
try {
|
|
548
|
-
if (directives_1_1 && !directives_1_1.done && (_a = directives_1.return)) _a.call(directives_1);
|
|
549
|
-
}
|
|
550
|
-
finally { if (e_1) throw e_1.error; }
|
|
551
|
-
}
|
|
552
552
|
return {
|
|
553
553
|
kind: graphql.Kind.DOCUMENT,
|
|
554
554
|
definitions: definitions,
|
|
@@ -1362,6 +1362,29 @@ function getUserTypesFromSchema(schema) {
|
|
|
1362
1362
|
return modelTypes;
|
|
1363
1363
|
}
|
|
1364
1364
|
|
|
1365
|
+
function createSchemaDefinition(def, config) {
|
|
1366
|
+
var schemaRoot = {};
|
|
1367
|
+
if (def.query) {
|
|
1368
|
+
schemaRoot.query = def.query.toString();
|
|
1369
|
+
}
|
|
1370
|
+
if (def.mutation) {
|
|
1371
|
+
schemaRoot.mutation = def.mutation.toString();
|
|
1372
|
+
}
|
|
1373
|
+
if (def.subscription) {
|
|
1374
|
+
schemaRoot.subscription = def.subscription.toString();
|
|
1375
|
+
}
|
|
1376
|
+
var fields = Object.keys(schemaRoot)
|
|
1377
|
+
.map(function (rootType) { return (schemaRoot[rootType] ? rootType + ": " + schemaRoot[rootType] : null); })
|
|
1378
|
+
.filter(function (a) { return a; });
|
|
1379
|
+
if (fields.length) {
|
|
1380
|
+
return "schema { " + fields.join('\n') + " }";
|
|
1381
|
+
}
|
|
1382
|
+
if (config && config.force) {
|
|
1383
|
+
return " schema { query: Query } ";
|
|
1384
|
+
}
|
|
1385
|
+
return undefined;
|
|
1386
|
+
}
|
|
1387
|
+
|
|
1365
1388
|
var operationVariables = [];
|
|
1366
1389
|
var fieldTypeMap = new Map();
|
|
1367
1390
|
function addOperationVariable(variable) {
|
|
@@ -1765,7 +1788,7 @@ function createNamedStub(name, type) {
|
|
|
1765
1788
|
return new constructor({
|
|
1766
1789
|
name: name,
|
|
1767
1790
|
fields: {
|
|
1768
|
-
|
|
1791
|
+
_fake: {
|
|
1769
1792
|
type: graphql.GraphQLString,
|
|
1770
1793
|
},
|
|
1771
1794
|
},
|
|
@@ -1788,7 +1811,7 @@ function isNamedStub(type) {
|
|
|
1788
1811
|
if (graphql.isObjectType(type) || graphql.isInterfaceType(type) || graphql.isInputObjectType(type)) {
|
|
1789
1812
|
var fields = type.getFields();
|
|
1790
1813
|
var fieldNames = Object.keys(fields);
|
|
1791
|
-
return fieldNames.length === 1 && fields[fieldNames[0]].name === '
|
|
1814
|
+
return fieldNames.length === 1 && fields[fieldNames[0]].name === '_fake';
|
|
1792
1815
|
}
|
|
1793
1816
|
return false;
|
|
1794
1817
|
}
|
|
@@ -4362,6 +4385,7 @@ exports.compareNodes = compareNodes;
|
|
|
4362
4385
|
exports.compareStrings = compareStrings;
|
|
4363
4386
|
exports.correctASTNodes = correctASTNodes;
|
|
4364
4387
|
exports.createNamedStub = createNamedStub;
|
|
4388
|
+
exports.createSchemaDefinition = createSchemaDefinition;
|
|
4365
4389
|
exports.createStub = createStub;
|
|
4366
4390
|
exports.debugLog = debugLog;
|
|
4367
4391
|
exports.fieldToFieldConfig = fieldToFieldConfig;
|