graphql-paper
Version:
A flexible in-memory store based on a GraphQL Schema
25 lines (24 loc) • 955 B
JavaScript
import { isSchema, buildASTSchema, buildSchema, printSchema } from 'graphql';
function copySchema(schema) {
return buildSchema(printSchema(schema));
}
function createSchema(schema) {
if (isSchema(schema)) return copySchema(schema);
if (typeof schema === 'object' && schema.kind === 'Document') {
try {
return 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 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');
}
export { createSchema };
//# sourceMappingURL=create-schema.mjs.map