0.0.5 • Published 5 years ago

@gaslight/graphql-import v0.0.5

Weekly downloads
4
License
MIT
Repository
github
Last release
5 years ago

graphql-import

Build Status

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

Install

yarn add @gaslight/graphql-import

Usage

import { importSchema } from '@gaslight/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!
}

https://example.com/graphql

# import User from 'https://exmaple.com/graphql'

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

Related topics & next steps

  • Static import step as build time
  • Namespaces
  • Support importing from HTTP endpoints