Skip to content

Commit c92b102

Browse files
committed
Renamed a few things and added per callback envs
1 parent f9ce2b3 commit c92b102

4 files changed

Lines changed: 36 additions & 18 deletions

File tree

src/main/java/graphql/schema/visitor/GraphQLSmartTypeVisitor.java renamed to src/main/java/graphql/schema/visitor/GraphQLSchemaVisitor.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,25 @@
88
import graphql.util.TraversalControl;
99

1010
/**
11-
* I called it smart because I want to offer more "smarts" above GraphQLTypeVisitor and its "context" uber object
11+
* This visitor interface offers more "smarts" above {@link GraphQLTypeVisitor} and aims to be easier to use
12+
* with more type safe helpers.
1213
* <p>
13-
* You would use it by doing `new GraphQLSmartTypeVisitor() { ...}.toTypeVisitor()`
14+
* You would use it places that need a {@link GraphQLTypeVisitor} by doing `new GraphQLSchemaVisitor() { ...}.toTypeVisitor()`
1415
*/
1516
@PublicSpi
16-
public interface GraphQLSmartTypeVisitor {
17+
public interface GraphQLSchemaVisitor {
1718

18-
default TraversalControl visitGraphQLObjectType(GraphQLObjectType objectType, SmartTypeVisitorEnvironment environment) {
19+
interface ObjectVisitorEnvironment extends GraphQLSchemaVisitorEnvironment {
20+
}
21+
22+
default TraversalControl visitGraphQLObjectType(GraphQLObjectType objectType, ObjectVisitorEnvironment environment) {
1923
return TraversalControl.CONTINUE;
2024
}
2125

2226
/**
2327
* This is a class specific for visiting {@link GraphQLFieldDefinition}s
2428
*/
25-
interface GraphQLFieldDefinitionVisitorEnvironment extends SmartTypeVisitorEnvironment {
29+
interface FieldVisitorEnvironment extends GraphQLSchemaVisitorEnvironment {
2630

2731
GraphQLFieldsContainer getFieldsContainer();
2832

@@ -36,7 +40,7 @@ interface GraphQLFieldDefinitionVisitorEnvironment extends SmartTypeVisitorEnvir
3640
*
3741
* @return control
3842
*/
39-
default TraversalControl visitGraphQLFieldDefinition(GraphQLFieldDefinition fieldDefinition, GraphQLFieldDefinitionVisitorEnvironment environment) {
43+
default TraversalControl visitGraphQLFieldDefinition(GraphQLFieldDefinition fieldDefinition, FieldVisitorEnvironment environment) {
4044
return TraversalControl.CONTINUE;
4145
}
4246

@@ -47,6 +51,6 @@ default TraversalControl visitGraphQLFieldDefinition(GraphQLFieldDefinition fiel
4751
* @return a type visitor
4852
*/
4953
default GraphQLTypeVisitor toTypeVisitor() {
50-
return new GraphQLSmartTypeVisitorAdapter(this);
54+
return new GraphQLSchemaVisitorAdapter(this);
5155
}
5256
}

src/main/java/graphql/schema/visitor/GraphQLSmartTypeVisitorAdapter.java renamed to src/main/java/graphql/schema/visitor/GraphQLSchemaVisitorAdapter.java

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,38 @@
99
import graphql.util.TraversalControl;
1010
import graphql.util.TraverserContext;
1111

12+
import static graphql.schema.visitor.GraphQLSchemaVisitor.FieldVisitorEnvironment;
13+
import static graphql.schema.visitor.GraphQLSchemaVisitor.ObjectVisitorEnvironment;
14+
1215
@Internal
13-
class GraphQLSmartTypeVisitorAdapter extends GraphQLTypeVisitorStub {
16+
class GraphQLSchemaVisitorAdapter extends GraphQLTypeVisitorStub {
1417

15-
private final GraphQLSmartTypeVisitor smartTypeVisitor;
18+
private final GraphQLSchemaVisitor smartTypeVisitor;
1619

17-
GraphQLSmartTypeVisitorAdapter(GraphQLSmartTypeVisitor smartTypeVisitor) {
20+
GraphQLSchemaVisitorAdapter(GraphQLSchemaVisitor smartTypeVisitor) {
1821
this.smartTypeVisitor = smartTypeVisitor;
1922
}
2023

24+
/* ------------------------------
25+
* GraphQLObjectType
26+
* ------------------------------ */
27+
static class ObjectEnv extends GraphQLSchemaVisitorEnvironmentImpl implements ObjectVisitorEnvironment {
28+
public ObjectEnv(TraverserContext<GraphQLSchemaElement> context) {
29+
super(context);
30+
}
31+
}
32+
2133
@Override
2234
public TraversalControl visitGraphQLObjectType(GraphQLObjectType node, TraverserContext<GraphQLSchemaElement> context) {
23-
return smartTypeVisitor.visitGraphQLObjectType(node, new SmartTypeVisitorEnvironmentImpl(context));
35+
return smartTypeVisitor.visitGraphQLObjectType(node, new ObjectEnv(context));
2436
}
2537

38+
/* ------------------------------
39+
* GraphQLFieldDefinition
40+
* ------------------------------ */
41+
static class FieldEnv extends GraphQLSchemaVisitorEnvironmentImpl implements FieldVisitorEnvironment {
2642

27-
static class FieldDefinitionEnv extends SmartTypeVisitorEnvironmentImpl implements GraphQLSmartTypeVisitor.GraphQLFieldDefinitionVisitorEnvironment {
28-
29-
public FieldDefinitionEnv(TraverserContext<GraphQLSchemaElement> context) {
43+
public FieldEnv(TraverserContext<GraphQLSchemaElement> context) {
3044
super(context);
3145
}
3246

@@ -38,6 +52,6 @@ public GraphQLFieldsContainer getFieldsContainer() {
3852

3953
@Override
4054
public TraversalControl visitGraphQLFieldDefinition(GraphQLFieldDefinition node, TraverserContext<GraphQLSchemaElement> context) {
41-
return smartTypeVisitor.visitGraphQLFieldDefinition(node, new FieldDefinitionEnv(context));
55+
return smartTypeVisitor.visitGraphQLFieldDefinition(node, new FieldEnv(context));
4256
}
4357
}

src/main/java/graphql/schema/visitor/SmartTypeVisitorEnvironment.java renamed to src/main/java/graphql/schema/visitor/GraphQLSchemaVisitorEnvironment.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import graphql.schema.GraphQLCodeRegistry;
44

5-
public interface SmartTypeVisitorEnvironment {
5+
public interface GraphQLSchemaVisitorEnvironment {
66

77
GraphQLCodeRegistry.Builder getCodeRegistry();
88
}

src/main/java/graphql/schema/visitor/SmartTypeVisitorEnvironmentImpl.java renamed to src/main/java/graphql/schema/visitor/GraphQLSchemaVisitorEnvironmentImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
import graphql.util.TraverserContext;
77

88
@Internal
9-
class SmartTypeVisitorEnvironmentImpl implements SmartTypeVisitorEnvironment {
9+
class GraphQLSchemaVisitorEnvironmentImpl implements GraphQLSchemaVisitorEnvironment {
1010

1111
protected final TraverserContext<GraphQLSchemaElement> context;
1212

13-
SmartTypeVisitorEnvironmentImpl(TraverserContext<GraphQLSchemaElement> context) {
13+
GraphQLSchemaVisitorEnvironmentImpl(TraverserContext<GraphQLSchemaElement> context) {
1414
this.context = context;
1515
}
1616

0 commit comments

Comments
 (0)