我可以将 GraphQL 联合用于纯字符串吗?

Can I use a GraphQL union for plain strings?

在 Graphql 中,我可以创建一个 union 如下所示:

union SearchResult = Book | Movie

有没有办法对纯字符串执行此操作?像这样:

union AccountRole = "admin" | "consumer"

恐怕你不能那样做,因为这是规范定义的。

来自规范 here , the part that you want to change should follow the Names syntax 中提到的联合语法,其中第一个字符只允许是大写字母,后者是小写字母或 _

(即字符设置如下)

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z _