如何将中继变量设置为枚举值

How to set a Relay variable as an enum value?

本文关键字:设置 枚举 变量      更新时间:2023-09-26

示例片段:

fragments: {
  viewer: () => Relay.QL`
    fragment on Viewer {
      people(first: $limit orderBy: $orderBy) {
        count
        edges {
          node {
            id,
            ${PersonListItem.getFragment('person')},
          },
        },
      }
    }
  `,
},

orderBy 参数接受以下枚举值:firstNameASC/firstNameDESC/lastNameASC/lastNameDESC

执行this.setVariables({orderBy: 'firstName'})时,orderBy变量将作为字符串传递给 GraphQL 服务器。

如何将这些变量中的任何一个传递到 中继的 setVariables 中,而不会将它们作为字符串发送?

现在,您可以将枚举变量用作字符串。

查询(EventsConnectionOrder是一个枚举)

query($orderBy: [EventsConnectionOrder]){
  viewer {
    events(first:1 orderBy: $orderBy) {
      edges {
        node {
          id
        }
      }
    }
  }
}

变量

{
  "orderBy": "dateASC"
}