2

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

谢谢!

4

1 回答 1

1

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"));
}
于 2021-08-15T15:49:27.200 回答