Apparently the latest version of TypeScript has stricter type checking. This is causing issues with the basic example on the README...
const resolvers = {
Query: {
hello: (_, { name }) => `Hello ${name || "World"}`
}
};
const server = new GraphQLServer({ typeDefs, resolvers });
This error is reported...
[ts]
Argument of type '{ typeDefs: string; resolvers: { Query: { hello: (_: any, { name }: { name: any; }) => string; };...' is not assignable to parameter of type 'Props<any, any, any>'.
Types of property 'resolvers' are incompatible.
Type '{ Query: { hello: (_: any, { name }: { name: any; }) => string; }; }' is not assignable to type 'IResolvers | undefined'.
Type '{ Query: { hello: (_: any, { name }: { name: any; }) => string; }; }' is not assignable to type 'IResolvers'.
Property 'Query' is incompatible with index signature.
Type '{ hello: (_: any, { name }: { name: any; }) => string; }' is not assignable to type '(() => any) | IResolverObject | GraphQLScalarType'.
Type '{ hello: (_: any, { name }: { name: any; }) => string; }' is not assignable to type 'GraphQLScalarType'.
Property 'name' is missing in type '{ hello: (_: any, { name }: { name: any; }) => string; }'.
This may be caused by https://github.com/DefinitelyTyped/DefinitelyTyped/issues/21359
@cruhl can you put up a repro?
The reason this fails is because everywhere GraphQLFieldResolver<any, any> is used it should be
GraphQLFieldResolver<any, any, any> instead.
See the generic types here: type GraphQLFieldResolver<TSource, TContext, TArgs = { [argName: string]: any }>
To reproduce use a resolver that doesn't use arguments conforming to { [argName: string]: any }
note that the following won't compile (this might be what's new in typescript)
interface A { foo: string; }
const a: A = { foo: 'bar' };
const b: { [name: string]: string; } = a;
@nmaro Based on that explanation my PR may fix this issue then: https://github.com/prismagraphql/graphql-yoga/pull/369.
@jasonkuhrt I would, but I'm away from my computer for the holidays, sorry! Thanks for looking into this everyone...
any update on this? or a workaround ?
@cport1 #418
@cport1 My current workaround is to "erase" the types:
const Query: QueryResolvers.Resolvers = {
async search() {
return {
count: 0,
hits: []
};
}
};
// Work around for https://github.com/prisma/graphql-yoga/pull/418
const resolvers: {} = { Query };
const server = new GraphQLServer({
typeDefs,
resolvers
});
If you want to disable type-checking on the resolvers input to the GraphQLServer constructor, you can also do this instead:
const server = new GraphQLServer({
typeDefs,
resolvers: resolvers as any
});
Due to inactivity of this issue we have marked it stale. It will be closed if no further activity occurs.
Still requires the workaround
Due to inactivity of this issue we have marked it stale. It will be closed if no further activity occurs.
Hey :wave:, It seems like this issue has been inactive for some time. In need for maintaining clear overview of the issues concerning the latest version of graphql-yoga we'll close it.
Feel free to reopen it at any time if you believe we should futher discuss its content. :slightly_smiling_face:
Most helpful comment
If you want to disable type-checking on the resolvers input to the
GraphQLServerconstructor, you can also do this instead: