dotansimha / graphql-code-generator-community

MIT License
118 stars 155 forks source link

[typescript-urql-graphcache] Optimistic Update Typename Hardcoded #142

Open alexjharrison opened 3 years ago

alexjharrison commented 3 years ago

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:
{
  "__schema": {
    "queryType": {
      "name": "query_root"
    },
    "mutationType": {
      "name": "mutation_root"
    },
    "subscriptionType": {
      "name": "subscription_root"
    },
    ...
}
  1. My GraphQL operations:

Incorrect optimistic updates

image

Correct graphcache updates

image

  1. My codegen.yml config file:
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:

Additional context

ardatan commented 3 years ago

Would you create a PR for a failing test and/or a fix?

Axedyson commented 2 years ago

Shouldn't this issue be closed?