0

I have a blog in JavaScript and I'm using Apollo GraphQL to save my data. I intend to get six articles of three categories. So I make a request to take all posts of one category and repeat this request three times with the categories's id's.

So, I intend to transform my three requests in only one, but I can't.

My code:

{
  allPosts(where: {category: "id"}, first: 6) {
    edges {
      node {
        title
        image
      }
    }
  }
}

Charles Braga
  • 488
  • 1
  • 4
  • 11

1 Answers1

0

You can use aliases for your request (maybe you need to adjust the fragment):

{
  firstCategory: allPosts(where: {category: "firstId"}, first: 6) {
    ...fields
  }

  secondCategory: allPosts(where: {category: "secondId"}, first: 6) {
    ...fields
  }
}

fragment fields on Post {
  edges {
    node {
      title
      image
    }
  }
}
pzaenger
  • 11,381
  • 3
  • 45
  • 46