Estoy usando un SWAPI Wrapper para este proyecto. Y parece que mi código es correcto, pero por alguna razón sigo recibiendo un JSON Parse error: Unexpected EOF cuando intento cargar los datos. Y cuando hago la siguiente consulta en el punto final de GraphQL, funciona:
{ allPeople { edges { node { id name birthYear gender homeworld { name } species { name } } } } } ... pero cuando lo hago en mi archivo, aparece el error mencionado anteriormente. A continuación se muestra mi código:
índice.js
import React from 'react'; import ReactDOM from 'react-dom'; import './index.css'; import App from './App'; import reportWebVitals from './reportWebVitals'; import{ ApolloClient, ApolloProvider, HttpLink, InMemoryCache, } from '@apollo/client' const client = new ApolloClient({ cache: new InMemoryCache(), link: new HttpLink({ uri: "https://graphql.org/swapi-graphql", useGETForQueries: true, fetchOptions: { mode: 'no-cors', } }) }) ReactDOM.render( <React.StrictMode> <ApolloProvider client={client}> <App /> </ApolloProvider> </React.StrictMode>, document.getElementById('root') ); reportWebVitals(); import './App.css'; import { useQuery, gql } from '@apollo/client'; const ALL_PERSONS = gql` query { allPeople { edges { node { id name birthYear gender homeworld { name } species { name } } } } } `; function App() { const { loading, error, data} = useQuery(ALL_PERSONS); if (loading){ return ( <div> Loading... </div> ); } else if (error){ return( <div> <h1>Something went wrong!</h1> <p>Name: {error.name}</p> <p>Message: {error.message}</p> <p>Data: {data}</p> </div> ); } else{ return ( <div className="App"> <h1>Star Wars API</h1> <div> {data} </div> </div> ); } } export default App;¡Cualquier ayuda es apreciada! Soy nuevo en el uso de Apollo Client y GraphQL