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

How to set a Relay variable as an enum value?

示例片段:

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 服务器。

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

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

例子

查询(EventsConnectionOrder 是一个枚举)

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

变量

{
  "orderBy": "dateASC"
}