[英]Accepting Int or String in graphQL schema
I have an input type in my apollo graphql schema, My schema looks like:我的 apollo graphql 模式中有一个输入类型,我的模式如下所示:
input Score {
total: String! // The input we recieve from the user might be a string or an int.
}
So, I want the total to be an string or int.所以,我希望总数是一个字符串或整数。 How can I implement that?
我该如何实施? Should I use custom scalar types or is there any better way?
我应该使用自定义标量类型还是有更好的方法?
Well your Schema can be as it are!好吧,您的架构可以保持原样!
typeDefs= gql`
input Score{
total: String!
}
type mutation{
totalBE: (input: Score)
}
`
Query:{
totalBe: ScoreBe(_,param);
}
but in the back end function resoolver但在后端功能解析器
resoolvers = {
ScoreBe(paramArgs):{
score = paramArgs.input.total;
//deal with it as String and Interger at the same time in your middleware or backEnd Technollogy. (is most easy here).
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.