paljs / prisma-tools

Prisma tools to help you generate CRUD system for GraphQL servers
https://paljs.com
MIT License
687 stars 55 forks source link

No order by relation #236

Closed terion-name closed 3 years ago

terion-name commented 3 years ago

Migrating to 4th version, while testing got strange error. Updated all libs (see below) but it didn't help.

Libs:

    "@paljs/generator": "^4.0.12",
    "@paljs/plugins": "^4.0.8",
    "@paljs/schema": "^4.0.6",
    "@prisma/client": "^3.1.1",
    "@prisma/debug": "^3.1.1",
    "@prisma/sdk": "^3.1.1",

Compiled client:

/**
 * Prisma Client JS version: 3.1.1
 * Query Engine version: b8c35d44de987a9691890b3ddf3e2e7effb9bf20
 */
Prisma.prismaVersion = {
  client: "3.1.1",
  engine: "b8c35d44de987a9691890b3ddf3e2e7effb9bf20"
}

Given operation:

const gql = require("graphql-tag");
module.exports = {
  "query": gql`query categoriesQuery($where: CategoryWhereInput, $orderBy: [CategoryOrderByWithRelationInput!], $cursor: CategoryWhereUniqueInput, $distinct: [CategoryScalarFieldEnum!], $skip: Int, $take: Int) {
  categories(
    where: $where
    orderBy: $orderBy
    cursor: $cursor
    distinct: $distinct
    skip: $skip
    take: $take
  ) {
    ...CategoryFlat
  }
}

fragment CategoryFlat on Category {
  id
  slug
  color
  display
  createdAt
  updatedAt
}
`,
  "variables": {
    "where": {
      "id": {
        "notIn": "ckucnhmy200002tsd3bpy270m"
      },
      "translations": {
        "some": {}
      },
      "display": {
        "in": "ACTIVE",
        "notIn": "INACTIVE"
      }
    },
    "orderBy": [
      {
        "surveys": {
          "_count": "asc"
        }
      }
    ]
  },
  "fetchPolicy": "no-cache"
}

Where CategoryOrderByWithRelationInput is:

input CategoryOrderByWithRelationInput {
        id: SortOrder
          slug: SortOrder
          color: SortOrder
          translations: CategoryTranslationOrderByRelationAggregateInput
          display: SortOrder
          surveys: SurveyOrderByRelationAggregateInput
          }

And resolver is default:

categories: (_parent, args, { prisma }) => {
      return prisma.category.findMany(args)
    },

Results in:

Invalid `prisma.category.findMany()` invocation:

{
  where: {
    id: {
      notIn: [
        'ckucnhmy200002tsd3bpy270m'
      ]
    },
    translations: {
      some: {}
    },
    display: {
      in: [
        'ACTIVE'
      ],
      notIn: [
        'INACTIVE'
      ]
    }
  },
  orderBy: [
    {
      surveys: {
      ~~~~~~~
        _count: 'asc'
      }
    }
  ],
  select: {
    id: true,
    slug: true,
    color: true,
    display: true,
    createdAt: true,
    updatedAt: true
  }
}

Unknown arg `surveys` in orderBy.0.surveys for type CategoryOrderByInput. Did you mean `select`? Available args:
type CategoryOrderByInput {
  id?: SortOrder
  slug?: SortOrder
  color?: SortOrder
  display?: SortOrder
  createdAt?: SortOrder
  updatedAt?: SortOrder
}

Why prisma client knows nothing about CategoryOrderByWithRelationInput?

terion-name commented 3 years ago

Sorry, forgot to update prisma dep