Input Objects


With t.object out of the way, let’s move on to t.inputObject. Use this type factory to create objects to be used inside resolver arguments:

/** Creating an input object from neutral types */
const ProfileArgs = t.inputObject({
  name: 'SignupArgs',
  fields: {
    fullName: t.string.nullable,
    membership: Membership,
    email: t.string,
  },
});

/** Creating an input object from another input type */
const UpdateProfileArgs = t.inputObject({
  name: 'UpdateProfileArgs',
  fields: {
    userId: t.id,
    profile: ProfileArgs,
  },
});
/** TypeScript */

type ProfileArgs = {
  fullName: string | null | undefined;
  membership: Membership;
  email: string;
};

type UpdateProfileArgs = {
  userId: string | number;
  profile: ProfileArgs;
};
# GraphQL:

input ProfileArgs {
  fullName: String;
  membership: !Membership;
  email: !String;
};

input UpdateProfileArgs {
  userId: !ID;
  profile: !ProfileArgs;
};
Edit on GitHub