when I add this code relay compiler show errors:
import Relay from "react-relay/classic";
import {graphql, QueryRenderer} from 'react-relay/compat';
export default ({user}) => {
return <QueryRenderer
environment={Relay.Store}
query={graphql`query { viewer { user(id: $userId) { id, username } } }`}
variables={{userId: user.id}}
render={({error, props}) => {
return <div>....</div>;
}}
/>
};
error:
$ relay-compiler --src ./src --schema ./schema.graphql
HINT: pass --watch to keep watching for
TypeError: Cannot read property 'value' of undefined
at /project/path/node_modules/relay-compiler/bin/relay-compiler:4656:35
at Array.forEach (native)
at validateTemplate (/project/path/node_modules/relay-compiler/bin/relay-compiler:4655:20)
at TaggedTemplateExpression (/project/path/node_modules/relay-compiler/bin/relay-compiler:4581:12)
at visit (/project/path/node_modules/relay-compiler/bin/relay-compiler:4696:6)
at traverse (/project/path/node_modules/relay-compiler/bin/relay-compiler:4709:8)
at visit (/project/path/node_modules/relay-compiler/bin/relay-compiler:4699:4)
at traverse (/project/path/node_modules/relay-compiler/bin/relay-compiler:4709:8)
at visit (/project/path/node_modules/relay-compiler/bin/relay-compiler:4699:4)
at /project/path/node_modules/relay-compiler/bin/relay-compiler:4713:12
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
I found the problem. I should add name to query:
// index.js
graphql`
query indexQuery($userId: ID!) {
viewer {
user(id: $userId) {
id, username
}
}
}
`;
Reopening to track this: the parser should validate that queries (and fragments, mutations, etc) are named rather than assume that node.name.value is set.
@kassens this seems like something we can do to improve developer experience
I tried this on relay 1.3 and getting an error like:
Parse error: Error: FindGraphQLTags: In module
app, a definition of kindOperationDefinitionrequires a name. in "app.js"
Which isn't quite ideal but better than what you saw probably from an earlier version. Please reopen if you're still seeing this!
Most helpful comment
Reopening to track this: the parser should validate that queries (and fragments, mutations, etc) are named rather than assume that
node.name.valueis set.