I am trying out relay-treasure hunt tutorial but getting the following error when I run npm start. I did update my schema by running npm run update-schema.
Uncaught Error: GraphQL validation error ``Cannot query field "game" on type "Query".`` in file `/home/tharaka/My Projects/relay-treasurehunt/js/routes/AppHomeRoute.js`. Try updating your GraphQL schema if an argument/field/type was recently added.
Here’s what’s inside my AppHomeRoute.js
import Relay from 'react-relay';
export default class extends Relay.Route {
static path = '/';
static queries = {
game: () => Relay.QL`query { game }`,
};
static routeName = 'AppHomeRoute';
}
2
2 Answers
In your data/schema.js
file…
var queryType = new GraphQLObjectType({
name: 'Query',
fields: () => ({
node: nodeField,
// Add your own root fields here
viewer: {
type: gameType,
resolve: () => getGame(),
},
}),
});
Change the viewer
property to game
. Like this…
var queryType = new GraphQLObjectType({
name: 'Query',
fields: () => ({
node: nodeField,
// Add your own root fields here
game: {
type: gameType,
resolve: () => getGame(),
},
}),
});
The name of that property needs to match the field you’re querying on in your fragment on your Home route. I suppose as an alternative you could change your route to request viewer
instead of game
. Do whichever feels better.
What does your server side code look like? The
Query
GraphQLObjectType needs to have a property calledfields
with a func that returns an object with agame
property.Jun 26, 2016 at 7:52
Here's the complete code
Jun 26, 2016 at 8:52