@graphql-tools/utils 7.7.0 → 7.7.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.
@@ -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
@@ -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) {
@@ -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;