-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1543 from gentics/hotfix-1.10.x-sup-15904-2
SUP-15409: Speed up parent loading the right way
- Loading branch information
Showing
8 changed files
with
305 additions
and
50 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
81 changes: 81 additions & 0 deletions
81
...ain/java/com/gentics/mesh/graphql/dataloader/NodeContentWithOptionalRuntimeException.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,81 @@ | ||
package com.gentics.mesh.graphql.dataloader; | ||
|
||
import org.dataloader.DataLoader; | ||
|
||
import com.gentics.mesh.core.data.node.NodeContent; | ||
|
||
import graphql.ExceptionWhileDataFetching; | ||
import graphql.execution.DataFetcherResult; | ||
import graphql.execution.DataFetcherResult.Builder; | ||
import graphql.schema.DataFetchingEnvironment; | ||
|
||
/** | ||
* Container class for an instance of {@link NodeContent} and an optional {@link RuntimeException}. | ||
* Instances of this class can be returned from {@link DataLoader} implementations (like the e.g. {@link NodeDataLoader#PARENT_LOADER}). | ||
*/ | ||
public class NodeContentWithOptionalRuntimeException { | ||
/** | ||
* NodeContent to be returned (may be null) | ||
*/ | ||
private final NodeContent nodeContent; | ||
|
||
/** | ||
* RuntimeException, which was thrown while trying to fetch the nodeContent (may be null) | ||
*/ | ||
private final RuntimeException runtimeException; | ||
|
||
/** | ||
* Empty instance (nodeContent and runtimeException are both null). Can be used to return null but without error | ||
*/ | ||
public final static NodeContentWithOptionalRuntimeException EMPTY = new NodeContentWithOptionalRuntimeException(); | ||
|
||
/** | ||
* Constructor for empty instance | ||
*/ | ||
private NodeContentWithOptionalRuntimeException() { | ||
this(null, null); | ||
} | ||
|
||
/** | ||
* Create instance returning the given nodeContent | ||
* @param nodeContent returned value | ||
*/ | ||
public NodeContentWithOptionalRuntimeException(NodeContent nodeContent) { | ||
this(nodeContent, null); | ||
} | ||
|
||
/** | ||
* Create instance returning null and adding an error | ||
* @param runtimeException exception | ||
*/ | ||
public NodeContentWithOptionalRuntimeException(RuntimeException runtimeException) { | ||
this(null, runtimeException); | ||
} | ||
|
||
/** | ||
* Create instance returning a nodeContent (may be null) and optionally adding an error | ||
* @param nodeContent returned value | ||
* @param runtimeException optional exception | ||
*/ | ||
public NodeContentWithOptionalRuntimeException(NodeContent nodeContent, RuntimeException runtimeException) { | ||
this.nodeContent = nodeContent; | ||
this.runtimeException = runtimeException; | ||
} | ||
|
||
/** | ||
* Transform the value into an instance of {@link DataFetcherResult} for the given environment. | ||
* If the nodeContent is null, but a runtimeException has been set, the runtimeException will be thrown | ||
* @param env data fetching environment | ||
* @return data fetcher result | ||
*/ | ||
public DataFetcherResult<NodeContent> getResult(DataFetchingEnvironment env) { | ||
if (nodeContent == null && runtimeException != null) { | ||
throw runtimeException; | ||
} | ||
Builder<NodeContent> builder = DataFetcherResult.<NodeContent>newResult().data(nodeContent); | ||
if (runtimeException != null) { | ||
builder.error(new ExceptionWhileDataFetching(env.getExecutionStepInfo().getPath(), runtimeException, env.getField().getSourceLocation())); | ||
} | ||
return builder.build(); | ||
} | ||
} |
Oops, something went wrong.