Closed michaelbridge closed 10 months ago
Unfortunately not much I can do - Args extends VariabledInput<argsType>
is necessary to be able to accept variables in any position of argsType, however, extends
also implies "additional properties available".
An alternative design that I was playing with but never got a chance to make work
query<{myVar: string}>('QueryName', (q, vars) => [
q.company({id: vars.myVar}, c => [c.display_name, c.investments(all)])
])
Runtime details: a proxy is passed where any get accessor always returns a variable (with the name of the accessor)
Pros
Cons
Looks like I was wrong
continent<
Args extends VariabledInput<{
code: string
}>,
Sel extends Selection<Continent>
>(
args: Args & { [K in keyof Args]: K extends keyof { code: string } ? Args[K] : never },
selectorFn: (s: Continent) => [...Sel]
)
has the desired behavior. Haven't tried yet if it will work in all situations.
PR: https://github.com/typed-graphql-builder/typed-graphql-builder/pull/67 - existing tests pass.
In both cases,
junk
is an invalid argument, whileid
is valid. As you can see in the 2nd example, type-checking does not correctly identifyjunk
as an invalid parameter. This issue also exists within more complicated JSON inputs, but this is the simplest reproduction.The generated type is as follows:
I experimented with several solutions but have thus far been unsuccessful. The solution I thought would work did not -- this involves wrapping
VariabledInput
withExact
(per type-fest):Thoughts? Hints? Suggestions?