graphql-nexus / nexus-plugin-prisma

Deprecated
MIT License
828 stars 118 forks source link

BatchRead plural is not added on specific type name for t.crud query #981

Open Sebdevar opened 3 years ago

Sebdevar commented 3 years ago

Version used: 0.24.0

For some weird reason I can't seem to explain just yet, the batchRead query isn't properly named during compilation when my object is named 'equipment', but works correctly if I change it to any other name.

Here's some actual code with multiple cases that work and the one that doesn't:

Prisma schema

model Channel {
  @@map("channel")

  id Int @id @default(autoincrement())

  name String @unique
  // other variables removed for the purpose of this issue
}

model ChannelCategory {
  @@map("channel_category")

  name String @id
  channels Channel[]
}

model Equipment {
  @@map("equipment")

  id Int @id
  name String @unique
}

ObjectTypes

Channel.ts

import { objectType } from '@nexus/schema';

export const Channel = objectType({
  name: 'Channel',
  definition(t) {
    t.model.id();
    t.model.name();
  }
});

ChannelCategory.ts

import { objectType } from '@nexus/schema';

export const ChannelCategory = objectType({
  name: 'ChannelCategory',
  definition(t) {
    t.model.name();
    t.model.channels();
  }
});

Equipment.ts

import { objectType } from '@nexus/schema';

export const Equipment = objectType({
  name: 'Equipment',
  definition(t) {
    t.model.id();
    t.model.name();
  }
});

QueryType

import { queryType } from '@nexus/schema';

export const Query = queryType({
  definition(t) {
    t.crud.channel();
    t.crud.channels({ ordering: true, filtering: true });
    t.crud.channelCategory();
    t.crud.channelCategories();
    t.crud.equipment();
    // t.crud.equipments(); <-- Property 'equipments' does not exist on type 'NexusPrismaFields<"Query">'.
  }
});

I also gave a quick glance inside the node_modules files for the generated t.crud object and found this: node_modules/@types/typegen-nexus-plugin-prisma/index.d.ts

// Prisma output types metadata
interface NexusPrismaOutputs {
  Query: {
    channel: 'Channel'
    channels: 'Channel'
    channelCategory: 'ChannelCategory'
    channelCategories: 'ChannelCategory'
    equipment: 'Equipment'
    equipment: 'Equipment'
    ...
  }
}

Any clues as to why this happens and how one could fix it, other than simply changing the name?

Sebdevar commented 3 years ago

still no comments on the issue?