oliveCshws
oliveCshws

Reputation: 75

graphql query with certain combination of parameters

I am looking to specify a certain required combination of parameters in a graphQL query.

The query should be valid either without any params and return all cats or filter by size AND species.

extend type Query {
    cats(size: String, species: String): [Cat]
}

Is the only way to do this via the resolver (throw error if one arg is passed) or is there a neater way?

Upvotes: 0

Views: 567

Answers (1)

puelo
puelo

Reputation: 6057

I don't believe that this is defined in the spec. You could define a new input type and then use this though.

input CatFilter {
    size: String!
    species: String!
}

extend type Query {
    cats(filter: CatFilter): [Cat]
}

That way the parameter is optional, but if given, both properties are required.

Upvotes: 1

Related Questions