NOTE: You can use TypedDocumentNode instead
see the example
GraphQL Code Generator plugin for generating a functions to read and write from the apollo cache
npm i graphql-codegen-apollo-cache
excludePatterns
(default: null): regexp to exclude operation namesexcludePatternsOptions
(default: ''): regexp flags to exclude operation namesreactApolloVersion
(default: 2): apollo client versionapolloCacheImportFrom
(default: apollo-cache-inmemory): apollo-cache-inmemory dependencyapolloImportFrom
(default: apollo-client v2 or @apollo/client v3): apollo client dependencydataIdFromObjectImport
(default: apollo-cache-inmemory): custom dataIdFromObject dependencydataIdFromObjectName
: dataIdFromObject function namegenerateFragmentsRead
(default: true): generate fragments read functionsgenerateFragmentsWrite
(default: true): generate fragments write functionsgenerateQueriesWrite
(default: true): generate query read functionsgenerateQueriesWrite
(default: true): generate query write functionscustomImports
(default: ''): full custom import declarationpre
(default: ''): custom code before each functionpost
(default: ''): custom code after each function
overwrite: true
schema:
- 'https://myschema/graphql'
documents:
- 'src/**/*.graphql'
generates:
src/@types/codegen/graphql.tsx:
plugins:
- 'typescript'
- 'typescript-operations'
- 'typescript-react-apollo'
src/@types/codegen/cache.tsx:
config:
documentMode: external
importDocumentNodeExternallyFrom: ./graphql
preset: import-types
presetConfig:
typesPath: ./graphql
plugins:
- ./build/src/index.js
hooks:
afterAllFileWrite:
- prettier --write