I wondering if it possible to get a type of single resolver function generated by graphql-codegen
?
I also use graphql-modules
with graphql-modules-preset
. All of these libraries provide me a list of automatically generated types, but unfortunately I can't find a type of a single resolver function.
I would expected something like this:
const createRepository: CreateRepositoryMutationResolver = (parent, args, context, info) => {
// Code goes here
}
where all arguments of the function (parent
, args
, context
and info
) are strongly typed.
Instead, I could only find this way of providing types
const createRepository: ResolverFn<{}, MutationCreateRepositoryInput, GraphQLContext, GraphQLInfo> = (parent, args, context, info) => {
// Code goes here
}
I would like to skip this step where I need to fill in generics of ResolverFn
Any ideas?
P.S. If I declare all resolvers in single file, then types work as expected.
const resolvers: RepositoryModule.Resolvers = {
Mutations: {
createRepository: (parent, args, context, info) => {
// all types of all arguments work as expected
},
removeRepository: (parent, args, context, info) => {
// all types of all arguments work as expected
}
}
}
But I want to move each resolver into separate file
I did a little research on the types that were generated by
graphql-codegen
and found that all properties ofResolvers
interface as well as all of its children are optional. It means that I can re-use this interface, but specify only resolvers that I need in the separate filesFirst file
second file
and after, in a module, I can join all resolvers by
loadFileSync
I'm not sure if this is the correct way to use this interface, but it works for me