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.36k stars 164 forks source link

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

Open AndrewIngram opened 6 months ago

AndrewIngram commented 6 months 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 6 months 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