Skip to content

Commit

Permalink
GraphQL Field level context and error event on blocking fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Phillip Kruger <[email protected]>
  • Loading branch information
phillip-kruger committed Sep 3, 2022
1 parent 36ea30a commit fa2424f
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 7 deletions.
2 changes: 1 addition & 1 deletion bom/application/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
<smallrye-health.version>3.2.1</smallrye-health.version>
<smallrye-metrics.version>3.0.5</smallrye-metrics.version>
<smallrye-open-api.version>2.2.0</smallrye-open-api.version>
<smallrye-graphql.version>1.7.0</smallrye-graphql.version>
<smallrye-graphql.version>1.7.1</smallrye-graphql.version>
<smallrye-opentracing.version>2.1.1</smallrye-opentracing.version>
<smallrye-fault-tolerance.version>5.5.0</smallrye-fault-tolerance.version>
<smallrye-jwt.version>3.5.3</smallrye-jwt.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public void handle(final RoutingContext ctx) {
}
}

private Void handleWithIdentity(final RoutingContext ctx) {
private void handleWithIdentity(final RoutingContext ctx) {
if (currentIdentityAssociation != null) {
QuarkusHttpUser existing = (QuarkusHttpUser) ctx.user();
if (existing != null) {
Expand All @@ -93,7 +93,6 @@ private Void handleWithIdentity(final RoutingContext ctx) {
}
currentVertxRequest.setCurrent(ctx);
doHandle(ctx);
return null;
}

protected abstract void doHandle(final RoutingContext ctx);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package io.quarkus.smallrye.graphql.runtime.spi.datafetcher;

import io.smallrye.graphql.execution.datafetcher.PlugableBatchableDataFetcher;
import io.smallrye.graphql.execution.datafetcher.PlugableDataFetcher;
import io.smallrye.graphql.schema.model.Field;
import io.smallrye.graphql.schema.model.Operation;
import io.smallrye.graphql.schema.model.Reference;
import io.smallrye.graphql.schema.model.Type;
import io.smallrye.graphql.spi.DataFetcherService;

Expand All @@ -18,18 +21,22 @@ public Integer getPriority() {
}

@Override
public PlugableDataFetcher getUniDataFetcher(Operation operation, Type type) {
public PlugableBatchableDataFetcher getUniDataFetcher(Operation operation, Type type) {
return new QuarkusUniDataFetcher(operation, type);
}

@Override
public PlugableDataFetcher getDefaultDataFetcher(Operation operation, Type type) {
public PlugableBatchableDataFetcher getDefaultDataFetcher(Operation operation, Type type) {
return new QuarkusDefaultDataFetcher(operation, type);
}

@Override
public PlugableDataFetcher getCompletionStageDataFetcher(Operation operation, Type type) {
public PlugableBatchableDataFetcher getCompletionStageDataFetcher(Operation operation, Type type) {
return new QuarkusCompletionStageDataFetcher(operation, type);
}

@Override
public PlugableDataFetcher getFieldDataFetcher(Field field, Type type, Reference owner) {
return new QuarkusFieldDataFetcher(field, type, owner);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ private <T> T invokeAndTransformBlocking(final DataFetchingEnvironment dfe, Data
} catch (Error e) {
resultBuilder.clearErrors().data(null).error(new AbortExecutionException(e));
return (T) resultBuilder.build();
} catch (Throwable ex) {
eventEmitter.fireOnDataFetchError(dfe.getExecutionId().toString(), ex);
throw ex;
}
});

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package io.quarkus.smallrye.graphql.runtime.spi.datafetcher;

import graphql.schema.DataFetchingEnvironment;
import io.quarkus.arc.Arc;
import io.quarkus.arc.ManagedContext;
import io.smallrye.graphql.execution.datafetcher.FieldDataFetcher;
import io.smallrye.graphql.schema.model.Field;
import io.smallrye.graphql.schema.model.Reference;
import io.smallrye.graphql.schema.model.Type;

public class QuarkusFieldDataFetcher<T> extends FieldDataFetcher<T> {

public QuarkusFieldDataFetcher(final Field field, final Type type, final Reference owner) {
super(field, type, owner);
}

@Override
public T get(DataFetchingEnvironment dfe) throws Exception {
ManagedContext requestContext = Arc.container().requestContext();
try {
RequestContextHelper.reactivate(requestContext, dfe);
return super.get(dfe);
} finally {
requestContext.deactivate();
}
}
}
2 changes: 1 addition & 1 deletion jakarta/rewrite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ recipeList:
newValue: 6.0.0-RC4
- org.openrewrite.maven.ChangePropertyValue:
key: smallrye-graphql.version
newValue: 2.0.0.RC7
newValue: 2.0.0.RC8
- org.openrewrite.maven.ChangePropertyValue:
key: smallrye-health.version
newValue: 4.0.0-RC2
Expand Down

0 comments on commit fa2424f

Please sign in to comment.