Graphql-java 中的自定义标量 [英] Custom Scalar in Graphql-java
问题描述
我们计划在我们的应用程序中使用 Graphql 作为后端服务器.我们选择 Graphql-Java 来开发我们的 POC.我们遇到了创建自己的标量类型来处理 java.util.Map 对象类型的情况.
We are planning use Graphql as backend server in our application. We choose Graphql-Java to develop our POC. We came across a stituation to create our own scalartype to handle java.util.Map object type.
我们还没有找到任何关于创建自定义标量类型的文档.示例代码如下
we havent found any documentation regarding creating a custom scalar type. In example code as below
RuntimeWiring buildRuntimeWiring() {
return RuntimeWiring.newRuntimeWiring()
.scalar(CustomScalar)
如何为 CustomScalar 对象完成实现.需要帮助.
how to was the implementation done for CustomScalar object. need help.
推荐答案
要大致了解如何制作标量,只需查看 现有的并做类似的事情.
To get a general idea how to make a scalar, just take a look into the existing ones and do something similar.
graphql-java 还有一个单独的额外标量项目:graphql-java-扩展标量.在那里你可以找到 对象标量(又名 JSON 标量)),可用于动态结构,例如 Map
s.
graphql-java also has a separate project for extra scalars: graphql-java-extended-scalars. And there you can find the object scalar (a.k.a. JSON scalar), that can be used for dynamic structures, like Map
s.
通过以下方式注册:
RuntimeWiring.newRuntimeWiring().scalar(ExtendedScalars.Object)
这篇关于Graphql-java 中的自定义标量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!