Javascript 如何将中继变量设置为枚举值?
示例片段:Javascript 如何将中继变量设置为枚举值?,javascript,reactjs,graphql,relay,graphql-js,Javascript,Reactjs,Graphql,Relay,Graphql Js,示例片段: fragments: { viewer: () => Relay.QL` fragment on Viewer { people(first: $limit orderBy: $orderBy) { count edges { node { id, ${PersonListItem.getFragment('person')}, },
fragments: {
viewer: () => Relay.QL`
fragment on Viewer {
people(first: $limit orderBy: $orderBy) {
count
edges {
node {
id,
${PersonListItem.getFragment('person')},
},
},
}
}
`,
},
orderBy
参数接受以下枚举值:firstNameDESC
/firstNameDESC
/lastNameDESC
/lastNameDESC
执行this.setVariables({orderBy:'firstName'})
时,orderBy
变量作为字符串传递给GraphQL服务器
如何将这些变量中的任何一个传递到中继的setVariables中,而不将它们作为字符串发送?您现在可以使用枚举变量作为字符串 例子 查询(
EventsConnectionOrder
是一个枚举)
变量
query($orderBy: [EventsConnectionOrder]){
viewer {
events(first:1 orderBy: $orderBy) {
edges {
node {
id
}
}
}
}
}
{
"orderBy": "dateASC"
}