Skip to content
This repository has been archived by the owner on Aug 2, 2023. It is now read-only.

Commit

Permalink
feat(RequestEntity): expose the ability to set the GraphQL request me…
Browse files Browse the repository at this point in the history
…thod without making a request (#58)
  • Loading branch information
chemdrew authored Nov 2, 2018
1 parent 1e82647 commit 2bfce73
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,12 @@ public static RequestBuilder Builder() {
private final Map<String, Object> variables;
private final Property property = new Property();
private final List<Class> scalars;
private GraphQLTemplate.GraphQLMethod requestMethod = GraphQLTemplate.GraphQLMethod.QUERY;
private GraphQLTemplate.GraphQLMethod requestMethod;
private String request;

GraphQLRequestEntity(RequestBuilder builder) {
this.url = builder.url;
this.requestMethod = builder.requestMethod;
this.scalars = Collections.unmodifiableList(builder.scalars);
this.headers = Collections.unmodifiableMap(builder.headers);
this.variables = Collections.unmodifiableMap(variableListToMap(builder.variables));
Expand Down Expand Up @@ -87,7 +88,7 @@ public List<Class> getScalars() {
return scalars;
}

void setRequestMethod(GraphQLTemplate.GraphQLMethod requestMethod) {
public void setRequestMethod(GraphQLTemplate.GraphQLMethod requestMethod) {
this.requestMethod = requestMethod;
property.setMethod(requestMethod);
}
Expand Down Expand Up @@ -333,6 +334,7 @@ public static class RequestBuilder {
List<Arguments> arguments = null;
List<Variable> variables = new ArrayList<Variable>();
List<Class> scalars = new ArrayList<Class>();
GraphQLTemplate.GraphQLMethod requestMethod = GraphQLTemplate.GraphQLMethod.QUERY;

RequestBuilder() { }

Expand Down Expand Up @@ -386,6 +388,11 @@ public RequestBuilder headers(Map<String, String> headers) {
return this;
}

public RequestBuilder requestMethod(GraphQLTemplate.GraphQLMethod requestMethod) {
this.requestMethod = requestMethod;
return this;
}

public GraphQLRequestEntity build() throws IllegalStateException {
if (url == null) throw new IllegalStateException("url must be set");
if (this.clazz == null && this.request == null) throw new IllegalStateException("request must be set");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,16 @@ public void simpleRequestWithUrl() throws MalformedURLException {
assertEquals("GraphQLRequestEntity{request='query ($andAnothaVariable:status,$anothaVariable:Int,$andAListVariable:[String],$variableName:String!){ test (id:null) { testShort : testShort testCharacter testList { anotherTestString (variableName:$variableName) andAnothaOne (anothaVariable:$anothaVariable,andAnothaVariable:$andAnothaVariable,andAListVariable:$andAListVariable) } testInteger testBoolean nestedTest { anotherTestString (variableName:$variableName) andAnothaOne (anothaVariable:$anothaVariable,andAnothaVariable:$andAnothaVariable,andAListVariable:$andAListVariable) } testByte : testByte testString : testString (anotherOne:null,default:\"default\",defaultList:null) testArrayList testFloat testDouble testLong } } ', url='"+EXAMPLE_URL+"'}", requestEntity.toString());
}

@Test
public void simpleRequestWithMethod() throws MalformedURLException {
GraphQLRequestEntity requestEntity = GraphQLRequestEntity.Builder()
.url(EXAMPLE_URL)
.request(TestModel.class)
.requestMethod(GraphQLTemplate.GraphQLMethod.MUTATE)
.build();
assertEquals("GraphQLRequestEntity{request='mutation ($andAnothaVariable:status,$anothaVariable:Int,$andAListVariable:[String],$variableName:String!){ test (id:null) { testShort : testShort testCharacter testList { anotherTestString (variableName:$variableName) andAnothaOne (anothaVariable:$anothaVariable,andAnothaVariable:$andAnothaVariable,andAListVariable:$andAListVariable) } testInteger testBoolean nestedTest { anotherTestString (variableName:$variableName) andAnothaOne (anothaVariable:$anothaVariable,andAnothaVariable:$andAnothaVariable,andAListVariable:$andAListVariable) } testByte : testByte testString : testString (anotherOne:null,default:\"default\",defaultList:null) testArrayList testFloat testDouble testLong } } ', url='"+EXAMPLE_URL+"'}", requestEntity.toString());
}

@Test
public void simpleRequestWithVariables() throws MalformedURLException {
GraphQLRequestEntity requestEntity = GraphQLRequestEntity.Builder()
Expand Down

0 comments on commit 2bfce73

Please sign in to comment.