graphql-code-generator-community icon indicating copy to clipboard operation
graphql-code-generator-community copied to clipboard

URQL GraphCache creates type error when there are no mutations

Open matthew-petrie opened this issue 3 years ago • 2 comments

Issue workflow progress

  • [x] 1. The issue provides a reproduction: https://github.com/matthew-petrie/graphql-code-generator-issue-sandbox-template
  • [x] 2. A failing test has been provided (see linked PR)
  • [x] 3. A local solution has been provided (see https://github.com/matthew-petrie/graphql-code-generator-issue-sandbox-template)
  • [x] 4. A pull request is pending review

Describe the bug

The typescript-urql-graphcache plugin causes a typescript error in the generated type file for the type GraphCacheOptimisticUpdaters if the schema has no mutations: Screenshot 2022-06-03 at 13 19 06

To Reproduce Reproduction repo: https://github.com/matthew-petrie/graphql-code-generator-issue-sandbox-template

Steps to reproduce the behavior:

  1. My GraphQL schema:
type Query {
    user(id: ID!): User!
}

type User {
    id: ID!
    username: String!
    email: String!
}
  1. My GraphQL operations:
query user {
    user(id: 1) {
        id
        username
        email
    }
}
  1. My codegen.yml config file:
schema: schema.graphql
documents: document.graphql
generates:
  types.ts:
    plugins:
      - typescript
      - typescript-operations
      - typescript-urql-graphcache

Expected behavior

For typescript-urql-graphcache to generate a types file with no Typescript errors. If there are no mutations GraphCacheOptimisticUpdaters should be output as:

export type GraphCacheOptimisticUpdaters = {};

Environment:

  • OS: macOS Monterey 12.3 - M1 Pro chip
  • @graphql-codegen/typescript-urql-graphcache: ^2.2.13
  • typescript: ^4.7.2
  • NodeJS: v16.13.1

matthew-petrie avatar Jun 03 '22 12:06 matthew-petrie

Raised a PR to fix this bug: https://github.com/dotansimha/graphql-code-generator/pull/7911

matthew-petrie avatar Jun 03 '22 12:06 matthew-petrie

@saihaj I think this issue is resolves with the merge of the PR linked above and can be closed

dargmuesli avatar May 23 '25 06:05 dargmuesli