This specific GraphQL schema example from the Constructing Types page showcases how to define the Query type.
// Creating the Query type
var queryType = new graphql.GraphQLObjectType({
name: 'Query',
fields: {
user: {
type: userType,
// Describing the arguments accepted by the `user` query
args: {
id: { type: graphql.GraphQLString }
},
resolve: (_, {id}) => {
return fakeDatabase[id];
}
}
}
});
Even though it's possible to specify the args and their GraphQL types (like GraphQLString in this case), the id property within the resolver is of type "any."
Attempting to replace {id}
with {id}: {id: string}
resulted in the error message
Type '(_: any, { id }: { id: string; })' is not assignable to type 'GraphQLFieldResolver<any, any, { [argName: string]: any; }>'
.
While this example uses a simple "string," my actual code involves more complex object types with multiple properties. It would be beneficial to have the correct property name referenced within the resolvers for clarity. I wonder if there is a way to indicate the resolver the actual types of the args, but as a TypeScript beginner, I haven't been able to figure it out.
Is there a method to specify/modify the types of the resolver's args?