【问题标题】:graphene django relay: Relay transform error石墨烯 django 继电器:继电器变换错误
【发布时间】:2017-02-26 23:12:34
【问题描述】:

作为 GraphQL 的新手,我有一个带有两个模型的服务器的石墨烯 django 实现,非常接近 graphene docs' example

在 graphiql 中,我可以做到这一点,然后返回结果。

跟随另一个relay tutorial,我打算在屏幕上呈现这个查询的结果。

我的尝试如下所示:

class Note extends Component {
  render() {
    return(
      <div> {this.props.store.title} </div>
    )
  }
}

Note = Relay.createContainer(Note, {
  fragments: {
    store: () => Relay.QL`
      fragment on Query {
        note(id: "Tm90ZU5vZGU6MQ==") {
          id
          title
        }
      }
    `
  }
});

class NoteRoute extends Relay.Route {
  static routeName = 'NoteRoute';
  static queries = {
    store: Component => {

      return Relay.QL`
      query {
        ${Component.getFragment('store')}
      }
    `},
  };
}

我的浏览器控制台显示以下错误:

Uncaught Error: Relay transform error ``There are 0 fields supplied to the query named `Index`, but queries must have exactly one field.`` in file `/Users/.../src/index.js`. Try updating your GraphQL schema if an argument/field/type was recently added.

我一直在尝试自己解决这个问题,但成功有限。

有人能指出正确的方向吗?

【问题讨论】:

  • 我认为 Relay 不允许使用片段 on Query。您的NoteRoute 中的查询需要一个且恰好一个字段。

标签: python django reactjs graphql relay


【解决方案1】:

感谢@stubailo 为我指明了正确的方向。我做了一些调整,现在有一个像这样运行的最小示例:

NoteList = Relay.createContainer(NoteList, {
  fragments: {
    store: () => Relay.QL`
      fragment N on NoteNodeConnection {
        edges {
          node{
            id
            title
            note
          }
        }
      }
    `
  }
});

class NoteRoute extends Relay.Route {
  static routeName = 'NoteRoute';
  static queries = {
    store: Component => {

      return Relay.QL`
      query {
        notes {
          ${Component.getFragment('store')}
        }
      }
    `},
  };
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-05-10
    • 2018-09-19
    • 2017-05-13
    • 1970-01-01
    • 2020-09-01
    • 2017-03-18
    • 2023-03-31
    • 2020-01-08
    相关资源
    最近更新 更多