Skip to content

Commit bf6bca8

Browse files
committed
some javadoc
1 parent eda1e89 commit bf6bca8

11 files changed

+77
-4
lines changed

src/main/java/graphql/servlet/context/ContextSetting.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,28 @@
2121
import java.util.function.Supplier;
2222
import java.util.stream.Collectors;
2323

24+
/**
25+
* An enum representing possible context settings. These are modeled after Apollo's link settings.
26+
*/
2427
public enum ContextSetting {
2528

29+
/**
30+
* A context object, and therefor dataloader registry and subject, should be shared between all GraphQL executions in a http request.
31+
*/
2632
PER_REQUEST,
33+
/**
34+
* Each GraphQL execution should always have its own context.
35+
*/
2736
PER_QUERY;
2837

38+
/**
39+
* Creates a set of inputs with the correct context based on the setting.
40+
* @param requests the GraphQL requests to execute.
41+
* @param schema the GraphQL schema to execute the requests against.
42+
* @param contextSupplier method that returns the context to use for each execution or for the request as a whole.
43+
* @param root the root object to use for each execution.
44+
* @return a configured batch input.
45+
*/
2946
public GraphQLBatchedInvocationInput getBatch(List<GraphQLRequest> requests, GraphQLSchema schema, Supplier<GraphQLContext> contextSupplier, Object root) {
3047
switch (this) {
3148
case PER_QUERY:
@@ -37,6 +54,13 @@ public GraphQLBatchedInvocationInput getBatch(List<GraphQLRequest> requests, Gra
3754
}
3855
}
3956

57+
/**
58+
* Augments the provided instrumentation supplier to also supply the correct dispatching instrumentation.
59+
* @param instrumentation the instrumentation supplier to augment
60+
* @param executionInputs the inputs that will be dispatched by the instrumentation
61+
* @param options the DataLoader dispatching instrumentation options that will be used.
62+
* @return augmented instrumentation supplier.
63+
*/
4064
public Supplier<Instrumentation> configureInstrumentationForContext(Supplier<Instrumentation> instrumentation, List<ExecutionInput> executionInputs,
4165
DataLoaderDispatcherInstrumentationOptions options) {
4266
ConfigurableDispatchInstrumentation dispatchInstrumentation;

src/main/java/graphql/servlet/context/DefaultGraphQLContextBuilder.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
import javax.websocket.Session;
66
import javax.websocket.server.HandshakeRequest;
77

8+
/**
9+
* Returns an empty context.
10+
*/
811
public class DefaultGraphQLContextBuilder implements GraphQLContextBuilder {
912

1013
@Override

src/main/java/graphql/servlet/context/DefaultGraphQLServletContext.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
import javax.security.auth.Subject;
66
import java.util.Optional;
77

8+
/**
9+
* An object for the DefaultGraphQLContextBuilder to return. Can be extended to include more context.
10+
*/
811
public class DefaultGraphQLServletContext implements GraphQLContext{
912

1013
private final Subject subject;

src/main/java/graphql/servlet/context/GraphQLContext.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,18 @@
55
import javax.security.auth.Subject;
66
import java.util.Optional;
77

8+
/**
9+
* Represents the context required by the servlet to execute a GraphQL request.
10+
*/
811
public interface GraphQLContext {
912

13+
/**
14+
* @return the subject to execute the query as.
15+
*/
1016
Optional<Subject> getSubject();
1117

18+
/**
19+
* @return the Dataloader registry to use for the execution.
20+
*/
1221
Optional<DataLoaderRegistry> getDataLoaderRegistry();
1322
}

src/main/java/graphql/servlet/input/BatchInputPreProcessResult.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package graphql.servlet.input;
22

3+
/**
4+
* Wraps the result of pre processing a batch. Allows customization of the response code and message if the batch isn't to be executed.
5+
*/
36
public class BatchInputPreProcessResult {
47

58
private final GraphQLBatchedInvocationInput batchedInvocationInput;
@@ -24,18 +27,30 @@ public BatchInputPreProcessResult(int statusCode, String messsage) {
2427
this.messsage = messsage;
2528
}
2629

30+
/**
31+
* @return If the servlet should try executing this batched input
32+
*/
2733
public boolean isExecutable() {
2834
return executable;
2935
}
3036

37+
/**
38+
* @return the batched input the servlet will try to execute.
39+
*/
3140
public GraphQLBatchedInvocationInput getBatchedInvocationInput() {
3241
return batchedInvocationInput;
3342
}
3443

44+
/**
45+
* @return status message the servlet will use if isExecutable is false.
46+
*/
3547
public String getStatusMessage() {
3648
return messsage;
3749
}
3850

51+
/**
52+
* @returnstatus code the servlet will use if if isExecutable is false.
53+
*/
3954
public int getStatusCode() {
4055
return statusCode;
4156
}

src/main/java/graphql/servlet/input/BatchInputPreProcessor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
public interface BatchInputPreProcessor {
77

88
/**
9-
* An injectable object that allows clients to manipulate a batch before executing, or abort altogether. If the returned result is not to be exeuted
9+
* An injectable object that allows clients to manipulate a batch before executing, or abort altogether.
1010
* @param batchedInvocationInput the input to process
1111
* @param request the servlet request
1212
* @param response the servlet response

src/main/java/graphql/servlet/input/GraphQLBatchedInvocationInput.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@
22

33
import java.util.List;
44

5+
/**
6+
* Interface representing a batched input.
7+
*/
58
public interface GraphQLBatchedInvocationInput {
69

10+
/**
11+
* @return each individual input in the batch, configured with a context.
12+
*/
713
List<GraphQLSingleInvocationInput> getExecutionInputs();
814
}

src/main/java/graphql/servlet/input/GraphQLSingleInvocationInput.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import java.util.Optional;
1212

1313
/**
14-
* @author Andrew Potter
14+
* Represents a single GraphQL execution.
1515
*/
1616
public class GraphQLSingleInvocationInput {
1717

@@ -27,15 +27,21 @@ public GraphQLSingleInvocationInput(GraphQLRequest request, GraphQLSchema schema
2727
subject = context.getSubject();
2828
}
2929

30+
/**
31+
* @return the schema to use to execute this query.
32+
*/
3033
public GraphQLSchema getSchema() {
3134
return schema;
3235
}
3336

37+
/**
38+
* @return a subject to execute the query as.
39+
*/
3440
public Optional<Subject> getSubject() {
3541
return subject;
3642
}
3743

38-
protected ExecutionInput createExecutionInput(GraphQLRequest graphQLRequest, GraphQLContext context, Object root) {
44+
private ExecutionInput createExecutionInput(GraphQLRequest graphQLRequest, GraphQLContext context, Object root) {
3945
return ExecutionInput.newExecutionInput()
4046
.query(graphQLRequest.getQuery())
4147
.operationName(graphQLRequest.getOperationName())

src/main/java/graphql/servlet/input/NoOpBatchInputPreProcessor.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
import javax.servlet.http.HttpServletRequest;
44
import javax.servlet.http.HttpServletResponse;
55

6+
/**
7+
* A default BatchInputPreProcessor that returns the input.
8+
*/
69
public class NoOpBatchInputPreProcessor implements BatchInputPreProcessor {
710

811
@Override

src/main/java/graphql/servlet/input/PerQueryBatchedInvocationInput.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import java.util.stream.Collectors;
1010

1111
/**
12-
* @author Andrew Potter
12+
* A Collection of GraphQLSingleInvocationInput that each have a unique context object.
1313
*/
1414
public class PerQueryBatchedInvocationInput implements GraphQLBatchedInvocationInput {
1515
private final List<GraphQLSingleInvocationInput> inputs;
@@ -19,6 +19,7 @@ public PerQueryBatchedInvocationInput(List<GraphQLRequest> requests, GraphQLSche
1919
.map(request -> new GraphQLSingleInvocationInput(request, schema, contextSupplier.get(), root)).collect(Collectors.toList());
2020
}
2121

22+
@Override
2223
public List<GraphQLSingleInvocationInput> getExecutionInputs() {
2324
return inputs;
2425
}

0 commit comments

Comments
 (0)