Skip to content

Conversation

@bbakerman
Copy link
Member

This will improve the runtime for every object type encountered since the type env allocation (and indeed method call) is not needed

@bbakerman bbakerman added this to the 20.0 milestone Oct 5, 2022
try {
return asyncHandleException(dataFetcherExceptionHandler, handlerParameters, executionContext);
return asyncHandleException(dataFetcherExceptionHandler, handlerParameters);
} catch (Exception handlerException) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Boy scout change - the executionContext was never used

.exception(handlerException)
.build();
return asyncHandleException(new SimpleDataFetcherExceptionHandler(), handlerParameters, executionContext);
return asyncHandleException(new SimpleDataFetcherExceptionHandler(), handlerParameters);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Boy scout change - the executionContext was never used

}

private <T> CompletableFuture<T> asyncHandleException(DataFetcherExceptionHandler handler, DataFetcherExceptionHandlerParameters handlerParameters, ExecutionContext executionContext) {
private <T> CompletableFuture<T> asyncHandleException(DataFetcherExceptionHandler handler, DataFetcherExceptionHandlerParameters handlerParameters) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Boy scout change - the executionContext was never used

Object serialized;
try {
serialized = enumType.serialize(result);
serialized = enumType.serialize(result, executionContext.getGraphQLContext(), executionContext.getLocale());
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Boy scout change - the deprecated method should not have been using this mechanism

.objectType(resolvedObjectType)
.fragments(executionContext.getFragmentsByName())
.variables(executionContext.getVariables())
.variables(executionContext.getCoercedVariables().toMap())
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Boy scout change - the deprecated method was used

// we can avoid a method call and type resolver environment allocation if we know it's an object type
if (fieldType instanceof GraphQLObjectType) {
return (GraphQLObjectType) fieldType;
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can avoid calling the extra method and inside that the resolver type env allocation if we know its an object type upfront

I originally did this inside esolvedType.resolveType() but why even call it with object types. This is faster


/**
* See (http://facebook.github.io/graphql/#sec-Errors-and-Non-Nullability),
* See (<a href="http://facebook.github.io/graphql/#sec-Errors-and-Non-Nullability">...</a>),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Boy scout change - warning from IDEA

GraphQLObjectType resolvedType;
Assert.assertTrue(fieldType instanceof GraphQLInterfaceType || fieldType instanceof GraphQLUnionType,
() -> "The passed in fieldType MUST be an interface or union type : " + fieldType.getClass().getName());
TypeResolutionEnvironment env = buildEnv(executionContext, field, source, executionStepInfo, fieldType, localContext);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We now ONLY take unions and interfaces. Since the object type check is outside now. This class is NOT general purpose and ONLY used above

public GraphQLObjectType resolveType(ExecutionContext executionContext, MergedField field, Object source, ExecutionStepInfo executionStepInfo, GraphQLType fieldType, Object localContext) {
GraphQLObjectType resolvedType;
Assert.assertTrue(fieldType instanceof GraphQLInterfaceType || fieldType instanceof GraphQLUnionType,
() -> "The passed in fieldType MUST be an interface or union type : " + fieldType.getClass().getName());
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now only interfaces and unions into this method. The outer code does the object check.

I know its more self contained if perhaps did all three but performance is performance. Not only do we avoid a env object allocation - we avoid a method call as well.

Copy link
Member

@dondonz dondonz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@bbakerman bbakerman merged commit 5643c46 into master Oct 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants