Skip to content

Instantly share code, notes, and snippets.

@mlg87
Last active July 21, 2020 21:10
Show Gist options
  • Save mlg87/2af09b2108b3f6cf57798ee3e1c641d4 to your computer and use it in GitHub Desktop.
Save mlg87/2af09b2108b3f6cf57798ee3e1c641d4 to your computer and use it in GitHub Desktop.
Using Apollo Client for global state management code samples - codegen.yml
# ./codegen.yml
overwrite: true
schema:
- localSchema.js
- ${SCHEMA_PATH}/graphql: # <-- this is for our remote schema, you'll probably have something similar
headers:
Authorization: ${AUTH0_ACCESS_TOKEN}
generates:
src/types/graphql.tsx:
documents: # <-- your app structure may be different, but this will pick up the queries.ts and mutations.ts files created earlier
- src/**/*queries.{js,ts}
- src/**/*mutations.{js,ts}
plugins:
- typescript
- typescript-operations
- typescript-react-apollo
config:
withHOC: false
withHooks: true # <-- say yes to the hooks
hooksImportFrom: "@apollo/react-hooks"
typesPrefix: I # <-- all of our types created will be prefixed with 'I'
skipTypename: true
namingConvention:
enumValues: upper-case#upperCase
scalars:
ID: string
hooks:
afterOneFileWrite:
- yarn lint:script --fix
- prettier --write src/**/*.{js,jsx,ts,tsx}
./schema.graphql:
plugins:
- schema-ast
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment