【问题标题】:How to set a Relay variable as an enum value?如何将 Relay 变量设置为枚举值?
【发布时间】: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 而不将它们作为字符串发送?

【问题讨论】:

    标签: javascript reactjs graphql relay graphql-js


    【解决方案1】:

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

    示例

    查询(EventsConnectionOrder 是一个枚举)

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

    变量

    {
      "orderBy": "dateASC"
    }
    

    【讨论】:

      猜你喜欢
      • 2023-03-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-02
      • 2011-05-19
      • 2014-09-20
      • 2023-04-09
      • 1970-01-01
      相关资源
      最近更新 更多