Ability to add custom operation name for request by robbertnoordzij · Pull Request #682 · kobylynskyi/graphql-java-codegen · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public static String toHttpJsonBody(GraphQLRequests graphQLRequests) {
}
return jsonQuery(operationWrapper(
firstRequest.getOperationType(),
null, // combined request does not have operation name
graphQLRequests.getOperationName(),
queryBuilder.toString()));
}

Expand Down Expand Up @@ -77,9 +77,13 @@ public static String toQueryString(GraphQLRequest graphQLRequest) {
if (graphQLRequest == null || graphQLRequest.getRequest() == null) {
return null;
}

String operationName = graphQLRequest.getOperationName() == null ?
graphQLRequest.getRequest().getOperationName() : graphQLRequest.getOperationName();

return operationWrapper(
graphQLRequest.getRequest().getOperationType(),
graphQLRequest.getRequest().getOperationName(),
operationName,
buildQuery(graphQLRequest));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,15 @@
*/
public class GraphQLRequests {

private final String operationName;
private final List<GraphQLRequest> requests = new ArrayList<>();

public GraphQLRequests(GraphQLRequest... requests) {
this(null, requests);
}

public GraphQLRequests(String operationName, GraphQLRequest... requests) {
this.operationName = operationName;
this.requests.addAll(Arrays.asList(requests));
}

Expand All @@ -23,6 +29,10 @@ public List<GraphQLRequest> getRequests() {
return new ArrayList<>(requests);
}

public String getOperationName() {
return operationName;
}

/**
* Serializes multiple GraphQL requests to be used as HTTP JSON body
* according to https://graphql.org/learn/serving-over-http specifications
Expand Down