Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting Missing types enums and Inputs #419

Open
shoaibsharif opened this issue Sep 22, 2019 · 3 comments
Open

Getting Missing types enums and Inputs #419

shoaibsharif opened this issue Sep 22, 2019 · 3 comments

Comments

@shoaibsharif
Copy link

shoaibsharif commented Sep 22, 2019

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
Copy link

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
Copy link
Author

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

@Bjoernstjerne
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants