prismagraphql/graphql-import

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

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

graphql-import

CircleCI npm version

Import & export definitions in GraphQL SDL (also refered to as GraphQL modules)

There is also a graphql-import-loader for Webpack available.

Install
 add graphql-import
Usage
rt { importSchema } from 'graphql-import'
rt { makeExecutableSchema } from 'graphql-tools'

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

t schema = makeExecutableSchema({ typeDefs, resolvers })
Examples
Importing specific fields

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!

Extending root fields

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.

Development

The implementation documentation documents how things are implemented under the hood. You can also use the VSCode test setup to debug your code/tests.

Related topics & next steps

Prisma


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.