graphql-fragment-codegen
Generate fragments on GraphQL types that contain all the fields defined in each type
Last updated 3 years ago by lachenmayer .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install graphql-fragment-codegen 
SYNC missed versions from official npm registry.

graphql-fragment-codegen

Generates fragments that contain all of the fields in a GraphQL type. Useful for eg. pre-fetching detail views in list queries, or for offline use.

Install

npm install -g graphql-fragment-codegen

Usage

graphql-fragment-codegen < path/to/input/schema.graphql > path/to/output/fragments.js

Example

Given the following schema:

schema {
  query: Query
}

type Query {
  foo: Foo
  bar: Bar
  baz: String
}

type Foo {
  someField: Int
  otherField: String
}

type Bar {
  yay: Boolean
  ok: Boolean
}

...it generates:

// This file was auto-generated by fragment-codegen. Do not edit it by hand.

export const Foo = `fragment Foo on Foo {
  someField
  otherField
}
`

export const Bar = `fragment Bar on Bar {
  yay
  ok
}
`

You can then use the resulting fragment in queries as follows:

import * as fragments from './fragments'

// ...
gql`
  query SomeQuery {
    foo {
      ...Foo
    }
  }
  ${fragments.Foo}
`
// ...

Current Tags

  • 1.5.0                                ...           latest (3 years ago)

7 Versions

  • 1.5.0                                ...           3 years ago
  • 1.4.0                                ...           3 years ago
  • 1.3.0                                ...           3 years ago
  • 1.2.0                                ...           3 years ago
  • 1.1.1                                ...           3 years ago
  • 1.1.0                                ...           3 years ago
  • 1.0.0                                ...           3 years ago
Maintainers (1)
Downloads
Today 0
This Week 1
This Month 1
Last Day 0
Last Week 2
Last Month 6
Dependencies (2)
Dev Dependencies (2)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |