@shaberman-forks/graphql-import
TypeScript icon, indicating that this package has built-in type declarations

0.7.1-1 • Public • Published

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

yarn add graphql-import

Usage

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

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

const schema = makeExecutableSchema({ typeDefs, resolvers })

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(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!
}

Full documentation

Related topics & next steps

  • Static import step as build time
  • Namespaces
  • Support importing from HTTP endpoints (or Links)
  • Create RFC to add import syntax to GraphQL spec

Prisma

Readme

Keywords

none

Package Sidebar

Install

npm i @shaberman-forks/graphql-import

Weekly Downloads

5

Version

0.7.1-1

License

MIT

Unpacked Size

61.5 kB

Total Files

12

Last publish

Collaborators

  • shaberman