graphql-codegen-default-documents
v0.1.3
Published
GraphQL Code Generator plugin for generating default documents (queries, mutations, subscriptions and 'AllFields' fragments) for your GraphQL schema.
Downloads
152
Maintainers
Readme
graphql-codegen-default-documents
Plugin for graphql-codegen to generate default documents, such as operations (queries, mutations, subscriptions) as well as 'AllFields' fragments for defined types from your GraphQL schema.
Installation
- with NPM
npm i -D graphql-codegen-default-documents
- with Yarn:
yarn add --dev graphql-codegen-default-documents
Usage
This plugin should be run before other plugins that need to use documents
.
If you have existing custom documents and include them globally in graphql-codegen
config, this plugin will not generate any fragments, queries, mutations or subscriptions with the same names as your custom ones to avoid conflicts.
For example, in your codegen-default-docs.ts
file:
const config = {
overwrite: true,
schema: [
'path/to/my-schema.graphql'
],
documents: [
'path/to/my-custom-documents.graphql'
],
generates: {
'path/to/generated-docs.graphql': {
plugins: [ 'graphql-codegen-default-documents' ],
config: {
docsToGenerate: [ 'fragment', 'query', 'mutation', 'subscription' ]
fragmentMinimumFields: 5,
skipTypename: false
},
},
},
};
and run it with graphql-codegen --config codegen-default-docs.ts
.
Then have a second graphql-codegen
config file, lets say codegen-next.ts
, which points to generated default docs file from the previous one:
const config = {
overwrite: true,
schema: [
'path/to/my-schema.graphql'
],
documents: [
'path/to/my-custom-documents.graphql',
// include documents generated by graphql-codegen-default-documents plugin
// at the first codegen.ts file
'path/to/generated-docs.graphql',
],
generates: {
'path/to/generated/your-other-file.ext': {
plugins: [
// other plugins
],
config: {
// other config
},
},
},
};
and run it with graphql-codegen --config codegen-next.ts
.
Acknowledgements
Inspired by https://github.com/argano/graphql-codegen-documents
TODO
- Handle Unions and Abstract Types
- Test cases
- More examples in README