How do I set up GraphQL query so one or another argument is required, but not both

Viewed 2963

I'm just getting to grips with GraphQL,

I have set up the following query: ​

type: UserType,
args: {
    id:    { name: 'id',    type: new GraphQLNonNull(GraphQLID)     },
    email: { name: 'email', type: new GraphQLNonNull(GraphQLString) }
},
resolve: (root, { id, email }, { db: { User } }, fieldASTs) => {
    ...
}

I would like to be able to pass either an 'id' or 'email' to the query, however, with this setup it requires both an id and email to be passed.

Is there a way to set up the query so only one argument is required, either id or email, but not both?

2 Answers
Related