我尝试执行Graphql客户端查询。遗憾的是,我无法找到任何关于如何使用Dynamic客户端进行简单突变的文档或示例。这是文档https://quarkus.io/guides/smallrye-graphql-client。
mutation mut {
add(p: {
amount: {0},
fromCurrencyId: {1},
reference: {2},
terminalKey: {3},
toCurrencyId: {4}
}) {
address
toCurrencyAmount
rate
createdAt
expireAt
}
}{0}.{4}是可变位置保持器。有人知道如何用DynamicGraphlQlClient执行这个查询吗?
谢谢!
发布于 2021-08-15 15:49:27
在按照Eclipse声明服务器端突变之后,如下所示:
@GraphQLApi
@ApplicationScoped
public class MyGraphQLApi {
@Mutation
public OutputType add(@Name("p") InputType p)) {
// perform your mutation and return result
}
}然后,您可以使用DynamicGraphQLClient声明性地使用DynamicGraphQLClient#executeSync方法执行突变,该方法具有在您的突变结构之后构造的io.smallrye.graphql.client.core.Document:
@Inject
private DynamicGraphQLClient client;
public void add() {
Document document = Document.document(
operation(
OperationType.MUTATION,
"mut",
field(
"add",
arg(
"p",
inputObject(
prop("amount", "amountValue"),
prop("fromCurrencyId", "fromCurrencyIdValue"),
prop("reference", "referenceValue"),
prop("terminalKey", "terminalKeyValue"),
prop("toCurrencyId", "toCurrencyIdValue")
)
)),
field("address"),
field("toCurrencyAmount"),
field("rate"),
field("createdAt"),
field("expireAt")
)
);
JsonObject data = client.executeSync(document).getData();
System.out.println(data.getString("address"));
}https://stackoverflow.com/questions/68772614
复制相似问题