https://github.com/correttojs/graphql-codegen-apollo-cache
GraphQL Code Generator plugin for generating a functions to read and write from the apollo cache
https://github.com/correttojs/graphql-codegen-apollo-cache
apollo-cache-inmemory apollo-client codegen graphql graphql-code-generator graphql-codegen typescript
Last synced: 11 months ago
JSON representation
GraphQL Code Generator plugin for generating a functions to read and write from the apollo cache
- Host: GitHub
- URL: https://github.com/correttojs/graphql-codegen-apollo-cache
- Owner: correttojs
- Created: 2020-06-13T19:08:36.000Z (almost 6 years ago)
- Default Branch: main
- Last Pushed: 2023-01-10T01:06:01.000Z (about 3 years ago)
- Last Synced: 2025-04-15T22:01:59.862Z (12 months ago)
- Topics: apollo-cache-inmemory, apollo-client, codegen, graphql, graphql-code-generator, graphql-codegen, typescript
- Language: TypeScript
- Homepage:
- Size: 1.94 MB
- Stars: 10
- Watchers: 1
- Forks: 1
- Open Issues: 24
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# NOTE: You can use [TypedDocumentNode](https://github.com/dotansimha/graphql-typed-document-node) instead
see the [example](example/src/index.ts)
# Graphql generator Apollo Cache Plugin
GraphQL Code Generator plugin for generating a functions to read and write from the apollo cache
## Install
`npm i graphql-codegen-apollo-cache`
## Configuration
- `excludePatterns` (default: null): regexp to exclude operation names
- `excludePatternsOptions` (default: ''): regexp flags to exclude operation names
- `reactApolloVersion` (default: 2): apollo client version
- `apolloCacheImportFrom` (default: apollo-cache-inmemory): apollo-cache-inmemory dependency
- `apolloImportFrom` (default: apollo-client v2 or @apollo/client v3): apollo client dependency
- `dataIdFromObjectImport` (default: apollo-cache-inmemory): custom dataIdFromObject dependency
- `dataIdFromObjectName`: dataIdFromObject function name
- `generateFragmentsRead`(default: true): generate fragments read functions
- `generateFragmentsWrite`(default: true): generate fragments write functions
- `generateQueriesWrite`(default: true): generate query read functions
- `generateQueriesWrite`(default: true): generate query write functions
- `customImports` (default: ''): full custom import declaration
- `pre` (default: ''): custom code before each function
- `post` (default: ''): custom code after each function
## Example config
```
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
```