Skip to content

Generate fragments on GraphQL types that contain all the fields defined in each type

Notifications You must be signed in to change notification settings

jasopolis/graphql-fragment-codegen

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.graphql

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.

fragment FooAllFields on Foo {
    someField
    otherField
}

fragment BarAllFields on Bar {
    yay
    ok
}

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

# ...

query SomeQuery {
    foo {
        ...FooAllFields
    }
}

# ...

About

Generate fragments on GraphQL types that contain all the fields defined in each type

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 96.8%
  • Shell 3.2%