Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lachenmayer/graphql-fragment-codegen
Generate fragments on GraphQL types that contain all the fields defined in each type
https://github.com/lachenmayer/graphql-fragment-codegen
Last synced: 2 days ago
JSON representation
Generate fragments on GraphQL types that contain all the fields defined in each type
- Host: GitHub
- URL: https://github.com/lachenmayer/graphql-fragment-codegen
- Owner: lachenmayer
- Created: 2017-10-27T16:22:49.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2017-11-07T20:42:30.000Z (about 7 years ago)
- Last Synced: 2025-01-02T20:34:10.365Z (11 days ago)
- Language: JavaScript
- Size: 21.5 KB
- Stars: 1
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# 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:
```graphql
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:
```js
// 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:
```js
import * as fragments from './fragments'// ...
gql`
query SomeQuery {
foo {
...Foo
}
}
${fragments.Foo}
`
// ...```