GraphQL Orders Edges and Nodes

Hey @edwinv ,

Our GraphQL APIs currently support both the **nodes** and **edges.node** approaches to accessing data, but are generally used for different contexts and needs. Here is a bit more info to expand on the concepts:

  • edges.node - When using **edges.node, the data returned is organized using **edges and **node. The **edges array contains multiple objects, and each object represents an edge, or a connection, between the nodes (which store the actual data of interest). The returned data will generally look like this:

    {
    “data”: {
    “objectName”: {
    “edges”: [
    {
    “node”: {
    “id”: “1”,
    “name”: “value1”
    }
    },
    {
    “node”: {
    “id”: “2”,
    “name”: “value2”
    }
    }
    ]
    }
    }
    }

  • nodes - When using **nodes, the data is more streamlined, directly accessing the collection of data objects without additional layers of **edges and **node**. This makes parsing and handling the result more straightforward. The returned data will generally look like this:

    {
    “data”: {
    “objectName”: {
    “nodes”: [
    {
    “id”: “1”,
    “name”: “value1”
    },
    {
    “id”: “2”,
    “name”: “value2”
    }
    ]
    }
    }
    }

How you plan to approach pagination may require some additional investigation into these approaches. Usually, using **nodes** and **pageInfo** would be preferred, but if edge data is necessary, **edges** can be used to return a **cursor** and **node**. I would suggest taking a look into the GraphQL pagination docs here.

Ultimately, the essential object/connection data will be the same, but which approach used will depend on preference and specific needs. I hope this clarification helps - Cheers!

@awwdam | Shopify Developer Support

3 Likes