我对 Relay 比较陌生,所以这可能是我犯的一个简单错误,但我已经寻找了一段时间,但没有找到有关我遇到的问题的任何信息。
这是我从应用程序中收到的错误:
Uncaught Error: Invariant Violation: GraphQLFragmentPointer: Value for the argument to
story
on queryRoute
should be a string, but it was set to10
. Check that the value is a string.
问题是我实际上希望它是 10
并且不希望它是字符串。我是否配置错误?
这是我的 GraphQL 架构:
var queryType = new GraphQLObjectType({
name: 'Query',
fields: () => ({
node: nodeField,
story: {
type: storyType,
args: {
storyID: {
description: 'Story ID',
type: GraphQLInt
}
},
resolve: (root, {storyID}) => {
if (storyID) {
return Story.get(storyID)
} else {
return Story.get(10)
}
}
},
}),
});
这是我定义的中继路由:
export default class extends Relay.Route {
static queries = {
story: () => Relay.QL`
query {
story(storyID: $storyID)
}
`,
};
static paramDefinitions = {
storyID: {
required: false
},
};
static routeName = 'StoryRoute';
};
这就是我实例化它的方式:
let route = new Route({storyID: 10})
最佳答案
好吧,看来我终于明白了。
根字段似乎受到严格限制,目前只能没有参数、单个字符串参数或多个字符串参数,直接与获取的对象的 ID 连接。
在此处查找更多信息:https://github.com/facebook/relay/issues/112 在这里:https://github.com/facebook/relay/issues/94
关于reactjs - RelayJS 整数查询参数的不变违规,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32668568/