dotansimha / dotansimha/graphql-code-generator-community
[typescript-urql-graphcache] Optimistic Update Typename Hardcoded
- Dominant language
- TypeScript
- Stars
- 137
- Forks
- 195
- Avg merge
- 6h 20m
- Merged PRs (30d)
- 16
Description
**Describe the bug**
When using the codegen cli tool to create my ts definitions for urql graphcache, the prefix for the mutation args for optimistic update functions is always "Mutation". In my schema it should be prefixed with "Mutation_Root".
The error is caused on this line
https://github.com/dotansimha/graphql-code-generator/blob/e8bc3fd2382d291aaacd4c78b54c759f4d791218/packages/plugins/typescript/urql-graphcache/src/index.ts#L189
Whereas the naming on the regular update function is correct because it dynamically creates the mutation arg prefix with `rootType.name`
https://github.com/dotansimha/graphql-code-generator/blob/e8bc3fd2382d291aaacd4c78b54c759f4d791218/packages/plugins/typescript/urql-graphcache/src/index.ts#L156
**To Reproduce**
`npm run generate`
```js
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"test:unit": "vue-cli-service test:unit",
"test:e2e": "vue-cli-service test:e2e",
"lint": "vue-cli-service lint",
"generate": "graphql-codegen"
},
```
1. My GraphQL schema:
```json
{
"__schema": {
"queryType": {
"name": "query_root"
},
"mutationType": {
"name": "mutation_root"
},
"subscriptionType": {
"name": "subscription_root"
},
...
}
```
2. My GraphQL operations:
## Incorrect optimistic updates

## Correct graphcache updates

3. My `codegen.yml` config file:
```yml
schema:
- ${VUE_APP_API_ROOT}:
headers:
Content-Type: application/json
x-hasura-admin-secret: ${HASURA_SECRET}
documents: src/**/*.graphql
generates:
src/assets/generated/schema.json:
plugins:
- urql-introspection
src/assets/generated/api.ts:
config:
gqlImport: '@urql/vue#gql'
dedupeOperationSuffix: true
plugins:
- typescript
- typescript-urql-graphcache
- typescript-operations
- typescript-vue-urql
```
**Expected behavior**
Optimistic update arguments prefix should be dynamically named based on the definition in the schema.
**Environment:**
- OS: Pop!_OS 21.04
- "@graphql-codegen/cli": "^2.0.1",
- "@graphql-codegen/typescript": "^2.0.0",
- "@graphql-codegen/typescript-operations": "^2.0.1",-
- "@graphql-codegen/typescript-urql-graphcache": "^2.1.1",
- "@graphql-codegen/typescript-vue-urql": "^2.0.0",
- NodeJS: v14.17.3
**Additional context**
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.