dotansimha / dotansimha/graphql-code-generator

Non-conventional root operation types in Apollo-Client Helpers' TypedTypePolicies

Open
#5,932 1 comment 0 reactions 0 assignees View on GitHub
stage/0-issue-prerequisites
Dominant language
TypeScript
Stars
11.3k
Forks
1.4k
Avg merge
1d 1h
Merged PRs (30d)
23

Description

**Is your feature request related to a problem? Please describe.**
The conventional names of the root operation types are `Query`, `Mutation` and `Subscription`, but other types are allowed to be the root operation types. Hasura GraphQL Engine, for instance, uses the non-conventional root operation types `query_root`, `mutation_root`, and `subscription_root`.

Apollo Client assumes conventional root operation types, but in the case that non-conventional types are used, [it has to be overridden in the type policies](https://www.apollographql.com/docs/react/caching/cache-configuration/#overriding-root-operation-types-uncommon). Otherwise, fragments on root operation types will unexpectedly break, and I suspect other subtle issues could appear.

This is a subtle detail that is easy to overlook, which could lead to issues down the line. I don't believe it is a frequent problem, but it would be nice to have a feature to help avoid this problem.

**Describe the solution you'd like**
TypedTypePolicies should be able to enforce correctness for non-conventional root operation types. More specifically, in the generated `TypedTypePolicies`, the respective property of a non-conventional root operation type should be required, and its `queryType`/`mutationType`/`subscriptionType` property should be required to be `true`.

A further restriction might be to omit the `queryType`/`mutationType`/`subscriptionType` properties from each `TypePolicy` except the respective property for each root operation type, although I don't see that providing much value.

**Describe alternatives you've considered**
The workaround is to remember to check the type policies to see if they properly match, or work with a schema with conventional root operation types.

**Additional context**
Example of correct type policies for Hasura:
```typescript
const typePolicies: TypedTypePolicies = {
query_root: {
queryType: true,
},
mutation_root: {
mutationType: true,
},
subscription_root: {
subscriptionType: true,
},
};
```

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.