Fetching Records
Fetch records from the API
Last updated
Fetch records from the API
Last updated
Fetching data is a fundamental operation when working with APIs. In Noloco's dynamic GraphQL API, this is accomplished using GraphQL Queries. This guide will introduce you to the pattern and arguments used to fetch records with precision and efficiency.
Queries for fetching records are named based on the table you're looking to retrieve data from. The naming convention is <tableName>Collection
, where <tableName>
represents the name of your table. For instance:
To fetch projects, use projectsCollection
.
To fetch users, use usersCollection
.
edges
, node
, and pageInfo
PatternThis structure allows you to navigate through your data with ease:
edges: This represents the connection between nodes. Within edges
, you can query the node
to access the fields of that record.
pageInfo: Contains metadata about the current page of results, useful for pagination. Fields commonly available include hasNextPage
, hasPreviousPage
, and startCursor
.
Let's assume we have the following Client Portal Noloco App, with a Project
table
You can fetch all of the projects and their name
with the following GraphQL Query:
You can refine your data retrieval using the following arguments:
first: Limits the number of records returned. For example, first: 5
will return only the first five records.
before: Cursor for pagination. Used in combination with pageInfo
to retrieve records before a certain point.
after: Cursor for pagination. Used in combination with pageInfo
to retrieve records after a certain point.
orderBy: An object that specifies which field to sort by and the direction of sorting. Example: orderBy: { field: "name", direction: "ASC" }
.
where: Allows you to filter records based on field values. The structure of the filter object varies depending on the field type. For instance, for a text field, you might use: where: { fieldName: { equals: "desiredValue" } }
.
Here's how you might fetch the first 10 projects, ordered by name:
Noloco's integration with GraphQL provides a powerful and flexible way to fetch and manipulate data. With a solid understanding of the patterns and arguments available, you can tailor your queries to retrieve precisely the data you need. As you become more accustomed to these structures, you'll find it becomes second nature to craft efficient and effective queries.