-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/master'
- Loading branch information
Showing
18 changed files
with
284 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package graphql.servlet; | ||
|
||
import graphql.ExecutionInput; | ||
import graphql.ExecutionResult; | ||
|
||
import java.util.function.BiFunction; | ||
|
||
/** | ||
* @author Andrew Potter | ||
*/ | ||
public interface BatchExecutionHandler { | ||
/** | ||
* Allows separating the logic of handling batch queries from how each individual query is resolved. | ||
* @param batchedInvocationInput the batch query input | ||
* @param queryFunction Function to produce query results. | ||
*/ | ||
void handleBatch(GraphQLBatchedInvocationInput batchedInvocationInput, BiFunction<GraphQLInvocationInput, ExecutionInput, ExecutionResult> queryFunction); | ||
} | ||
|
47 changes: 47 additions & 0 deletions
47
src/main/java/graphql/servlet/DefaultGraphQLBatchExecutionHandlerFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package graphql.servlet; | ||
|
||
import graphql.ExecutionInput; | ||
import graphql.ExecutionResult; | ||
|
||
import java.io.IOException; | ||
import java.io.Writer; | ||
import java.util.Iterator; | ||
import java.util.function.BiFunction; | ||
|
||
public class DefaultGraphQLBatchExecutionHandlerFactory implements GraphQLBatchExecutionHandlerFactory { | ||
@Override | ||
public BatchExecutionHandler getBatchHandler(Writer respWriter, GraphQLObjectMapper graphQLObjectMapper) { | ||
return new DefaultGraphQLBatchExecutionHandler(respWriter, graphQLObjectMapper); | ||
} | ||
|
||
private class DefaultGraphQLBatchExecutionHandler implements BatchExecutionHandler { | ||
|
||
private final Writer respWriter; | ||
|
||
private final GraphQLObjectMapper graphQLObjectMapper; | ||
|
||
private DefaultGraphQLBatchExecutionHandler(Writer respWriter, GraphQLObjectMapper graphQLObjectMapper) { | ||
this.respWriter = respWriter; | ||
this.graphQLObjectMapper = graphQLObjectMapper; | ||
} | ||
|
||
@Override | ||
public void handleBatch(GraphQLBatchedInvocationInput batchedInvocationInput, BiFunction<GraphQLInvocationInput, ExecutionInput, | ||
ExecutionResult> queryFunction) { | ||
Iterator<ExecutionInput> executionInputIterator = batchedInvocationInput.getExecutionInputs().iterator(); | ||
try { | ||
respWriter.write("["); | ||
while (executionInputIterator.hasNext()) { | ||
ExecutionResult result = queryFunction.apply(batchedInvocationInput, executionInputIterator.next()); | ||
respWriter.write(graphQLObjectMapper.serializeResultAsJson(result)); | ||
if (executionInputIterator.hasNext()) { | ||
respWriter.write(","); | ||
} | ||
} | ||
respWriter.write("]"); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
src/main/java/graphql/servlet/GraphQLBatchExecutionHandlerFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package graphql.servlet; | ||
|
||
import java.io.Writer; | ||
|
||
/** | ||
* Interface to allow customization of how batched queries are handled. | ||
*/ | ||
public interface GraphQLBatchExecutionHandlerFactory { | ||
/** | ||
* Produces an BatchExecutionHandler instance for a specific response. Can maintain state across each request within a batch. | ||
* @param respWriter to send the response back | ||
* @param graphQLObjectMapper to serialize results. | ||
* @return a handler instance | ||
*/ | ||
BatchExecutionHandler getBatchHandler(Writer respWriter, GraphQLObjectMapper graphQLObjectMapper); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.