I am trying to do a very basic query via React with Apollo.
When I do this query in GraphiQL I nicely get my results back but in my app I get an undefined data object. And a error with a message:
Network error: Unexpected end of JSON input
The query is:
query {
category(id: 3) {
id
children {
id
name
}
}
}
This is my component
import React, { Component } from 'react';
import { Query } from 'react-apollo';
import gql from 'graphql-tag';
const CATEGORIES_LIST = gql`
query CATEGORIES_LIST {
category(id: 3) {
id
children {
id
name
}
}
}
`;
class Cat extends Component {
render() {
return (
<div>
<p>Items!</p>
<Query query={CATEGORIES_LIST}>
{payload => {
console.log(payload);
return <p>fetch done!</p>;
}}
</Query>
</div>
)
}
}
export default Cat;
While the GraphiQL response is with the exact same request
{
"data": {
"category": {
"id": 3,
"children": [
{
"id": 4,
"name": "Bags"
},
{
"id": 5,
"name": "Fitness Equipment"
},
{
"id": 6,
"name": "Watches"
}
]
}
}
}
By the way I'm querying a local Magento 2.3 graphql server.
When inspecting the network tab this is the response i get from the graphql endpoint. So no url typo are issue in the response
{
"data":{
"category":{
"id":3,
"children":[
{
"id":4,
"name":"Bags",
"__typename":"CategoryTree"
},
{
"id":5,
"name":"Fitness Equipment",
"__typename":"CategoryTree"
},
{
"id":6,
"name":"Watches",
"__typename":"CategoryTree"
}
],
"__typename":"CategoryTree"
}
}
}