Just pass (entire 'composed/prepared earlier') value for filter
(define at query) variable. Leaving this variable undefined makes it optional.
query GetUsers($filter: SomeFilterInputType) {
users(
first: 10,
filter: $filter ) {
pass value for filter
in [query] variables:
{
filter: { search: 'sth'}
}
... where SomeFilterInputType
is a [users
query] arg type name, it can be read from API specs, available in graphiql/playground docs ... or server code/type defs
It can be tested in graphiql/playground using QUERY VARIABLES.
variables
passed from JavaScript is an object with the same structure, easily created/modified conditionally.
In this case SomeFilterInputType
(no !
mark after type name) means it (filter
variable) can be nulled/undefined - usually optional args are nullable (not required). If some arg is required in API/BE specs then it must be required in client, too.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…