Queries
Graphback provides two query types for every model in the schema.
find<Type>s
: fetch all or a subset of items through optional filtering, pagination and sorting.get<Type>
: fetch a single item by its unique ID.
#
FindThe find
operation allows the client to fetch multiple items from the database, with optional filtering, pagination and ordering of the data allowing you to specify exactly the data you need.
The query follows the naming format find<Type>s
:
Arguments:
filter
: filter object to query specific data.page
: enables pagination of the data.orderBy
: sorts the data in ascending or descending order.
The items fetched by findNote
are returned in a container type NoteResultList
created by Graphback:
Example of a simple query to retrieve all notes:
#
FilteringGraphback generates all the appropriate schema elements from GraphQLCRUD and provides a mapping implementation for both PostgreSQL and MongoDB. This lets you perform simple or complex querying of your data directly from GraphQL queries.
Take an example Note
model, which uses each of the built-in scalar types: ID
, String
, Boolean
, Int
, Float
.
Graphback generates a filter input type for each model in the schema.
So you can perform filtering of the data like this:
#
OperatorsThis is a list of all available filter operators.
Operator | Meaning | Scalars |
---|---|---|
eq | Equal to | All |
ne | Not equal to | All |
lt | Less than | All |
le | Less than or equal to | All |
gt | Greater than | All |
gt | Greater than or equal to | All |
between | Between a range (of numbers) | Int, Float |
in | In a list of items | All |
contains | String contains | String |
startsWith | String starts with | String |
endsWith | String ends with | String |
Each field in the NoteFilter
input maps to a generated scalar input. This specifies the operators available for that scalar.
#
PaginationYou can perform pagination with the page
argument.
#
OrderingTo sort/order items by a certain field, use the orderBy
argument.
#
GetThe get
operation allows the client to fetch a single item from the database by its unique ID.
The query follows the naming format get<Type>
:
Arguments:
id
: The unique ID of the object. This will always beid: ID
. The resolver will automatically map this to your primary key field.
Example of a query to retrieve a single user by their primary field (email):