Have your say in Community Polls: What was/is your greatest motivation to start your own business?
Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

GraphQL Orders Edges and Nodes

Solved

GraphQL Orders Edges and Nodes

edwinv
Tourist
4 0 3

What is the difference between these node and nodes?

Looking through the explorer they have the same fields and when I use them I get the same results, but I may be overlooking something.

 

query MyQuery {
  orders(first: 1) {
    nodes{}
    edges {
      node{}
    }
  }
}

 

Accepted Solution (1)

ShopifyDevSup
Shopify Staff
1453 238 524

This is an accepted solution.

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


 

Developer Support @ Shopify
- Was this reply helpful? Click Like to let us know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

View solution in original post

Reply 1 (1)

ShopifyDevSup
Shopify Staff
1453 238 524

This is an accepted solution.

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


 

Developer Support @ Shopify
- Was this reply helpful? Click Like to let us know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog