0

I have been working with apollo-nuxt to query my graphql, but run into some weird issues while doing so. First of all this is my query:

{
  getOrder(quantity: 2) {
    id
    createdAt
    content {
      amount
      productId
    }
  }
}

which returns the following at /graphqli:

{
  "data": {
    "getOrder": [
      {
        "id": null,
        "createdAt": 1592224281,
        "content": [
          {
            "amount": 5,
            "productId": "Salad"
          },
          {
            "amount": 2,
            "productId": "Water"
          }
        ]
      },
      {
        "id": null,
        "createdAt": 1592224264,
        "content": [
          {
            "amount": 5,
            "productId": "Whine"
          },
          {
            "amount": 3,
            "productId": "Water"
          }
        ]
      }
    ]
  }
}

this is as expected. Now using the same query in apollo (nuxt code):

<script>
import gql from 'graphql-tag'
export default {
  apollo: {
    orders: gql` query order {
    orders: getOrder(quantity: 2) {
    id
    createdAt
    content {
      amount
      productId
    }
  }
 }`
  },
...

will produce this result:

Screenshot of array content in Vue tools

I cannot explain why the same query produces two different results. One with the two different objects in the array and the apollo one with two times the same object in an array. When adding more (by increasing the quantity) I just get more of the same object in the array. What am I missing here?

1 Answer 1

1

Your id for both orders is the same value (null) so Apollo ends up using the cache key for both orders (Order:null) and the orders field ends up referring to the same key twice. You need to fix your backend so that id is resolved correctly to a unique value for each Order.

Sign up to request clarification or add additional context in comments.

1 Comment

thanks I wasn't using the id parameter as this would follow with the implementation of a db (which I am currently mocking)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.