# Fetching Records

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.

### **Basic Query Structure**

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`.

### **The `edges`, `node`, and `pageInfo` Pattern**

This 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`.

### Example Query

Let's assume we have the following Client Portal Noloco App, with a `Project` table

<figure><img src="/files/STRQs3As5RT10bMdqV6d" alt=""><figcaption></figcaption></figure>

You can fetch all of the projects and their `name` with the following GraphQL Query:

```
query {
  projectsCollection {
    edges {
      node {
        id
        uuid
        name
      }
    }
    pageInfo {
      hasNextPage
    }
  }
}
```

#### **Query Arguments**

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.
* **sort:** An array of objects specifying the fields and directions for sorting records. Example: `sort: [{ field: "name", direction: "ASC" }]`.
  * The sorting respects the order of the entries (tie-breaking)
  * Repeated fields are ignored, the first one is used.
  * Only the first 3 entries in the array are used.
  * The fields must be a valid field on the table.
* **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" } }`.

#### **Deprecated Arguments**

* **orderBy:** A single object used to specify which field to sort by and the direction. Example: `orderBy: { field: "name", direction: "ASC" }`. Prefer using `sort` instead.

#### **Example Query with Arguments**

Here's how you might fetch the first 10 projects, ordered by name:

```graphql
query {
  projectsCollection(first: 10, sort: [{field: "name", direction: ASC}]) {
    edges {
      node {
        id
        name
      }
    }
  }
}
```

### **Conclusion**

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.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://guides.noloco.io/api-documentation/api-overview/fetching-records.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
