graphql-nexus / nexus-plugin-prisma

Deprecated
MIT License
829 stars 118 forks source link

Getting Missing types enums and Inputs #419

Open shoaibsharif opened 4 years ago

shoaibsharif commented 4 years ago

here is my schema on schema.prisma

model Offer {
  id String @default(cuid()) @id
  title              String
  gallery   String[]
  author     User

  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt

}

model User {
  id                           String        @default(cuid()) @id
  name                         String
  email                        String        @unique
  password                     String
  gender       GENDERS
}
enum GENDERS {
  MALE
  FEMALE
  OTHER
}

when I try to create Mutation I tried to do this:

export const Mutation = mutationType({
  definition(t){
t.field('signup', {
      type: 'AuthPayload',
      args: {
        name: stringArg({ required: true }),
        email: stringArg({ required: true }),
        password: stringArg({ required: true }),
        gender: arg({ type: 'GENDERS' })
      },
      resolve: async (parent, { name, email, password, gender }, ctx) => {
        const hashedPassword = await hash(password, 10);
        const user = await ctx.photon.users.create({
          data: {
            name,
            email,
            password: hashedPassword,
            gender,
          }
        });
        return {
          token: sign({ userId: user.id }, APP_SECRET),
          user
        };
      }
    });
 t.field('createOffer', {
      type: 'Offer',
      args: {
        title: stringArg({ required: true }),
        description: stringArg({ required: true }),
        price: floatArg({ required: true }),
        discountprice: floatArg(),
        discountPercentage: floatArg(),
        url: stringArg(),
        thumbnail: stringArg(),
        gallery: arg({ type: 'OfferCreategalleryInput' })
      },
      resolve: async (parent, args, ctx) => {
        return ctx.photon.offers.create({
          data: {
            ...args,
            author: {
              connect: {
                id:ctx.request.userId
              }
            }
          }
        });
      }
    });
}
)}

when I run the server, I get this error

- Missing type GENDERS, did you forget to import a type to the root query?
- Missing type OfferCreategalleryInput, did you forget to import a type to the root query or mean OfferWhereUniqueInput?

But I tried to use t.crud.createOneOffer() or anything with t.crud.(which was not in nexus documentation I want to mention that), it solves the problem. So Is there any workaround with this?

I am using:

    "ts-node": "8.4.1",
    "ts-node-dev": "1.0.0-pre.43",
    "typescript": "3.6.3",
    "prisma2": "2.0.0-alpha.193",
    "nexus": "0.12.0-beta.9"
darrylyoung commented 4 years ago

Hi, @shoaibsharif. Did you find a proper solution to this? I've come across a few people now – myself included – who's seen this issue. As you mentioned, the only way other than manually writing input types for everything is to expose the related crud operation and then that seems to work in generating the required types.

shoaibsharif commented 4 years ago

I couldn’t find any solution after that. Please let me know to if you can find any.

Bjoernstjerne commented 4 years ago

I get my enums with this:

import { enumType } from '@nexus/schema';
import * as photon from '../generated/photon/photonC';

export const Gender = enumType({
    name: 'Gender',
    members: photon.Gender,
});

I did not renamed photon to prisma but it is working with latest beta version. Most of my inputTypes are rewritten not only due to this behavior, often I don`t wanted to expose all fields.