Skip to content

Add WebGraphQlRequest constructor #681

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
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 @@ -96,6 +96,36 @@ public WebGraphQlRequest(
this.attributes = Collections.unmodifiableMap(attributes);
}

/**
* Create an instance by provided fields.
* @param uri the URL for the HTTP request or WebSocket handshake
* @param headers the HTTP request headers
* @param cookies the HTTP request cookies
* @param attributes request attributes
* @param query the GraphQL's document
* @param operationName the GraphQL's operation name
* @param variables the GraphQL's variables
* @param extensions the GraphQL's extensions
* @param id an identifier for the GraphQL request
* @param locale the locale from the HTTP request, if any
* @since 1.2.0
*/
public WebGraphQlRequest(
URI uri, HttpHeaders headers, @Nullable MultiValueMap<String, HttpCookie> cookies,
Map<String, Object> attributes, String query, String operationName, Map<String, Object> variables,
Map<String, Object> extensions, String id, @Nullable Locale locale) {

super(query, operationName, variables, extensions, id, locale);

Assert.notNull(uri, "URI is required'");
Assert.notNull(headers, "HttpHeaders is required'");

this.uri = UriComponentsBuilder.fromUri(uri).build(true);
this.headers = headers;
this.cookies = (cookies != null ? CollectionUtils.unmodifiableMultiValueMap(cookies) : EMPTY_COOKIES);
this.attributes = Collections.unmodifiableMap(attributes);
}

@SuppressWarnings("unchecked")
private static <T> T getKey(String key, Map<String, Object> body) {
if (key.equals("query") && !StringUtils.hasText((String) body.get(key))) {
Expand Down