Когда я использую динамический запрос, например следующее создает правильный запрос и возвращает правильный результат:
Код: Выделить всё
@Inject
@GraphQLClient("linear")
DynamicGraphQLClient dynamicClient;
@GET
@Path("/dynamicteams")
@Produces(MediaType.APPLICATION_JSON)
@Blocking
public JsonObject getTeams() throws Exception {
Document query = document(
operation(
field("teams",
field("nodes",
field("id"),
field("name")
)
)
)
);
Log.info("Query: " + query.build());
// ie Query: query { teams { nodes { id name } } }
Response response = dynamicClient.executeSync(query);
return response.getData();
}
Код: Выделить всё
{"teams":{"nodes":[{"id":"my-id-1","name":"Team 1"},{"id":"my-id-2","name":"Team 2"}]}}
Код: Выделить всё
query teams { teams { nodes { id name } } }
Код: Выделить всё
@Inject
LinearClientApi typesafeClient;
@GET
@Path("/safeteams")
@Produces(MediaType.APPLICATION_JSON)
@Blocking
public TeamsResponse getSafeTeams() {
TeamsResponse resp = typesafeClient.getTeams();
Log.info("Response: " + resp.toString());
return resp;
}
Код: Выделить всё
@GraphQLClientApi(configKey = "linear-typesafe")
public interface LinearClientApi {
TeamsResponse getTeams();
}
public class TeamsResponse {
private List nodes;
public List getNodes() {
return nodes;
}
public void setNodes(List nodes) {
this.nodes = nodes;
}
}
public class TeamNode {
private String id;
private String name;
// Getters and setters
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
Код: Выделить всё
@Query(value="XXX")
TeamsResponse getTeams();
Код: Выделить всё
query XXX { XXX {nodes {id name}} }
Спасибо,
Мюррей
Подробнее здесь: https://stackoverflow.com/questions/793 ... sted-query
Мобильная версия