graphql-boilerplates / react-fullstack-graphql

Starter projects for fullstack applications based on React & GraphQL.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to query nested arrays?

jkhaui opened this issue · comments

This isn't so much an issue, but I've searched everywhere and can't really find an answer specific to my problem with nested queries using the Apollo boilerplate.

I'm using the basic boilerplate and have modified FeedPage.js and its associated query to fit my own GraphQL server. It works great for the most part; except when I try to query an array nested within a parent array. For example, consider this query:

query {
posts {
nodes {
id
content
comments {
nodes {
id
content
}
}
}
}
}

Now, the following code works:

        <Fragment>
          <h1>Feed</h1>
          {data.posts &&
            data.posts.nodes.map(post => (
              <Post
                key={post.id}
                post={post}
                refresh={() => refetch()}
              />
            ))}
          {this.props.children}
        </Fragment>

But my issue is: what if I want to return comment.content, and map a list of comments to keys?

I'm really stuck here and would greatly appreciate some guidance. Thanks!