简体   繁体   English

如何对 graphQL 模式中的一个字段使用不同的标量类型?

[英]How to use different scalar types for one field in graphQL schema?

I have an input type that says:我有一个输入类型,上面写着:

input testInput {
a: String 
b: String
c: Boolean
}

I have a situation where field c can be either String or Boolean .我有一种情况,字段c可以是StringBoolean How can i implement the field c that will accept both String and Boolean ?如何实现将接受StringBoolean c

Graphql does not support union of scalar types. Graphql 不支持标量类型的联合。 So you can modify it this way所以你可以这样修改

input testInput { a: String b: String c: hybridType }输入 testInput { a:字符串 b:字符串 c:hybridType }

type cBoolean { content: Boolean }类型 cBoolean { 内容:Boolean }

type cString { content: String }类型 cString { 内容:字符串 }

union hybridType = cBoolean | union hybridType = cBoolean | cString字符串

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM