UNPKG

graphql-mocks

Version:
35 lines (26 loc) 1.01 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var graphql = require('graphql'); var copySchema = require('./copy-schema.js'); function createSchema(schema) { if (graphql.isSchema(schema)) return copySchema.copySchema(schema); if (typeof schema === 'object' && schema.kind === 'Document') { try { return graphql.buildASTSchema(schema); } catch (error) { throw new Error('Unable to build a schema from the AST Schema passed into the `graphqlSchema` dependency. Failed with error:\n\n' + error.message); } } if (typeof schema === 'string') { try { return graphql.buildSchema(schema); } catch (error) { throw new Error('Unable to build a schema from the string passed into the `graphqlSchema` dependency. Failed with error:\n\n' + error.message); } } throw new Error('Unable to build schema, pass in an instance of schema or a string'); } exports.createSchema = createSchema; //# sourceMappingURL=create-schema.js.map