3

I'm creating my graphql layer with prisma. I have a question about using prisma with typescript in the resolvers.

In the documentation it is suggested to import prisma to get intellisense:

import { prisma } from '../generated/prisma-client'

If you do so, when you are writing a resolver like this one, you won't get any suggestions.

const user = (parent, args, context, info) => context.prisma.bodyweight({id: parent.id}).user()

To get the suggestions you would have to write it without referencing the context adding the reference later, which predisposes you to forget it and create bugs.

Is there a way to fix it (maybe in the tsconfig)?

4

1 回答 1

4

您可以通过键入上下文来获得智能感知:

import { Prisma } from '../generated/prisma-client';
export interface Context{
  prisma: Prisma;
}

const user = (parent, args, context: Context, info) => context.prisma.bodyweight({id: parent.id}).user()

您还应该检查 graphqlgen。这将允许您自动键入解析器。https://github.com/prisma/graphqlgen#graphqlgen

于 2019-01-08T11:09:35.423 回答