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

Issue with updateMany mutation #37

Closed DennisMG closed 1 year ago

DennisMG commented 1 year ago

I'm getting this error when trying to use updateMany (salesOrder is the name of my prisma model)

{
  "data": {},
  "errors": [
    {
      "message": "Cannot read properties of undefined (reading 'salesOrder')",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "updateManySalesOrder"
      ],
      "extensions": {
        "code": "INTERNAL_SERVER_ERROR",
        "stacktrace": [...]
      }
    }
  ]
}

I went to the the generated mutation file and console.log the _context object from the resolver, and indeed didn't have the prisma object in it.

import * as Inputs from '../../inputs';
import { BatchPayload } from '../../objects';
import { defineMutation, defineMutationFunction, defineMutationObject } from '../../utils';

export const updateManySalesOrderMutationObject = defineMutationFunction((t) =>
  defineMutationObject({
    type: BatchPayload,
    nullable: false,
    args: {
      where: t.arg({ type: Inputs.SalesOrderWhereInput, required: false }),
      data: t.arg({ type: Inputs.SalesOrderUpdateManyMutationInput, required: true }),
    },
    resolve: async (_root, args, _context, _info) =>
      await _context.prisma.salesOrder.updateMany({ where: args.where || undefined, data: args.data }),
  }),
);

export const updateManySalesOrderMutation = defineMutation((t) => ({
  updateManySalesOrder: t.field(updateManySalesOrderMutationObject(t)),
}));

I checked other mutations for example the createMany and noticed that in the resolver the first argument had _query, so I tried adding that to the updateMany resolver and it worked!!

My updateMany mutation now looks like this but is complaining image

I'm not sure if I'm doing something wrong. I'm using the same versions recommended in the readme.

    "@pothos/core": "3.23.0",
    "@pothos/plugin-prisma": "3.37.0",
    "@prisma/client": "4.7.0",
    "graphql": "16.6.0",
    "prisma": "4.7.0"
Cauen commented 1 year ago

@DennisMG There was a small autocrud error that i was missed on #24 fix Its now fixed in 0.5.6 :D

Can you please update and regenerate? e.e

DennisMG commented 1 year ago

Is working now! Thanks a lot!