Using GQL from Apollo/client default variables results in "Unexpected end of JSON input"

Viewed 42

I am trying to pass default variables to my gql query in React :

query getQuery($id: UUID!, $current: Boolean = true) {
  myQuery(id: $id) {
    id
    name
    versions (current: $current) {
      id
    }
  }
}
useQuery(MY_QUERY, {
  fetchPolicy: 'network-only',
  notifyOnNetworkStatusChange: true,
  variables: {
    id: myId
  },
});

But i have an error Error: Unexpected end of JSON input

1 Answers

looks like everything are ok with your default value. It's work I think you should search for an error in another place request payload

import {gql} from '@apollo/client';

export const getQuery = gql`
    query getQuery($id: UUID!, $current: Boolean = true) {
        myQuery(id: $id) {
            id
            name
            versions (current: $current) {
                id
            }
        }
    }`;

Related