UNPKG

1.79 kBMarkdownView Raw
1# graphql-import
2
3[![CircleCI](https://circleci.com/gh/graphcool/graphql-import.svg?style=shield)](https://circleci.com/gh/graphcool/graphql-import) [![npm version](https://badge.fury.io/js/graphql-import.svg)](https://badge.fury.io/js/graphql-import)
4
5
6Import & export definitions in GraphQL SDL (also refered to as GraphQL modules)
7
8## Install
9
10```sh
11yarn add graphql-import
12```
13
14## Usage
15
16```ts
17import { importSchema } from 'graphql-import'
18import { makeExecutableSchema } from 'graphql-tools'
19
20const typeDefs = importSchema('schema.graphql')
21const resolvers = {}
22
23const schema = makeExecutableSchema({ typeDefs, resolvers })
24```
25
26## Example
27
28Assume the following directory structure:
29
30```
31.
32├── a.graphql
33├── b.graphql
34└── c.graphql
35```
36
37`a.graphql`
38
39```graphql
40# import B from "b.graphql"
41
42type A {
43 # test 1
44 first: String
45 second: Float
46 b: B
47}
48```
49
50`b.graphql`
51
52```graphql
53# import C from 'c.graphql'
54
55type B {
56 c: C
57 hello: String!
58}
59```
60
61`c.graphql`
62
63```graphql
64type C {
65 id: ID!
66}
67```
68
69Running `console.log(importSchema('a.graphql'))` procudes the following output:
70
71```graphql
72type A {
73 first: String
74 second: Float
75 b: B
76}
77
78type B {
79 c: C
80 hello: String!
81}
82
83type C {
84 id: ID!
85}
86```
87
88Please refer to [`src/index.test.ts`](https://github.com/graphcool/graphql-import/blob/master/src/index.test.ts) for more examples.
89
90## Development
91
92The [implementation documentation](https://graphql-import.now.sh/) documents how things are implemented under the hood. You can also use the VSCode test setup to debug your code/tests.
93
94## Related topics & next steps
95
96- Static import step as build time
97- Namespaces
98- Support importing from HTTP endpoints (or [Links](https://github.com/apollographql/apollo-link))
99- Create RFC to add import syntax to GraphQL spec