Quarkus SmallRye Graphql-客户端变异查询

Quarkus SmallRye Graphql-Client Mutation Query

我尝试执行 Graphql 客户端查询。遗憾的是,我找不到任何类型的文档或示例来说明如何使用 Dynamic Graph QL Client 进行简单的 Mutation。这是文档 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 执行此查询吗?

谢谢!

Eclipse MicroProfile API 之后声明您的服务器端变更如下:

@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(
            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"));
}