Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GraphQL/Gatsby/Prismic - difference between 'edges.node.data' and 'nodes.data' in query

I'm following this tutorial on Medium to get Gatsby working with Prismic.

In the GraphiQL explorer, the two queries below both yield the same result and was wondering when I should use one over the other (i.e. edges.node.data vs nodes.data):

Query #1:

query Articles {
  articles: allPrismicArticle {
    edges {
      node {
        data {
          title {
            text
          }
          image {
            url
          }
          paragraph {
            html
          }
        }
      }
    }
  }
}

Query #2:

query Articles {
  articles: allPrismicArticle {
    nodes {
      data {
        title {
          text
        }
        image {
          url
        }
        paragraph {
          html
        }
      }
    }
  }
}

like image 948
epsilon42 Avatar asked Oct 05 '19 03:10

epsilon42


1 Answers

As you've found out, there's no difference at all. nodes can be thought of as a shortcut to edges.map(edge => edge.node). This'll save us a bit of typing when using the data returned by graphql.

There's a few case where querying edges is useful, for example in a allMarkdownRemark query, edges may contain helpful info like total posts.

like image 95
Derek Nguyen Avatar answered Nov 14 '22 04:11

Derek Nguyen