如何使用具有特殊字符的ApolloStack / GraphQL创建枚举变量?

时间:2016-07-25 19:14:36

标签: graphql apollo

我尝试使用ApolloStack创建GraphQL枚举类型。但似乎没有任何效果。供参考,请参阅示例代码。

enum Test {
    ABC
    Dog
    Dog/Cat
}

在上面的示例中,Dog / Cat将导致服务器无法正常工作。

2 个答案:

答案 0 :(得分:0)

我不确定使用' /'在声明枚举值时可以使用。

尝试切换' Dog / Cat'像动物'

这样的东西

答案 1 :(得分:0)

GraphQL中的enum中不能包含特殊字符。但是您可以使用解析器来处理它们 - 除非您在GraphQL中无法解析Type,否则您只能解析类型的field

例如,

type Foo {
  test: Test
}
enum Test {
  ABC
  Dog
  DogCat
}

并在Foo的解析器中,

{
  Foo: {
    test({ test }) {
      // handle special characters and return enum supported string
      if (test === "Cat/Dog") return "CatDog";
      return test;
    }
  }
}
相关问题