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

Posted

技术标签:

【中文标题】如何将 Relay 变量设置为枚举值?【英文标题】:How to set a Relay variable as an enum value? 【发布时间】:2016-06-27 01:23:24 【问题描述】:

示例片段:

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 而不将它们作为字符串发送?

【问题讨论】:

【参考方案1】:

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

示例

查询(EventsConnectionOrder 是一个枚举)

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

变量


  "orderBy": "dateASC"

【讨论】:

以上是关于如何将 Relay 变量设置为枚举值?的主要内容,如果未能解决你的问题,请参考以下文章

从外部存储中检索 Relay 查询片段的变量

如何在 Relay Container 之间传递变量

问题记录

枚举类型的变量如何使用?

将PB中的枚举型转化数值型

变量循环首判断循环首枚举循环首