urql icon indicating copy to clipboard operation
urql copied to clipboard

RFC: exchange-graphcache should allow overriding of rootFields names

Open ckknight opened this issue 2 months ago • 2 comments

Summary

In our GraphQL Schema, we have the typical Query and Mutation types, but our root subscription type is named GqlSubscription, because someone in the early stages of the GraphQL API design created their own Subscription type that is unrelated to GraphQL subscriptions.

We want to not have to pass in the full introspection query to the cacheExchange function, which is how the custom GqlSubscription name would be determined.

Proposed Solution

Add a new, optional property to CacheExchangeOpts called rootFields that allows specifying these name overrides

Update Store to observe the new rootFields property, allowing it to still be overridden by schema (if provided).

Requirements

ckknight avatar Oct 07 '25 19:10 ckknight

I might be misremembering this, but I think we actually used to have a rootTypeNames option (or something named similarly?) but got rid of it in favour of being able to specify a partial schema option 🤔 https://github.com/urql-graphql/urql/blob/046c6e5eacde0732429508cf86757f4af2122e58/exchanges/graphcache/src/ast/schema.ts#L35-L40

I could be wrong here, but @JoviDeCroock might remember. Not sure if we want to carry this forward or add a second overlapping option here like the PR proposes, but that's just for context for now. No strong opinions from my end either way

kitten avatar Oct 07 '25 20:10 kitten

That's correct yes, we allow for a partial schema which can 1, be used for abstract types resolution and 2, for the aforementioned use case.

JoviDeCroock avatar Oct 08 '25 08:10 JoviDeCroock