Nexus-plugin-prisma: Question: Remove an argument from an input type

Created on 4 Apr 2019  路  3Comments  路  Source: graphql-nexus/nexus-plugin-prisma

I have the following schema coming out of nexus which is built from the prisma schema.

type Mutation {
  createEvent(data: EventCreateInput!): Event!
}
input TennisTeam_EventCreateInput {
  name: String!
  owner: UserCreateOneWithoutEventsInput!
}

What I want to do is remove the owner argument from this type so it is not available when calling the mutation.

I have been trying to add the following but I don't know what syntax is required to remove the owner arg. The underlying prisma type has this but I want the server to set this value and not the client, thus removing the argument.

export const Mutation = prismaObjectType({
  name: "Mutation",
  definition(t) {
    t.prismaFields([
      {
        name: "createEvent",
        args: [???],
      }
    ]);
  }
});
notprisma1 typdocs

Most helpful comment

Hey there,

You have to override the input type by doing the following:

export const YourInputType = prismaInputObjectType({
  name: "YourInputType",
  definition(t) {
    t.prismaFields(['the field you want to keep', '...', ...])
  }
});

Closing, feel free to re-open if that doesn't help you 馃檶

All 3 comments

Hey there,

You have to override the input type by doing the following:

export const YourInputType = prismaInputObjectType({
  name: "YourInputType",
  definition(t) {
    t.prismaFields(['the field you want to keep', '...', ...])
  }
});

Closing, feel free to re-open if that doesn't help you 馃檶

What if we want to make available some fields for an admin, for instance, and hide them for a user?

I have orders, which clients can rename, but they can't change the status of the order. And admins can do whatever they want on the order.

I would have two mutations, but I don't know how to "extend" or "restrict" an InputObjectType without overriding it. I would like to duplicate it with more or less arguments.

Is that possible?

@Weakky great, thanks! I think it should be in docs

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jamesopti picture jamesopti  路  4Comments

antonbramsen picture antonbramsen  路  4Comments

jasonkuhrt picture jasonkuhrt  路  4Comments

sachaw picture sachaw  路  3Comments

colinhacks picture colinhacks  路  5Comments