Apologies for my English
I am struggling to create types for resolvers on GraphQL yoga. I attempted to generate them using graphql-codegen, but the resulting types are behaving strangely. Additionally, they do not include context types for Prisma2.
Here is my code snippet from codegen.yml:
schema: ./src/schema.graphql
generates:
./src/resolvers/resolvers-types.ts:
plugins:
- typescript
- typescript-resolvers
config:
contextType: './context#Context'
In my context.ts file, I have defined the context type as follows:
import {PrismaClient} from '@prisma/client'
export type Context = { prisma:PrismaClient }
And in my resolvers.ts file, here is how I import and define the resolvers with StringIndexed:
import {IResolvers, Mutation} from './resolvers-types'
interface StringIndexSignatureInterface {
[index: string]: any
}
type StringIndexed<T> = T & StringIndexSignatureInterface
const resolvers: StringIndexed<IResolvers> = {
Query: {
users: (parent, args, ctx, info) => {
return ctx.prisma.user.findMany
}
}
};
I am encountering an error related to type incompatibility when I exclude StringIndexed. It seems necessary for the resolvers to work properly. Can someone please advise me on how to resolve this issue?