Skip to content

Commit c0b60b2

Browse files
committed
adds correct ListType and NonNullType handling for the query
1 parent 2d0f797 commit c0b60b2

File tree

13 files changed

+321
-75
lines changed

13 files changed

+321
-75
lines changed

src/main/java/graphql/execution/Execution.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,21 @@ private boolean shouldIncludeNode(ExecutionContext executionContext, List<Direct
233233
}
234234

235235
private boolean doesFragmentTypeApply(ExecutionContext executionContext, Selection selection, GraphQLObjectType type) {
236+
// String typeCondition
237+
// if(selection instanceof InlineFragment){
238+
// typeCondition = ((InlineFragment) selection).getTypeCondition();
239+
// }else if( selection instanceof FragmentDefinition){
240+
// typeCondition = ((FragmentDefinition) selection).getTypeCondition();
241+
// }
242+
// var conditionalType = typeFromAST(exeContext.schema, fragment.typeCondition);
243+
// if (conditionalType === type) {
244+
// return true;
245+
// }
246+
// if (conditionalType instanceof GraphQLInterfaceType ||
247+
// conditionalType instanceof GraphQLUnionType) {
248+
// return conditionalType.isPossibleType(type);
249+
// }
250+
// return false;
236251
return false;
237252
}
238253
}

