UNPKG

graphql-paper

Version:

A flexible in-memory store based on a GraphQL Schema

27 lines (25 loc) 977 B
'use strict'; var graphql = require('graphql'); function copySchema(schema) { return graphql.buildSchema(graphql.printSchema(schema)); } function createSchema(schema) { if (graphql.isSchema(schema)) return 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