【发布时间】:2020-10-25 02:51:58
【问题描述】:
对不起我的英语
所以,我需要在 GraphQL 瑜伽上为解析器创建类型。我用 graphql-codegen 创建了它,但它的工作原理很奇怪。而且他目前没有为 Prisma2 创建类型上下文。
codegen.yml
schema: ./src/schema.graphql
generates:
./src/resolvers/resolvers-types.ts:
plugins:
- typescript
- typescript-resolvers
config:
contextType: './context#Context'
context.ts
import {PrismaClient} from '@prisma/client'
export type Context = { prisma:PrismaClient }
解析器.ts
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
}
}
};
他抛出关于类型不兼容的错误
没有 StringIndexed 他不工作
请告诉我如何做到这一点
【问题讨论】:
标签: typescript types graphql prisma codegen