Enhance your GraphQL API with filters.
Use this library to let the user filter through the results of a GraphQL query.
Here is an implementation of this library.
Try this query:
{
nodes(filter: {
schema: { is: vehicle },
fields: {
vehicle: {
price: {
lt: 2000000
}
}
}
}) {
elements {
fields {
... on vehicle {
name
price
}
}
}
}
}
Play around with the autocompletion to see whats possible.
Create your filter by implementing the Filter
interface or by extending one of the predefined abstract filters. It is best to create your filter by composing the small predefined filters.
See AbstractFilterTest.java to see an example of how to integrate this library in your environment.
Filter
The main Filter interface. Every filter implements this.FilterField
can be used to create filters that can easily be nested in other filters.StartFilter
is used to easily create the argument object forgraphql-java
MainFilter
A filter that does not filter directly and instead contains a collection of other filters.StartMainFilter
Same as above but additionally implements StartFilter.MappedFilter
Used to map a type into another type using another FilterCommonFilters
Provides common filters which can be used for all types. This includes these logical operations of filters:and
,or
andnot
.
The following filters can be used to filter primitive types: BooleanFilter
, DateFilter
, NumberFilter
, StringFilter
.
See NodeFilter.java as an example filter implementation.