Name: graphql-import
Owner: Prisma
Description: Import & export definitions in GraphQL SDL
Created: 2017-11-20 11:11:43.0
Updated: 2018-05-24 13:55:19.0
Pushed: 2018-05-24 13:55:17.0
Homepage: https://graphql-import.now.sh/
Size: 292
Language: TypeScript
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
Import & export definitions in GraphQL SDL (also refered to as GraphQL modules)
There is also a
graphql-import-loader
for Webpack available.
add graphql-import
rt { importSchema } from 'graphql-import'
rt { makeExecutableSchema } from 'graphql-tools'
t typeDefs = importSchema('schema.graphql')
t resolvers = {}
t schema = makeExecutableSchema({ typeDefs, resolvers })
Assume the following directory structure:
a.graphql
b.graphql
c.graphql
a.graphql
port B from "b.graphql"
A {
test 1
rst: String
cond: Float
B
b.graphql
port C from 'c.graphql'
B {
C
llo: String!
c.graphql
C {
: ID!
Running console.log(importSchema('a.graphql'))
produces the following output:
A {
rst: String
cond: Float
B
B {
C
llo: String!
C {
: ID!
It is possible to import from a root field like Query
;
queries.graphql
Query {
ed: [Post!]!
afts: [Post!]!
mutations.graphql
Mutation {
blish(id: ID!): Post!
letePost(id: ID!): Post!
schema.graphql
port Query.* from "queries.graphql"
port Mutation.publish from "mutations.graphql"
Running console.log(importSchema('schema.graphql'))
produces the following output:
Query {
ed: [Post!]!
afts: [Post!]!
Mutation {
blish(id: ID!): Post!
Please refer to src/index.test.ts
for more examples.
The implementation documentation documents how things are implemented under the hood. You can also use the VSCode test setup to debug your code/tests.