$ npm install graphql-import
Import & export definitions in GraphQL SDL (also refered to as GraphQL modules)
There is also a
graphql-import-loaderfor Webpack available.
yarn add graphql-import
import { importSchema } from 'graphql-import'
import { makeExecutableSchema } from 'graphql-tools'
async function start() {
const typeDefs = await importSchema('schema.graphql'); // or .gql or glob pattern like **/*.graphql
const resolvers = {};
const schema = makeExecutableSchema({ typeDefs, resolvers })
}
main().catch(err => console.error(err));
Assume the following directory structure:
.
├── schema.graphql
├── posts.graphql
└── comments.graphql
schema.graphql
# import Post from "posts.graphql"
type Query {
posts: [Post]
}
posts.graphql
# import Comment from 'comments.graphql'
type Post {
comments: [Comment]
id: ID!
text: String!
tags: [String]
}
comments.graphql
type Comment {
id: ID!
text: String!
}
Running console.log(await importSchema('schema.graphql')) produces the following output:
type Query {
posts: [Post]
}
type Post {
comments: [Comment]
id: ID!
text: String!
tags: [String]
}
type Comment {
id: ID!
text: String!
}
© 2010 - cnpmjs.org x YWFE | Home | YWFE