JSPM

graphql-import

0.7.2-c2d1532.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 198248
  • Score
    100M100P100Q34739F
  • License MIT

Package Exports

  • graphql-import

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (graphql-import) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

graphql-import

Discord Chat

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'

async function start() {
  const typeDefs = await importSchema('schema.graphql'); // or .gql or glob pattern like **/*.graphql
  const resolvers = {};

  const schema = makeExecutableSchema({ typeDefs, resolvers })
}

main().catch(err => console.error(err));

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(await 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

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

Prisma