dotansimha / graphql-code-generator-community

MIT License
117 stars 152 forks source link

URQL GraphCache creates type error when there are no mutations #193

Open matthew-petrie opened 2 years ago

matthew-petrie commented 2 years ago

Issue workflow progress

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:

matthew-petrie commented 2 years ago

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