dotansimha / dotansimha/graphql-code-generator-community

[typescript-urql-graphcache] Optimistic Update Typename Hardcoded

Open
#142 2 comments 1 reaction 0 assignees View on GitHub
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
![image](https://user-images.githubusercontent.com/8920897/130695098-f5897eba-1050-42d4-9bf8-09007751b62a.png)

## Correct graphcache updates
![image](https://user-images.githubusercontent.com/8920897/130695149-625a5b2d-92af-44b1-bb04-87495571771d.png)

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.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.