You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello, thanks for maintaining garph as an open source project. This is perhaps related to #78 but I am creating as a new issue because it does seem like there is an issue with types somewhere.
My goal is to restructure a project that uses garph such that resolvers are grouped into separate modules. This has proven to be surprisingly difficult because I keep running into type errors that defy intuition.
I have a minimal reproducer here that illustrates the problem.
The api-schema.ts has the type definitons for graphql. And the resolvers are located here.
The crux is that I have a Resolvers type that I infer from the schema definiton:
It is not clear why an object of type { locations: Resolvers["Query"]["locations"] } is not assignable to Resolvers["Query"] when Query doesn't have any other fields.
However, if I inline the locations resolver within the Query resolver here, it typechecks fine.
The text was updated successfully, but these errors were encountered:
Hi @mishushakov - I sorted it out - was an error at my end.
While logging the issue, I hadn't realized that Resolvers["Query"] was a union of multiple types. So Resolvers["Query"]["locations"] would end up being union of the type of that field from different members and if I wrap that into an object it would no longer be assignable to Resolvers["Query"].
So the pattern I adopted was always using Resolvers["SomeType"] when splitting, which works great.
// One file:constQueryLocationsResolvers: Resolvers["Query"]={locations: (...)=>{ ... }}// Another file constQueryPricesResolvers: Resolvers["Query"]={prices: (...)=>{ ... }}// Finally while merging: constQueryResolvers: Resolvers["Query"]={
...QueryLocationsResolvers,
...QueryPricesResolvers,}exportconstschema=buildSchema({
g,resolvers: {Query: QueryResolvers,// ...},})
Hello, thanks for maintaining garph as an open source project. This is perhaps related to #78 but I am creating as a new issue because it does seem like there is an issue with types somewhere.
My goal is to restructure a project that uses garph such that resolvers are grouped into separate modules. This has proven to be surprisingly difficult because I keep running into type errors that defy intuition.
I have a minimal reproducer here that illustrates the problem.
The api-schema.ts has the type definitons for graphql. And the resolvers are located here.
The crux is that I have a Resolvers type that I infer from the schema definiton:
and then use its members when defining specific resolvers, for example:
The above type checks without issues.
However when I try to compose these resolvers into a Query/Mutation type, I get obscure type errors that are hard to fathom:
It is not clear why an object of type
{ locations: Resolvers["Query"]["locations"] }
is not assignable toResolvers["Query"]
when Query doesn't have any other fields.However, if I inline the locations resolver within the Query resolver here, it typechecks fine.
The text was updated successfully, but these errors were encountered: