Skip to content

Is there any way to restrict a Pothos input implementation to only contain the fields of the backing type? #815

Answered by hayes
elimist3 asked this question in Q&A
Discussion options

You must be logged in to vote

You could use satisfies to limit what fields can be defined:

type CreateUser = {
  firstName: string;
  lastName: string;
};

const CreateActivityInputRef = builder.inputRef<CreateUser>('CreateUserInput').implement({
  fields: (t) =>
    ({
      firstName: t.string({ required: true }),
      lastName: t.string({ required: true }),
      someOtherField: t.string({ required: true }), // <---------  any way to disallow fields like this that don't exist in CreateUser?
    } satisfies Record<keyof CreateUser, InputFieldRef<unknown>>),
});

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by elimist3
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants