Dee*_*ank 17 graphql graphql-js
我想创建一个可以返回 anArray of Integers或String.
我已经尝试在 form 中使用 union
union CustomVal = [Int] | String,但这会返回错误。
架构声明是:
union CustomValues = [Int] | String
type Data {
name: String
slug: String
selected: Boolean
values: CustomValues
}
Run Code Online (Sandbox Code Playgroud)
错误是:
node_modules/graphql/error/syntaxError.js:24
return new _GraphQLError.GraphQLError('Syntax Error: ' + description, undefined, source, [position]);
Syntax Error: Expected Name, found [
GraphQL request (81:23)
80:
81: union CustomValues = [Int] | String
Run Code Online (Sandbox Code Playgroud)
这可以在graphql中做到吗?如果没有,您能否建议一种替代方法来做到这一点。
我问这个,因为工会文件说 Note that members of a union type need to be concrete object types; you can't create a union type out of interfaces or other unions.
任何解决方案都会非常有帮助。
小智 21
按照这个https://github.com/facebook/graphql/issues/215,Graphql 目前不支持缩放联合类型,你可以这样做
union IntOrString = IntBox | StringBox
type IntBox {
value: Int
}
type StringBox {
value: String
}
Run Code Online (Sandbox Code Playgroud)
或者你可以有你的自定义类型,看这个graphql,联合标量类型?
| 归档时间: |
|
| 查看次数: |
22882 次 |
| 最近记录: |