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

    0.5.0 • 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 })

    Example

    Assume the following directory structure:

    .
    ├── a.graphql
    ├── b.graphql
    └── c.graphql
    

    a.graphql

    # import B from "b.graphql"
    
    type A {
      # test 1
      first: String
      second: Float
      b: B
    }

    b.graphql

    # import C from 'c.graphql'
    
    type B {
      c: C
      hello: String!
    }

    c.graphql

    type C {
      id: ID!
    }

    Running console.log(importSchema('a.graphql')) procudes the following output:

    type A {
      first: String
      second: Float
      b: B
    }
    
    type B {
      c: C
      hello: String!
    }
    
    type C {
      id: ID!
    }

    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

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

    Keywords

    none

    Install

    npm i @volst/graphql-import

    DownloadsWeekly Downloads

    1

    Version

    0.5.0

    License

    MIT

    Unpacked Size

    52.2 kB

    Total Files

    12

    Last publish

    Collaborators

    • amees_me
    • rutgerschimmel