如何指定采用多种类型的 graphql 类型?
How do I specify a graphql type that takes multiple types?
我想创建一个可以 return Array of Integers
或 String
的 graphql 类型。
我已经尝试过在表单中使用 union
union CustomVal = [Int] | String
,但这 return 是一个错误。
模式声明是:
union CustomValues = [Int] | String
type Data {
name: String
slug: String
selected: Boolean
values: CustomValues
}
错误是:
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
这可以在 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.
任何解决方案都会非常有帮助。
按照这个https://github.com/facebook/graphql/issues/215,Graphql目前不支持scaler union类型,你可以这样做
union IntOrString = IntBox | StringBox
type IntBox {
value: Int
}
type StringBox {
value: String
}
或者您可以使用自定义类型,请参阅此
我想创建一个可以 return Array of Integers
或 String
的 graphql 类型。
我已经尝试过在表单中使用 union
union CustomVal = [Int] | String
,但这 return 是一个错误。
模式声明是:
union CustomValues = [Int] | String
type Data {
name: String
slug: String
selected: Boolean
values: CustomValues
}
错误是:
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
这可以在 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.
任何解决方案都会非常有帮助。
按照这个https://github.com/facebook/graphql/issues/215,Graphql目前不支持scaler union类型,你可以这样做
union IntOrString = IntBox | StringBox
type IntBox {
value: Int
}
type StringBox {
value: String
}
或者您可以使用自定义类型,请参阅此