hayes / pothos

Pothos GraphQL is library for creating GraphQL schemas in typescript using a strongly typed code first approach
https://pothos-graphql.dev
ISC License
2.28k stars 153 forks source link

[Suggestion] SubGraph-specific context type with subgraph plugin #1208

Open AndrewIngram opened 1 month ago

AndrewIngram commented 1 month ago

We're trying out the subgraph plugin, as we have two schemas. They actually have different context shapes (not drastically so, but enough that we've given them different TypeScript types), at the moment I'm supporting this by having the Pothos context type being a union of the two, but this leaves me having to manually write discriminator code in resolvers to determine which is applicable. It'd be useful if we could define the context type per subgraph, such that the context arg is as narrow as possible.

hayes commented 1 month ago

Unfortunately this isn't easy to do from a technical perspective. Plugins don't have an easy way to affect resolver types without creating custom methods.

The scope-auth plugin can change contexts but it does it through one of 2 methods:

Using a t.withAuth({ ...scopes }).field or t.authField to define fields with changed contexts. We could potentially copy that pattern, but just doing it automatically on normal field definitions isn't possible