简体   繁体   English

如何在继电器现代中设置初始变量?

[英]How to set initial variables in relay modern?

started relay at learnrelay.org, from the tutorial the code to set initial variables https://www.learnrelay.org/queries/variables/ is like this: 开始在learningrelay.org上进行中继,从教程中设置初始变量https://www.learnrelay.org/queries/variables/的代码如下:

export default Relay.createContainer(
  ListPage,
  {
    initialVariables: {
      sortOrder: 'id_DESC'
    },
    fragments: {
      viewer: () => Relay.QL`
        fragment on Viewer {
          allPokemons (first: 1000, orderBy: $sortOrder) {

we usually assign variables in relay classic like this, but this code throws an error in relay modern and I don't know why? 我们通常像这样在经典继电器中分配变量,但是这段代码在现代继电器中引发错误,我不知道为什么?

export default createPaginationContainer(TodoList,
  initialVariables: {
    first: 10,
  }, 
  fragments: {
  viewer: graphql`
    fragment TodoList_viewer on User {
      todos( # we need to expose todos on user so we can check if todo text already exist and sync in database 
        first: $first 
      ) @connection(key: "TodoList_todos") { #assign a key of connection that can be used shared updater

You can't use initialVariables in Relay Modern - see this link in the docs . 您无法在Relay Modern中使用initialVariables 请参阅文档中的此链接 Note that as of now, the documentation for migrating away from these functions is extremely brief. 请注意,到目前为止,用于迁移这些功能的文档非常简短。

If you're working on this right now, there's a pending update to the RefetchContainer documentation that shows how to properly fetch and refetch your view based on variables. 如果您现在正在处理此问题,则RefetchContainer文档中有一个待处理的更新 ,其中显示了如何根据变量正确地获取和重新获取视图。

If you're only using the variables for pagination, check out PaginationContainer . 如果仅将变量用于分页, 请签出PaginationContainer

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM