Estoy siguiendo el guid paso a paso de Relay Doc, pero encuentro un error de nodo AST cuando intento yarn start después del paso 5, ¿alguien tenía idea de cuál es el problema?
Writing js ERROR: Invalid AST Node: { kind: "Root", operation: "query", loc: { kind: "Source", start: 3, end: 105, source: [Source] }, metadata: null, name: "AppRepositoryNameQuery", argumentDefinitions: [], directives: [], selections: [[Object]], type: Query }. error Command failed with exit code 100. info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.Código:
// your-app-name/src/App.js import React from 'react'; import './App.css'; import fetchGraphQL from './fetchGraphQL'; const { useState, useEffect } = React; function App() { // We'll load the name of a repository, initially setting it to null const [name, setName] = useState(null); // When the component mounts we'll fetch a repository name useEffect(() => { let isMounted = true; fetchGraphQL(` query RepositoryNameQuery { # feel free to change owner/name here repository(owner: "facebook" name: "relay") { name } } `).then(response => { // Avoid updating state if the component unmounted before the fetch completes if (!isMounted) { return; } const data = response.data; setName(data.repository.name); }).catch(error => { console.error(error); }); return () => { isMounted = false; }; }, [fetchGraphQL]); // Render "Loading" until the query completes return ( <div className="App"> <header className="App-header"> <p> {name != null ? `Repository: ${name}` : "Loading"} </p> </header> </div> ); } export default App;Entorno: WSL2 Ubuntu
Encuentre el código de la guía paso a paso en Relay doc
Editar: descubrí que este error solo ocurre cuando intento usar el compilador de relés instalado en la carpeta node_modules del proyecto y el uso de la versión instalada globalmente resolvió el problema
Al seguir la guía paso a paso, al ejecutar uno de los siguientes comandos del paso 4, se instala la versión graphql de 16.0.1 :
npm install --save-dev relay-compiler graphql babel-plugin-relay -- or -- yarn add --dev relay-compiler graphql babel-plugin-relay Sin embargo, relay-compiler tiene una dependencia de pares de la versión 15 de graphql ( ^15.0.0 ). Entonces, para corregir el error, reemplace el comando con:
npm install --save-dev relay-compiler graphql@^15.0.0 babel-plugin-relay -- or -- yarn add --dev relay-compiler graphql@^15.0.0 babel-plugin-relayProblema de GitHub relacionado: https://github.com/facebook/relay/issues/3622