3

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

enum Test {
    ABC
    Dog
    Dog/Cat
}

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

4

2 回答 2

0

我不确定在声明枚举值时是否可以使用“/”。

尝试将“狗/猫”的名称切换为“动物”之类的名称

于 2016-09-03T20:19:39.863 回答
0

enum在 GraphQL中不能有特殊字符。但是您可以使用解析器来处理它们 - 除了在 GraphQL 中无法解析 aType的问题之外,您只能解析fieldType 的 a。

例如,

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;
    }
  }
}
于 2017-03-29T00:05:39.997 回答