Cauen / prisma-generator-pothos-codegen

The fastest way to create a fully customizable CRUD Graphql API from Prisma Schema.
https://www.npmjs.com/package/prisma-generator-pothos-codegen
95 stars 16 forks source link

resolver return type doesn't match #44

Closed larsivi closed 1 year ago

larsivi commented 1 year ago

I think I have the basics in place now (a schema, generated pothos and autocrud). However, compiling the project cause errors as seen at the bottom. The reason seems to be that the type of resolve doesn't match the actual output from the prisma API. I think I perhaps can fix this via the replacer functionality, but it also seems that this should come out correct from the initial generate phase.

I have the following config:

crud: { outputDir: './src/generated/crud/', prismaCaller: '_context.db', disabled: false, builderImporter: "import { builder } from '../../builder';", // inputsImporter: "import * as Inputs from '@/schema/inputs'", deleteOutputDirBeforeGenerate: true, exportEverythingInObjectsDotTs: true, prismaImporter: import { Prisma } from '../client';, }, inputs: { builderImporter: "import { builder } from '../../builder';", prismaImporter: import { Prisma } from '../client';, outputFilePath: './src/generated/crud/inputs.ts', },

`src/generated/crud/Customer/mutations/deleteOne.base.ts:10:7 - error TS2322: Type 'Promise' is not assignable to type 'MaybePromise<readonly unknown[]> | null | undefined'. Type 'Promise' is not assignable to type 'Promise<readonly unknown[]>'. Type 'Customer' is not assignable to type 'readonly unknown[]'.

10 await _context.db.customer.delete({ where: args.where, ...query }),


  ../../../node_modules/.pnpm/@pothos+plugin-prisma@3.47.2_@pothos+core@3.29.0_@prisma+client@4.14.0_graphql@16.6.0_typescript@4.9.4/node_modules/@pothos/plugin-prisma/dts/types.d.ts:152:224
    152 export type PrismaFieldResolver<Types extends SchemaTypes, Model extends PrismaModelTypes, Parent, Param extends TypeParam<Types>, Args extends InputFieldMap, Nullable extends FieldNullability<Param>, ResolveReturnShape> = (query: {
153     include?: Model['Include'];
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
154     select?: Model['Select'];
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
155 }, parent: Parent, args: InputShapeFromFields<Args>, context: Types['Context'], info: GraphQLResolveInfo) => ShapeFromTypeParam<Types, Param, Nullable> extends infer Shape ? [Shape] extends [[readonly (infer Item)[] | null | undefined]] ? ListResolveValue<Shape, Item, ResolveReturnShape> : MaybePromise<Shape> : never;
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The expected type comes from the return type of this signature.

`

Cauen commented 1 year ago

Hi @larsivi Its seems like a error at config pothos builder types.

Can you please share a minimal reproducible example?

larsivi commented 1 year ago

Sorry about this (again), learning to fully exhaust the problem solving opportunities. Setting up the minimal example, I noticed the same issue, but tacked on to the bottom there was also a note on objects.d.ts not compiling. This didn't show up in my project, but when I tried to compile my objects.d.ts I saw that it didn't compile either. This was a generation config error, so when fixing that, everything did in fact compile :)