graphql-nexus / nexus-plugin-prisma

Deprecated
MIT License
828 stars 118 forks source link

Generated types missing relations possibly #234

Closed DevanB closed 5 years ago

DevanB commented 5 years ago

I'm unsure if this is a nexus-prisma issue, an issue at all, or if I am perhaps misunderstanding something.

I have the following User type in my datamodel.graphl

type User {
  id: ID! @unique
  email: String! @unique
  firstName: String!
  lastLogin: DateTime
  lastName: String!
  organization: Organization! @relation(name: "UsersByOrganization")
  password: String!
  roles: [Role!]! @relation(name: "RolesByUser")
  settings: [Setting!]! @relation(name: "SettingsByUser")
  subscription: StripeSubscription @relation(name: "StripeSubscriptionByUser")
}

When I do the following in my server:

const updatedUser = await this.ctx.prisma.updateUser({
    data: {
        lastLogin: new Date().toISOString(),
        updatedBy: { connect: { id: user.id } },
    },
    where: { id: user.id },
});

I expect to find that updatedUser would have a roles value, however it doesn't. It also seems to be missing organization, settings and subscription, which are all relationships.

The User interface (even after running prisma generate several times) is in fact:

export interface User {
  id: ID_Output;
  email: String;
  firstName: String;
  lastLogin?: DateTimeOutput;
  lastName: String;
  password: String;
}

Am I misunderstanding relationships, or is my generated types missing fields for a reason?

Thanks much! 😄

difagume commented 5 years ago

The same thing happens to me, I'm using: nexus: 0.11.6, nexus-prisma: 0.3.5, prisma-client-lib: 1.30.0, typescript: 3.4.2, ts-node: 8.0.3

for example in my scheme I have:

type Articulo_detalle {
  activo: Boolean!
  articulo: Articulo!
  cantidad: Int!
  id: ID!
  producto: Producto!
}

but by looking at the file nexus.js I have:

Articulo_detalle: { // root type
    activo: boolean; // Boolean!
    cantidad: number; // Int!
    id: string; // ID!
  }

as well as in the index.ts file of the generated/prisma-client directory:

export interface Articulo_detalle {
  id: ID_Output;
  cantidad: Int;
  activo: Boolean;
}

The relationship to Producto is being lost.

Weakky commented 5 years ago

Hey 👋,

This is related to the prisma-client rather than nexus-prisma. But yeah, it's expected that roles aren't fetched by default because it's a relation, and the client only fetches scalar values by default.

The only way to fetch relations and scalars right now is by using fragments until the client V2 API lands: https://github.com/prisma/rfcs/pull/2

Hopefully that answers your question. If it doesn't, feel free to re-open 🙌

DevanB commented 5 years ago

I believe I understand this. Re: using fragments...is this what you have done here and here?

Thanks for the information @Weakky!