简体   繁体   English

为什么我在过滤器中使用枚举时在 graphql 中出现语法错误?

[英]Why I get syntax error in graphql when I use enum in filter?

For every user has gender property.对于每个用户都有性别属性。 The gender property is enum in graphql.在 graphql 中,性别属性是枚举。

I want to query all users that have female and male values only.我想查询所有只有femalemale值的用户。

Why when I write my query on graphql playground I got an error message?为什么当我在 graphql playground 上写查询时收到错误消息?

I also try to write: userMany(filter: { gender: [female, male] }) { but I got syntax error.我也尝试写: userMany(filter: { gender: [female, male] }) {但我遇到了语法错误。

Is there another way to write this query to get the results?有没有另一种方法来编写这个查询来获得结果?

The query:查询:

{
  userMany(filter: { gender: female AND male }) {
    name
    age
    gender
    someMixed
    salaryDecimal
    virtualField
  }
}

The error:错误:

{
  "errors": [
    {
      "message": "Syntax Error: Expected :, found Name \"male\"",
      "stack": [
        "Syntax Error: Expected :, found Name \"male\"",
        "",
        "GraphQL request:2:41",
        "1 | {",
        "2 |   userMany(filter: { gender: female AND male }) {",
        "  |                                         ^",
        "3 |     name",
        "    at syntaxError (/app/node_modules/graphql/error/syntaxError.js:15:10)",
        "    at expectToken (/app/node_modules/graphql/language/parser.js:1428:38)",
        "    at parseObjectField (/app/node_modules/graphql/language/parser.js:588:3)",
        "    at item (/app/node_modules/graphql/language/parser.js:571:12)",
        "    at any (/app/node_modules/graphql/language/parser.js:1500:16)",
        "    at parseObject (/app/node_modules/graphql/language/parser.js:576:13)",
        "    at parseValueLiteral (/app/node_modules/graphql/language/parser.js:470:14)",
        "    at parseArgument (/app/node_modules/graphql/language/parser.js:348:12)",
        "    at many (/app/node_modules/graphql/language/parser.js:1515:16)",
        "    at parseArguments (/app/node_modules/graphql/language/parser.js:334:54)",
        "    at parseField (/app/node_modules/graphql/language/parser.js:321:16)",
        "    at parseSelection (/app/node_modules/graphql/language/parser.js:295:76)",
        "    at many (/app/node_modules/graphql/language/parser.js:1515:16)",
        "    at parseSelectionSet (/app/node_modules/graphql/language/parser.js:282:17)",
        "    at parseOperationDefinition (/app/node_modules/graphql/language/parser.js:192:21)",
        "    at parseExecutableDefinition (/app/node_modules/graphql/language/parser.js:169:12)"
      ]
    }
  ]
}

Try this:尝试这个:

{
  userMany(filter: {OR: [{gender: female}, {gender: male}]}) {
    name
    age
    gender
    someMixed
    salaryDecimal
    virtualField
  }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用字段作为来自一个 graphql 查询的过滤器,以获取单独查询中的流体图像? - How can I use a field as a filter from one graphql query to get a fluid image thats in a separate query? 枚举列上的 GraphQL 过滤器 - GraphQL Filter on Enum Column 离开页面时,我得到:未处理的 GraphQL 订阅错误错误:GraphQL 错误:未提供所需类型 xxx 的变量 xx - When leaving the page I get: Unhandled GraphQL subscription error Error: GraphQL error: Variable xx of required type xxx was not provided 为什么我不能在 graphql 中过滤深度嵌套查询? - Why can't i filter a Deep nested query in graphql? 为什么在React.js + GraphQL中出现此错误:模块构建失败:SyntaxError:意外令牌(10:6) - Why do I get this error in React.js + GraphQL: Module build failed: SyntaxError: Unexpected token (10:6) 为什么我的 graphQL 突变创建用户出现错误 400 - Why do i get error 400 on my graphQL mutation create user 如何对 django model 和 graphql 突变 ZDBC11CAA5BDA99F77E6FB4DABDZ882E 使用单个枚举? - How can I use a single enum for django model and graphql mutation arguments? 当 HotChocolate GraphQL 服务器中引发异常时,如何获取更多错误详细信息或日志记录? - How can I get more error details or logging, when an exception is thrown in a HotChocolate GraphQL server? 访问子字段时如何让 graphql-ruby 使用连接? - How can I get graphql-ruby to use joins when accessing subfields? 什么时候我应该使用Relay GraphQL连接和简单列表? - When should I use a Relay GraphQL connection and when a plain list?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM