如何为类型安全客户端编写 quarkus-smallrye-graphql-client Mutation 代码?

问题描述 投票:0回答:1

我正在尝试 Quarkus 应用程序和 Linear.app 之间的集成。

我可以使用类型安全的客户端进行阅读,但我在进行突变以创建新的 isuue 时遇到问题。

我需要生成的查询格式显然是:

mutation IssueCreate {
  issueCreate(
    input: {
      title: "Issue from Quarkus Test at 1737606760071"
      description: "Something went wrong"
      teamId: "my-linear-team-id"
    }
  ) {
    success
    issue {
      id
      title
    }
  }
}

其中

my-linear-team-id
实际上是一个真正的 teamId

记录器说: 完整的 graphql 请求:

{
  "query": "mutation issueCreate($input: CreateIssueInputInput!) { issueCreate(input: $input) {success issue {id title}} }",
  "variables": {
    "input": {
      "title": "Issue from Quarkus Test at 1737606760071",
      "description": "Something went wrong",
      "teamId": "my-linear-team-id"
    }
  },
  "operationName": "issueCreate"
}

响应图:

{
  "errors": [
    {
      "message": "Unknown type \"CreateIssueInputInput\".",
      "locations": [
        {
          "line": 1,
          "column": 30
        }
      ],
      "extensions": {
        "code": "GRAPHQL_VALIDATION_FAILED",
        "type": "graphql error",
        "userError": true,
        "meta": {}
      }
    }
  ]
}

我不知道如何编写我的请求以生成正确的突变。

我的java看起来像:

public class CreateIssueInput {
    private String title;
    private String description;
    private String teamId;

    // Getters and setters ...
}

public class CreateIssueResponse {
  private boolean success;
  private Issue issue;

  // Getters and setters ...

  public static class Issue {
      private String id;
      private String title;

      // Getters and setters ...
  }
}

import io.smallrye.graphql.client.typesafe.api.GraphQLClientApi;

@GraphQLClientApi(configKey = "linear-typesafe")
public interface LinearClientApi {
    @Mutation
    CreateIssueResponse issueCreate(@NonNull CreateIssueInput input);
}

// Send to Linear:
CreateIssueInput linearIssue = new CreateIssueInput();
linearIssue.setTeamId("my-linear-team-id"); // For the SO example
linearIssue.setTitle("Issue from Quarkus Test at " + System.currentTimeMillis());
linearIssue.setDescription("Something went wrong");

linearClientApi.issueCreate(linearIssue);

任何人都可以看到我这样做是错误的吗?我找不到可以说明问题的类型安全突变示例。看起来大多数示例都使用动态客户端。

谢谢, 穆雷

graphql quarkus smallrye
1个回答
0
投票

生成输入类型时,SmallRye GraphQL 在类名后面附加

Input
,因此
CreateIssueInput
变为
CreateIssueInputInput
。您要么必须将类命名为
CreateIssue
,要么用
@org.eclipse.microprofile.graphql.Input("CreateIssueInput")
对其进行注释以显式指定生成的输入类型的名称

© www.soinside.com 2019 - 2024. All rights reserved.