Skip to main content

Filtering

To filter results, we use the filter argument. It takes the ConnectionFilterInput corresponding to the entity we're retrieving as a value. These inputs are defined as:

input ExampleConnectionFilterInput {
_and: [ExampleConnectionFilterInput!]
_or: [ExampleConnectionFilterInput!]
url: ConnectionStringFilterInput
# ...and so on for other field types like Boolean, Date, Int etc.
}

Each field in the ConnectionFilterInput can be filtered by a subset of predicates available for the given data type. For example String fields use ConnectionStringFilterInput:

input ConnectionStringFilterInput {
beginsWith: String
contains: String
endsWith: String
eq: String
in: [String!]
isEmpty: Boolean
isNull: Boolean
matchesRegex: String
ne: String
notContains: String
notIn: [String!]
notMatchesRegex: String
}

The _and and _or arrays are special properties allowing to write more complex filters. ConnectionFilterInput objects in the _and array are combined using logical AND operator, and those inside _or array are combined using logical OR operator. All root-level conditions are always combined using logical AND operator. That means a filter such as this:

{
_and: [
{ sitemapsInCount: { eq: 0 } }
],
_or: [
{ url: { contains: "news" } },
{ url: { contains: "guides" } }
],
hasStructuredData: { eq: false }
}

is exactly the same as:

{
_and: [
{ sitemapsInCount: { eq: 0 } },
{
_or: [
{ url: { contains: "news" },
{ url: { contains: "guides" }
]
},
{ hasStructuredData: { eq: false } },
]
}

Example - Getting Projects with a filter

query getAccount($id: ObjectID!) {
getAccount(id: $id) {
projects(
filter: {
_or: [{ name: { eq: "Google" } }, { name: { eq: "Wikipedia" } }]
}
) {
nodes {
name
}
}
}
}

Try in explorer