Skip to content

Commit 2baa91f

Browse files
committed
SchemaUtil is not static any more
1 parent c2cee89 commit 2baa91f

File tree

14 files changed

+50
-41
lines changed

14 files changed

+50
-41
lines changed

src/main/java/graphql/execution/FieldCollector.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,21 @@
22

33

44
import graphql.language.*;
5-
import graphql.schema.GraphQLInterfaceType;
6-
import graphql.schema.GraphQLObjectType;
7-
import graphql.schema.GraphQLType;
8-
import graphql.schema.GraphQLUnionType;
5+
import graphql.schema.*;
96

107
import java.util.ArrayList;
118
import java.util.List;
129
import java.util.Map;
1310

1411
import static graphql.execution.TypeFromAST.getTypeFromAST;
15-
import static graphql.schema.SchemaUtil.findImplementations;
1612

1713
public class FieldCollector {
1814

1915
private ValuesResolver valuesResolver;
2016
private ConditionalNodes conditionalNodes;
2117

18+
private SchemaUtil schemaUtil = new SchemaUtil();
19+
2220
public FieldCollector() {
2321
valuesResolver = new ValuesResolver();
2422
conditionalNodes = new ConditionalNodes();
@@ -100,7 +98,7 @@ private boolean checkTypeCondition(ExecutionContext executionContext, GraphQLObj
10098
}
10199

102100
if (conditionType instanceof GraphQLInterfaceType) {
103-
List<GraphQLObjectType> implementations = findImplementations(executionContext.getGraphQLSchema(), (GraphQLInterfaceType) conditionType);
101+
List<GraphQLObjectType> implementations = schemaUtil.findImplementations(executionContext.getGraphQLSchema(), (GraphQLInterfaceType) conditionType);
104102
return implementations.contains(type);
105103
} else if (conditionType instanceof GraphQLUnionType) {
106104
return ((GraphQLUnionType) conditionType).getTypes().contains(type);

src/main/java/graphql/execution/TypeFromAST.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@
99

1010
public class TypeFromAST {
1111

12+
private static SchemaUtil schemaUtil = new SchemaUtil();
13+
1214
public static GraphQLType getTypeFromAST(GraphQLSchema schema, Type type) {
1315
if (type instanceof ListType) {
1416
return new GraphQLList(getTypeFromAST(schema, ((ListType) type).getType()));
1517
} else if (type instanceof NonNullType) {
1618
return new GraphQLNonNull(getTypeFromAST(schema, ((NonNullType) type).getType()));
1719
}
18-
return SchemaUtil.findType(schema, ((TypeName) type).getName());
20+
return schemaUtil.findType(schema, ((TypeName) type).getName());
1921
}
2022
}

src/main/java/graphql/introspection/Schema.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ public Object get(DataFetchingEnvironment environment) {
196196
public Object get(DataFetchingEnvironment environment) {
197197
Object type = environment.getSource();
198198
if (type instanceof GraphQLInterfaceType) {
199-
return SchemaUtil.findImplementations(environment.getGraphQLSchema(), (GraphQLInterfaceType) type);
199+
return new SchemaUtil().findImplementations(environment.getGraphQLSchema(), (GraphQLInterfaceType) type);
200200
}
201201
if (type instanceof GraphQLUnionType) {
202202
return ((GraphQLUnionType) type).getTypes();
@@ -334,7 +334,7 @@ public Object get(DataFetchingEnvironment environment) {
334334
@Override
335335
public Object get(DataFetchingEnvironment environment) {
336336
GraphQLSchema schema = (GraphQLSchema) environment.getSource();
337-
return SchemaUtil.allTypesAsList(schema);
337+
return new SchemaUtil().allTypesAsList(schema);
338338
}
339339
})
340340
.build())
@@ -396,7 +396,7 @@ public Object get(DataFetchingEnvironment environment) {
396396
@Override
397397
public Object get(DataFetchingEnvironment environment) {
398398
String name = environment.getArgument("name");
399-
return SchemaUtil.findType(environment.getGraphQLSchema(), name);
399+
return new SchemaUtil().findType(environment.getGraphQLSchema(), name);
400400
}
401401
})
402402
.build();

src/main/java/graphql/schema/GraphQLFieldDefinition.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public GraphQLFieldDefinition(String name, String description, GraphQLOutputType
2828

2929

3030
void replaceTypeReferences(Map<String, GraphQLType> typeMap) {
31-
type = (GraphQLOutputType) SchemaUtil.resolveTypeReference(type, typeMap);
31+
type = (GraphQLOutputType) new SchemaUtil().resolveTypeReference(type, typeMap);
3232
}
3333

3434
public String getName() {

src/main/java/graphql/schema/GraphQLList.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public GraphQLType getWrappedType() {
1717
}
1818

1919
void replaceTypeReferences(Map<String, GraphQLType> typeMap) {
20-
wrappedType = SchemaUtil.resolveTypeReference(wrappedType, typeMap);
20+
wrappedType = new SchemaUtil().resolveTypeReference(wrappedType, typeMap);
2121
}
2222

2323
@Override

src/main/java/graphql/schema/GraphQLNonNull.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public GraphQLType getWrappedType() {
1616
}
1717

1818
void replaceTypeReferences(Map<String, GraphQLType> typeMap) {
19-
wrappedType = SchemaUtil.resolveTypeReference(wrappedType, typeMap);
19+
wrappedType = new SchemaUtil().resolveTypeReference(wrappedType, typeMap);
2020
}
2121

2222

src/main/java/graphql/schema/GraphQLSchema.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public Builder mutation(GraphQLObjectType mutationType) {
6666

6767
public GraphQLSchema build() {
6868
GraphQLSchema graphQLSchema = new GraphQLSchema(queryType, mutationType);
69-
SchemaUtil.replaceTypeReferences(graphQLSchema);
69+
new SchemaUtil().replaceTypeReferences(graphQLSchema);
7070
return graphQLSchema;
7171
}
7272

src/main/java/graphql/schema/SchemaUtil.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,30 @@
88

99
public class SchemaUtil {
1010

11-
public static boolean isLeafType(GraphQLType type) {
11+
public boolean isLeafType(GraphQLType type) {
1212
GraphQLUnmodifiedType unmodifiedType = getUnmodifiedType(type);
1313
return
1414
unmodifiedType instanceof GraphQLScalarType
1515
|| unmodifiedType instanceof GraphQLEnumType;
1616
}
1717

18-
public static boolean isInputType(GraphQLType graphQLType) {
18+
public boolean isInputType(GraphQLType graphQLType) {
1919
GraphQLUnmodifiedType unmodifiedType = getUnmodifiedType(graphQLType);
2020
return
2121
unmodifiedType instanceof GraphQLScalarType
2222
|| unmodifiedType instanceof GraphQLEnumType
2323
|| unmodifiedType instanceof GraphQLInputObjectType;
2424
}
2525

26-
public static GraphQLUnmodifiedType getUnmodifiedType(GraphQLType graphQLType) {
26+
public GraphQLUnmodifiedType getUnmodifiedType(GraphQLType graphQLType) {
2727
if (graphQLType instanceof GraphQLModifiedType) {
2828
return getUnmodifiedType(((GraphQLModifiedType) graphQLType).getWrappedType());
2929
}
3030
return (GraphQLUnmodifiedType) graphQLType;
3131
}
3232

3333

34-
private static void collectTypes(GraphQLType root, Map<String, GraphQLType> result) {
34+
private void collectTypes(GraphQLType root, Map<String, GraphQLType> result) {
3535
if (root instanceof GraphQLNonNull) {
3636
collectTypes(((GraphQLNonNull) root).getWrappedType(), result);
3737
} else if (root instanceof GraphQLList) {
@@ -55,14 +55,14 @@ private static void collectTypes(GraphQLType root, Map<String, GraphQLType> resu
5555
}
5656
}
5757

58-
private static void collectTypesForUnions(GraphQLUnionType unionType, Map<String, GraphQLType> result) {
58+
private void collectTypesForUnions(GraphQLUnionType unionType, Map<String, GraphQLType> result) {
5959
for (GraphQLType type : unionType.getTypes()) {
6060
collectTypes(type, result);
6161
}
6262

6363
}
6464

65-
private static void collectTypesForInterfaces(GraphQLInterfaceType interfaceType, Map<String, GraphQLType> result) {
65+
private void collectTypesForInterfaces(GraphQLInterfaceType interfaceType, Map<String, GraphQLType> result) {
6666
if (result.containsKey(interfaceType.getName())) return;
6767
result.put(interfaceType.getName(), interfaceType);
6868

@@ -75,7 +75,7 @@ private static void collectTypesForInterfaces(GraphQLInterfaceType interfaceType
7575
}
7676

7777

78-
private static void collectTypesForObjects(GraphQLObjectType objectType, Map<String, GraphQLType> result) {
78+
private void collectTypesForObjects(GraphQLObjectType objectType, Map<String, GraphQLType> result) {
7979
if (result.containsKey(objectType.getName())) return;
8080
result.put(objectType.getName(), objectType);
8181

@@ -87,12 +87,12 @@ private static void collectTypesForObjects(GraphQLObjectType objectType, Map<Str
8787
}
8888
}
8989

90-
public static GraphQLType findType(GraphQLSchema schema, String name) {
90+
public GraphQLType findType(GraphQLSchema schema, String name) {
9191
Map<String, GraphQLType> typesByName = allTypes(schema);
9292
return typesByName.get(name);
9393
}
9494

95-
public static Map<String, GraphQLType> allTypes(GraphQLSchema schema) {
95+
public Map<String, GraphQLType> allTypes(GraphQLSchema schema) {
9696
Map<String, GraphQLType> typesByName = new LinkedHashMap<>();
9797
collectTypes(schema.getQueryType(), typesByName);
9898
if (schema.isSupportingMutations()) {
@@ -101,11 +101,11 @@ public static Map<String, GraphQLType> allTypes(GraphQLSchema schema) {
101101
return typesByName;
102102
}
103103

104-
public static List<GraphQLType> allTypesAsList(GraphQLSchema graphQLSchema) {
104+
public List<GraphQLType> allTypesAsList(GraphQLSchema graphQLSchema) {
105105
return new ArrayList<>(allTypes(graphQLSchema).values());
106106
}
107107

108-
public static List<GraphQLObjectType> findImplementations(GraphQLSchema schema, GraphQLInterfaceType interfaceType) {
108+
public List<GraphQLObjectType> findImplementations(GraphQLSchema schema, GraphQLInterfaceType interfaceType) {
109109
Map<String, GraphQLType> allTypes = allTypes(schema);
110110
List<GraphQLObjectType> result = new ArrayList<>();
111111
for (GraphQLType type : allTypes.values()) {
@@ -119,7 +119,7 @@ public static List<GraphQLObjectType> findImplementations(GraphQLSchema schema,
119119
}
120120

121121

122-
static void replaceTypeReferences(GraphQLSchema schema) {
122+
void replaceTypeReferences(GraphQLSchema schema) {
123123
Map<String, GraphQLType> typeMap = allTypes(schema);
124124
for (GraphQLType type : typeMap.values()) {
125125
if (type instanceof GraphQLFieldsContainer) {
@@ -128,13 +128,13 @@ static void replaceTypeReferences(GraphQLSchema schema) {
128128
}
129129
}
130130

131-
private static void resolveTypeReferencesForFieldsContainer(GraphQLFieldsContainer fieldsContainer, Map<String, GraphQLType> typeMap) {
131+
private void resolveTypeReferencesForFieldsContainer(GraphQLFieldsContainer fieldsContainer, Map<String, GraphQLType> typeMap) {
132132
for (GraphQLFieldDefinition fieldDefinition : fieldsContainer.getFieldDefinitions()) {
133133
fieldDefinition.replaceTypeReferences(typeMap);
134134
}
135135
}
136136

137-
static GraphQLType resolveTypeReference(GraphQLType type, Map<String, GraphQLType> typeMap) {
137+
GraphQLType resolveTypeReference(GraphQLType type, Map<String, GraphQLType> typeMap) {
138138
if (type instanceof GraphQLTypeReference) {
139139
return typeMap.get(type.getName());
140140
}
@@ -147,7 +147,7 @@ static GraphQLType resolveTypeReference(GraphQLType type, Map<String, GraphQLTyp
147147
return type;
148148
}
149149

150-
static List<GraphQLType> resolveTypeReferences(List<GraphQLType> types, Map<String, GraphQLType> typeMap) {
150+
List<GraphQLType> resolveTypeReferences(List<GraphQLType> types, Map<String, GraphQLType> typeMap) {
151151
List<GraphQLType> resolvedTypes = new ArrayList<>();
152152
for (GraphQLType type : types) {
153153
resolvedTypes.add(resolveTypeReference(type, typeMap));

src/main/java/graphql/validation/TraversalContext.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ public class TraversalContext implements QueryLanguageVisitor {
2020
GraphQLDirective directive;
2121
GraphQLArgument argument;
2222

23+
SchemaUtil schemaUtil = new SchemaUtil();
24+
2325

2426
public TraversalContext(GraphQLSchema graphQLSchema) {
2527
this.schema = graphQLSchema;
@@ -52,7 +54,7 @@ public void enter(Node node) {
5254

5355

5456
private void enterImpl(SelectionSet selectionSet) {
55-
GraphQLUnmodifiedType rawType = SchemaUtil.getUnmodifiedType(getOutputType());
57+
GraphQLUnmodifiedType rawType = new SchemaUtil().getUnmodifiedType(getOutputType());
5658
GraphQLCompositeType parentType = null;
5759
if (rawType instanceof GraphQLCompositeType) {
5860
parentType = (GraphQLCompositeType) rawType;
@@ -85,12 +87,12 @@ private void enterImpl(OperationDefinition operationDefinition) {
8587
}
8688

8789
private void enterImpl(InlineFragment inlineFragment) {
88-
GraphQLType type = SchemaUtil.findType(schema, inlineFragment.getTypeCondition().getName());
90+
GraphQLType type = schemaUtil.findType(schema, inlineFragment.getTypeCondition().getName());
8991
addType((GraphQLOutputType) type);
9092
}
9193

9294
private void enterImpl(FragmentDefinition fragmentDefinition) {
93-
GraphQLType type = SchemaUtil.findType(schema, fragmentDefinition.getTypeCondition().getName());
95+
GraphQLType type = schemaUtil.findType(schema, fragmentDefinition.getTypeCondition().getName());
9496
addType((GraphQLOutputType) type);
9597
}
9698

@@ -121,7 +123,7 @@ private void enterImpl(ArrayValue arrayValue) {
121123
}
122124

123125
private void enterImpl(ObjectField objectField) {
124-
GraphQLUnmodifiedType objectType = SchemaUtil.getUnmodifiedType(getInputType());
126+
GraphQLUnmodifiedType objectType = schemaUtil.getUnmodifiedType(getInputType());
125127
GraphQLInputType inputType = null;
126128
if (objectType instanceof GraphQLInputObjectType) {
127129
GraphQLInputObjectField inputField = ((GraphQLInputObjectType) objectType).getField(objectField.getName());
@@ -157,7 +159,7 @@ public void leave(Node node) {
157159
inputTypeStack.remove(inputTypeStack.size() - 1);
158160
} else if (node instanceof Argument) {
159161
argument = null;
160-
inputTypeStack.remove(inputTypeStack.size()-1);
162+
inputTypeStack.remove(inputTypeStack.size() - 1);
161163
} else if (node instanceof ArrayValue) {
162164
inputTypeStack.remove(inputTypeStack.size() - 1);
163165
} else if (node instanceof ObjectField) {

src/main/java/graphql/validation/rules/FragmentsOnCompositeType.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@
1010

1111
public class FragmentsOnCompositeType extends AbstractRule {
1212

13+
private SchemaUtil schemaUtil = new SchemaUtil();
14+
1315
public FragmentsOnCompositeType(ValidationContext validationContext, ErrorCollector errorCollector) {
1416
super(validationContext, errorCollector);
1517
}
1618

1719
@Override
1820
public void checkInlineFragment(InlineFragment inlineFragment) {
19-
GraphQLType type = SchemaUtil.findType(getValidationContext().getSchema(), inlineFragment.getTypeCondition().getName());
21+
GraphQLType type = schemaUtil.findType(getValidationContext().getSchema(), inlineFragment.getTypeCondition().getName());
2022
if (type == null) return;
2123
if (!(type instanceof GraphQLCompositeType)) {
2224
addError(new ValidationError(ValidationErrorType.InlineFragmentTypeConditionInvalid));
@@ -25,7 +27,7 @@ public void checkInlineFragment(InlineFragment inlineFragment) {
2527

2628
@Override
2729
public void checkFragmentDefinition(FragmentDefinition fragmentDefinition) {
28-
GraphQLType type = SchemaUtil.findType(getValidationContext().getSchema(), fragmentDefinition.getTypeCondition().getName());
30+
GraphQLType type = schemaUtil.findType(getValidationContext().getSchema(), fragmentDefinition.getTypeCondition().getName());
2931
if (type == null) return;
3032
if (!(type instanceof GraphQLCompositeType)) {
3133
addError(new ValidationError(ValidationErrorType.InlineFragmentTypeConditionInvalid));

0 commit comments

Comments
 (0)