InferResolversStrict not checking resolver params correctly
Closed this issue · 4 comments
mlafeldt commented
Hey, here's something I'd like to understand:
Given the following code, InferResolversStrict
will happily accept getUsername
as a resolver, although its arguments are wrong. I think this is related to the fact that the first arg is supposed to be parent: any
, which checks against id: string
. However, the number of args isn't enforced either (it should be 4 instead of 1).
(I don't think it's a problem with Deno's TS compiler options as those are pretty strict by default.)
Please enlighten me. 😄
import { graphql } from "npm:graphql"
import { buildSchema, g, InferResolversStrict } from "npm:garph"
function getUsername(id: string): string {
return "User#" + id
}
const queryType = g.type("Query", {
username: g.string().args({
id: g.id(),
}),
})
const resolvers: InferResolversStrict<
{ Query: typeof queryType },
{}
> = {
Query: {
username: getUsername, // wrong
// username: (_, args, __, ___) => getUsername(args.id), // correct
},
}
const query = Deno.args[0]
const schema = buildSchema({ g, resolvers })
const result = await graphql({
schema,
source: query,
rootValue: resolvers,
})
console.log(JSON.stringify(result, null, 2))
mishushakov commented
Good finding, Mathias! Will investigate soon
mishushakov commented
mishushakov commented
mishushakov commented
Will be closing as it's not reproducible. Feel free to reopen, if you could give me a reproducible example