Back to Prisma1

graphql-import

docs/1.6/06-GraphQL-Ecosystem/07-GraphQL-Import/01-Overview.md

1.34.121.1 KB
Original Source

graphql-import

graphql-import is a package that allows importing & exporting schema definitions in GraphQL SDL (also refered to as GraphQL modules).

Install

sh
yarn add graphql-import

Usage

ts
import { importSchema } from 'graphql-import'
import { makeExecutableSchema } from 'graphql-tools'

const typeDefs = importSchema('schema.graphql')
const resolvers = {}

const schema = makeExecutableSchema({ typeDefs, resolvers })

Example

Assume the following directory structure:

.
├── a.graphql
├── b.graphql
└── c.graphql

a.graphql

graphql
# import B from "b.graphql"

type A {
  # test 1
  first: String
  second: Float
  b: B
}

b.graphql

graphql
# import C from 'c.graphql'

type B {
  c: C
  hello: String!
}

c.graphql

graphql
type C {
  id: ID!
}

Running console.log(importSchema('a.graphql')) procudes the following output:

graphql
type A {
  first: String
  second: Float
  b: B
}

type B {
  c: C
  hello: String!
}

type C {
  id: ID!
}