src/main/java/graphql/execution/Resolver.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ private Map<String, Argument> argumentMap(List<Argument> arguments) {
5656

5757

5858
private Object getVariableValue(GraphQLSchema schema, VariableDefinition variableDefinition, Object inputValue) {
59-
GraphQLType type = SchemaUtil.findType(schema, variableDefinition.getType().getName());
59+
GraphQLType type = TypeFromAST.getTypeFromAST(schema, variableDefinition.getType());
6060

6161
if (!isValid(type, inputValue)) {
6262
throw new GraphQLException("Invalid value for type");
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package graphql.execution;
2+
3+
4+
import graphql.language.ListType;
5+
import graphql.language.NonNullType;
6+
import graphql.language.Type;
7+
import graphql.language.TypeName;
8+
import graphql.schema.*;
9+
10+
public class TypeFromAST {
11+
12+
public static GraphQLType getTypeFromAST(GraphQLSchema schema, Type type) {
13+
if (type instanceof ListType) {
14+
return new GraphQLList(getTypeFromAST(schema, ((ListType) type).getType()));
15+
} else if (type instanceof NonNullType) {
16+
return new GraphQLNonNull(getTypeFromAST(schema, ((NonNullType) type).getType()));
17+
}
18+
return SchemaUtil.findType(schema, ((TypeName) type).getName());
19+
}
20+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package graphql.introspection;
2+
3+
4+
import graphql.schema.GraphQLFieldDefinition;
5+
import graphql.schema.GraphQLList;
6+
import graphql.schema.GraphQLNonNull;
7+
import graphql.schema.GraphQLObjectType;
8+
9+
import java.util.Arrays;
10+
import java.util.Collections;
11+
import java.util.List;
12+
13+
public class Schema {
14+
15+
// private static GraphQLFieldDefinition types = new GraphQLFieldDefinition("types",
16+
// new GraphQLNonNull(new GraphQLList(new GraphQLNonNull())));
17+
//
18+
//
19+
// private static List<GraphQLFieldDefinition> fields = Arrays.asList(types);
20+
// public static GraphQLObjectType __Schema = new GraphQLObjectType("__Schema",
21+
//
22+
// });
23+
}

src/main/java/graphql/language/FragmentDefinition.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,20 @@
55

66
public class FragmentDefinition implements Definition {
77
private String name;
8-
private String typeCondition;
8+
private TypeName typeCondition;
99
private List<Directive> directives;
1010
private SelectionSet selectionSet;
1111

1212
public FragmentDefinition() {
1313

1414
}
1515

16-
public FragmentDefinition(String name, String typeCondition) {
16+
public FragmentDefinition(String name, TypeName typeCondition) {
1717
this.name = name;
1818
this.typeCondition = typeCondition;
1919
}
20-
public FragmentDefinition(String name, String typeCondition,SelectionSet selectionSet) {
20+
21+
public FragmentDefinition(String name, TypeName typeCondition, SelectionSet selectionSet) {
2122
this.name = name;
2223
this.typeCondition = typeCondition;
2324
this.selectionSet = selectionSet;
@@ -32,11 +33,11 @@ public void setName(String name) {
3233
this.name = name;
3334
}
3435

35-
public String getTypeCondition() {
36+
public TypeName getTypeCondition() {
3637
return typeCondition;
3738
}
3839

39-
public void setTypeCondition(String typeCondition) {
40+
public void setTypeCondition(TypeName typeCondition) {
4041
this.typeCondition = typeCondition;
4142
}
4243

src/main/java/graphql/language/InlineFragment.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,35 @@
55
import java.util.List;
66

77
public class InlineFragment implements Selection {
8-
private String typeCondition;
8+
private TypeName typeCondition;
99
private List<Directive> directives = new ArrayList<>();
1010
private SelectionSet selectionSet;
1111

1212
public InlineFragment() {
1313

1414
}
1515

16-
public InlineFragment(String typeCondition) {
16+
public InlineFragment(TypeName typeCondition) {
1717
this.typeCondition = typeCondition;
1818
}
1919

20-
public InlineFragment(String typeCondition, List<Directive> directives, SelectionSet selectionSet) {
20+
public InlineFragment(TypeName typeCondition, List<Directive> directives, SelectionSet selectionSet) {
2121
this.typeCondition = typeCondition;
2222
this.directives = directives;
2323
this.selectionSet = selectionSet;
2424
}
2525

26-
public InlineFragment(String typeCondition, SelectionSet selectionSet) {
26+
public InlineFragment(TypeName typeCondition, SelectionSet selectionSet) {
2727
this.typeCondition = typeCondition;
2828
this.selectionSet = selectionSet;
2929
}
3030

3131

32-
public String getTypeCondition() {
32+
public TypeName getTypeCondition() {
3333
return typeCondition;
3434
}
3535

36-
public void setTypeCondition(String typeCondition) {
36+
public void setTypeCondition(TypeName typeCondition) {
3737
this.typeCondition = typeCondition;
3838
}
3939

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package graphql.language;
2+
3+
4+
public class ListType implements Type{
5+
6+
private Type type;
7+
8+
public ListType() {
9+
}
10+
11+
public ListType(Type type) {
12+
this.type = type;
13+
}
14+
15+
public Type getType() {
16+
return type;
17+
}
18+
19+
public void setType(Type type) {
20+
this.type = type;
21+
}
22+
23+
@Override
24+
public boolean equals(Object o) {
25+
if (this == o) return true;
26+
if (o == null || getClass() != o.getClass()) return false;
27+
28+
ListType listType = (ListType) o;
29+
30+
return !(type != null ? !type.equals(listType.type) : listType.type != null);
31+
32+
}
33+
34+
@Override
35+
public int hashCode() {
36+
return type != null ? type.hashCode() : 0;
37+
}
38+
39+
@Override
40+
public String toString() {
41+
return "ListType{" +
42+
"type=" + type +
43+
'}';
44+
}
45+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package graphql.language;
2+
3+
4+
public class NonNullType implements Type {
5+
6+
private Type type;
7+
8+
public NonNullType() {
9+
}
10+
11+
public NonNullType(Type type) {
12+
this.type = type;
13+
}
14+
15+
public Type getType() {
16+
return type;
17+
}
18+
19+
public void setType(ListType type) {
20+
this.type = type;
21+
}
22+
23+
public void setType(TypeName type) {
24+
this.type = type;
25+
}
26+
27+
@Override
28+
public boolean equals(Object o) {
29+
if (this == o) return true;
30+
if (o == null || getClass() != o.getClass()) return false;
31+
32+
NonNullType that = (NonNullType) o;
33+
34+
return !(type != null ? !type.equals(that.type) : that.type != null);
35+
36+
}
37+
38+
@Override
39+
public int hashCode() {
40+
return type != null ? type.hashCode() : 0;
41+
}
42+
43+
@Override
44+
public String toString() {
45+
return "NonNullType{" +
46+
"type=" + type +
47+
'}';
48+
}
49+
}
Lines changed: 1 addition & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,5 @@
11
package graphql.language;
22

33

4-
public class Type {
5-
6-
private String name;
7-
8-
public Type() {
9-
}
10-
11-
12-
public Type(String name) {
13-
this.name = name;
14-
}
15-
16-
public String getName() {
17-
return name;
18-
}
19-
20-
public void setName(String name) {
21-
this.name = name;
22-
}
23-
24-
@Override
25-
public boolean equals(Object o) {
26-
if (this == o) return true;
27-
if (o == null || getClass() != o.getClass()) return false;
28-
29-
Type type = (Type) o;
30-
31-
return !(name != null ? !name.equals(type.name) : type.name != null);
32-
33-
}
34-
35-
@Override
36-
public int hashCode() {
37-
return name != null ? name.hashCode() : 0;
38-
}
39-
40-
@Override
41-
public String toString() {
42-
return "Type{" +
43-
"name='" + name + '\'' +
44-
'}';
45-
}
4+
public interface Type {
465
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package graphql.language;
2+
3+
4+
public class TypeName implements Type{
5+
6+
private String name;
7+
8+
public TypeName(String name) {
9+
this.name = name;
10+
}
11+
12+
public String getName() {
13+
return name;
14+
}
15+
16+
public void setName(String name) {
17+
this.name = name;
18+
}
19+
20+
@Override
21+
public boolean equals(Object o) {
22+
if (this == o) return true;
23+
if (o == null || getClass() != o.getClass()) return false;
24+
25+
TypeName namedType = (TypeName) o;
26+
27+
if (name != null ? !name.equals(namedType.name) : namedType.name != null) return false;
28+
29+
return true;
30+
}
31+
32+
@Override
33+
public int hashCode() {
34+
return name != null ? name.hashCode() : 0;
35+
}
36+
37+
@Override
38+
public String toString() {
39+
return "TypeName{" +
40+
"name='" + name + '\'' +
41+
'}';
42+
}
43+
}

0 commit comments

Comments
 (0)