reactjs - RelayJS 整数查询参数的不变违规

标签 reactjs graphql relayjs graphql-js

我对 Relay 比较陌生,所以这可能是我犯的一个简单错误,但我已经寻找了一段时间,但没有找到有关我遇到的问题的任何信息。

这是我从应用程序中收到的错误:

Uncaught Error: Invariant Violation: GraphQLFragmentPointer: Value for the argument to story on query Route should be a string, but it was set to 10. 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/

相关文章:

javascript - React 不渲染新组件,新的 webpack 设置

javascript - 打开标记reactjs onclick

reactjs - 从 DynamoDB 更改 react 应用程序更新数据

react-native - 将 Relay 与 React-Native 结合使用时的条件片段或嵌入的根容器

javascript - 如何检查连接在中继中是否有新项目?

javascript - ionic 4 : ion-chip activatable/clickable by default; how to turn off?

javascript - 失败的 Jest 单元测试

javascript - 使用 getInitialProps 保护路由 - Next.js

web-services - 不同类型的网络服务

relayjs - 如何避免在中继突变中往返大量数据?