Skip to content

How to query nested arrays? #493

@jkhaui

Description

@jkhaui

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions