Cannot provide array of objects in GraphQL mutation through Apollo

Viewed 174

I'm building app in Gatsby using Apollo to fetch and send data to CMS via GraphQL. All variables declared as Stringworks as expected but when I try to send an array of 5 objects, in console it gets empty array. What's interesting, when I try to do the same operation through Insomnia, GraphiQL app or even Apollo DevTools, all variables work.

Here's my query

const ADD_REVIEW = gql`
  mutation AddReview(
    $name: String!
    $caption: String!
    $shopifyId: String!
    $rate: [Json!]
  ) {
    createReview(
      data: {
        author: $name
        caption: $caption
        shopifyId: $shopifyId
        rate: $rate
      }
    ) {
      id
      author
      caption
      rate
      shopifyId
    }
  }
`

here's array of objects I want to send through mutation

 const [stars, setStars] = useState([
    {
      key: 1,
      checked: true,
    },
    {
      key: 2,
      checked: true,
    },
    {
      key: 3,
      checked: true,
    },
    {
      key: 4,
      checked: false,
    },
    {
      key: 5,
      checked: false,
    },
  ])

and here's submit function

const [addReview, { data }] = useMutation(ADD_REVIEW)

.
.
.

const handleSubmit = (e) => {
    e.preventDefault()
    let shopifyId = 'new id'
    addReview({
      variables: { name, caption, shopifyId, stars },
    }).then((res) => console.log(res, data))
  }

Does anyone know where I made mistake?

0 Answers
Related