我遇到了一个问题,我想使用graphql-dgs-extended-scalars,特别是JSON标量,但很难找到一个明确的教程来说明如何做到这一点。我确信他们就在那里,但以防有人发现自己和我处于同样的境地,希望我下面的简单解释能节省他们的时间。
发布于 2021-11-10 12:53:02
安装
在pom文件中(特定于maven)
<dependency>
<groupId>com.netflix.graphql.dgs</groupId>
<artifactId>graphql-dgs-extended-scalars</artifactId>
<version>${netflix.graphql.dgs.version}</version>
</dependency>在配置文件中(例如,application.yml)
dgs:
graphql:
extensions:
scalars:
objects:
enabled: true使用标量(本例中为JSON)
在模式中
...
type SomeType {
thing: JSON!
}
...
input SomeTypeInput {
thing: JSON!
}
...
scalar JSON在将用作datafetcher输入的类中
public class SomethingDTO
{
/**
* This does not have to be a Map, you could use another
* reasonable object like JSONObject, etc.
*/
public Map<String, Object> thing;
}然后,您可以在任意形状的查询中将json格式的对象作为参数传递。
这只适用于JSON标量,但大多数情况下都遵循这种模式(所有?)在库中找到的其他标量。
https://stackoverflow.com/questions/69913611
复制相似问题