diff --git a/multipart-spring-graphql/src/main/java/name/nkonev/multipart/spring/graphql/client/support/MultipartClientGraphQlRequest.java b/multipart-spring-graphql/src/main/java/name/nkonev/multipart/spring/graphql/client/support/MultipartClientGraphQlRequest.java index 4e61fe5..8240965 100644 --- a/multipart-spring-graphql/src/main/java/name/nkonev/multipart/spring/graphql/client/support/MultipartClientGraphQlRequest.java +++ b/multipart-spring-graphql/src/main/java/name/nkonev/multipart/spring/graphql/client/support/MultipartClientGraphQlRequest.java @@ -4,10 +4,13 @@ import org.springframework.graphql.client.ClientGraphQlRequest; import org.springframework.graphql.support.DefaultGraphQlRequest; import org.springframework.lang.Nullable; +import org.springframework.util.Assert; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; +import static java.util.Collections.emptyMap; + public class MultipartClientGraphQlRequest extends DefaultGraphQlRequest implements ClientGraphQlRequest { private final Map attributes = new ConcurrentHashMap<>(); @@ -34,4 +37,53 @@ public Map getAttributes() { return this.attributes; } + public static Builder builder() { + return new Builder(); + } + + public static class Builder { + private String document; + private String operationName; + private Map variables = emptyMap(); + private Map extensions = emptyMap(); + private Map attributes = emptyMap(); + private Map fileVariables = emptyMap(); + + public Builder withDocument(String document) { + this.document = document; + return this; + } + public Builder withOperationName(String operationName) { + this.operationName = operationName; + return this; + } + public Builder withVariables(Map variables) { + this.variables = variables; + return this; + } + public Builder withExtensions(Map extensions) { + this.extensions = extensions; + return this; + } + public Builder withAttributes(Map attributes) { + this.attributes = attributes; + return this; + } + public Builder withFileVariables(Map fileVariables) { + this.fileVariables = fileVariables; + return this; + } + + public MultipartClientGraphQlRequest build() { + Assert.notNull(this.document, "document must not be null"); + return new MultipartClientGraphQlRequest( + this.document, + this.operationName, + this.variables, + this.extensions, + this.attributes, + this.fileVariables + ); + } + } }