[英]GraphQL validation error
I am trying out relay-treasure hunt tutorial but getting the following error when I run npm start . 我正在尝试中继寻宝教程,但是在运行npm start时遇到以下错误。 I did update my schema by running npm run update-schema . 我确实通过运行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 这是我的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';
}
It seems you have to query everything through either node
or viewer
, because those are the only fields on the root query type. 看来您必须通过node
或viewer
所有内容,因为这些是根查询类型上的唯一字段。 So maybe try this: 所以也许试试这个:
query {
viewer {
game
}
}
In your data/schema.js
file... 在您的data/schema.js
文件中...
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
. 将viewer
属性更改为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
. 我想作为一种替代方案,您可以更改路线以请求viewer
而不是game
。 Do whichever feels better. 做任何感觉更好的事情。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.