GraphQL Blackbox/“任何"类型? [英] GraphQL Blackbox / "Any" type?

查看:57
本文介绍了GraphQL Blackbox/“任何"类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以将GraphQL中的字段指定为黑盒,类似于Flow如何具有"any"类型?我的架构中有一个字段,该字段应该能够接受任意值,可以是String,Boolean,Object,Array等.

Is it possible to specify that a field in GraphQL should be a blackbox, similar to how Flow has an "any" type? I have a field in my schema that should be able to accept any arbitrary value, which could be a String, Boolean, Object, Array, etc.

推荐答案

我提出了一个中间立场的解决方案.我没有尝试将这种复杂性推到GraphQL上,而是选择仅使用String类型并JSON.stringify设置数据,然后再将其设置在字段上.因此,一切都变得字符串化了,稍后在我的应用程序中,当我需要使用该字段时,我JSON.parse结果取回所需的对象/数组/布尔值/等.

I've come up with a middle-ground solution. Rather than trying to push this complexity onto GraphQL, I'm opting to just use the String type and JSON.stringifying my data before setting it on the field. So everything gets stringified, and later in my application when I need to consume this field, I JSON.parse the result to get back the desired object/array/boolean/ etc.

这篇关于GraphQL Blackbox/“任何"类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