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
102 stars 19 forks source link

Build error for deleteMany and updateMany #36

Closed elritz closed 1 year ago

elritz commented 1 year ago

Check out your generated files folder:

I am getting this error, only for these files

Type 'Promise<BatchPayload>' is not assignable to type 'MaybePromise<readonly unknown[]> | null | undefined'.
  Type 'Promise<BatchPayload>' is not assignable to type 'Promise<readonly unknown[]>'.
    Type 'BatchPayload' is missing the following properties from type 'readonly unknown[]': length, concat, join, slice, and 19 more.ts(2322)
builder-options.d.ts(10, 71): The expected type comes from the return type of this signature.

What this means is I cant build a project. Let me know if you get the same error I have updated the packages but i also downgraded them to make sure, also I am using pnpm.

   "prisma": "^4.9.0",

   "prisma-generator-pothos-codegen": "^0.5.5",

    "@pothos/core": "^3.24.0",
    "@pothos/plugin-directives": "^3.9.1",
    "@pothos/plugin-federation": "^3.7.0",
    "@pothos/plugin-prisma": "^3.40.2",
    "@pothos/plugin-prisma-utils": "^0.5.0",
    "@pothos/plugin-relay": "^3.33.1",
    "@pothos/plugin-simple-objects": "^3.6.7",
    "@pothos/plugin-with-input": "^3.10.0",
Cauen commented 1 year ago

Hi @elritz

Can you please share a minimal, reproducible example? in a Github repo?

Anyway, do these issues happen in your environment when using the sample project?

DennisMG commented 1 year ago

@elritz I had the same issue, I fixed it by going into the file where the BatchPayload object is generated and fixed the prisma import.

Cauen commented 1 year ago

@DennisMG Does setting inputs.prismaImporter at config.js resolve this issue?

{
  /** Input type generation config */
  inputs?: {
    /** Create simpler inputs for easier customization and ~65% less generated code. Default: `false` */
    simple?: boolean;
    /** How to import the Prisma namespace. Default: `"import { Prisma } from '.prisma/client';"` */
>>  prismaImporter?: string;
    /** How to import the Pothos builder. Overrides global builderImporter config. Default: `"import { builder } from './builder';"` */
    builderImporter?: string;
    /** Path to generate the inputs file to from project root. Default: `'./generated/inputs.ts'` */
    outputFilePath?: string;
    /** List of excluded scalars from generated output */
    excludeScalars?: string[];
    /** A function to replace generated source. Combined with global replacer config */
    replacer?: Replacer<'inputs'>;
  };
DennisMG commented 1 year ago

@Cauen This is my config file. I have prismaImporter set for both crud and inputs. but the import is missing from all the files, seems like is ignoring the setting.

module.exports = {
  inputs: {
    simple: true,
    outputFilePath: "./graphql/__generated__/inputs.ts",
    prismaImporter: `import prisma from "../../../../../lib/prisma"`,
  },
  crud: {
    outputDir: "./graphql/__generated__/",
    inputsImporter: `import * as Inputs from '../inputs';`,
    prismaImporter: `import prisma from "../../../../../lib/prisma"`,
    prismaCaller: "prisma",
    disabled: false,
  },
  global: {
    builderImporter: `import { builder } from '../../pages/api/builder';`,
  },
}
DennisMG commented 1 year ago

I managed to get it working. Now my config file looks like this:

module.exports = {
  inputs: {
    outputFilePath: "./graphql/__generated__/inputs.ts",
    prismaImporter: `import { Prisma } from "@prisma/client";`,
    prismaCaller: "_context.prisma",
  },
  crud: {
    outputDir: "./graphql/__generated__/",
    inputsImporter: `import * as Inputs from '../inputs';`,
    prismaImporter: `import { Prisma } from "@prisma/client";`,
    prismaCaller: "_context.prisma",
    disabled: false,
  },
  global: {
    builderImporter: `import { builder } from '../../pages/api/builder';`,
  },
}

I added the prismaCaller: "_context.prisma", and now I'm sending the db connection through the server context like this:

const server = new ApolloServer({
  schema,
})

export default startServerAndCreateNextHandler(server, {
  context: async (req, res) => ({ prisma }),
})
Cauen commented 1 year ago

Closing the issue, once we have the probable solution Thanks @DennisMG