Repository navigation
Expand file tree
/
Copy pathResolveType.java
More file actions
77 lines (63 loc) · 3.34 KB
/
Copy pathResolveType.java
File metadata and controls
77 lines (63 loc) · 3.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package graphql.execution;
import graphql.Internal;
import graphql.TypeResolutionEnvironment;
import graphql.schema.GraphQLInterfaceType;
import graphql.schema.GraphQLObjectType;
import graphql.schema.GraphQLType;
import graphql.schema.GraphQLUnionType;
import graphql.schema.TypeResolver;
import java.util.Map;
@Internal
public class ResolveType {
public GraphQLObjectType resolveType(ExecutionContext executionContext, MergedField field, Object source, Map<String, Object> arguments, GraphQLType fieldType) {
GraphQLObjectType resolvedType;
if (fieldType instanceof GraphQLInterfaceType) {
TypeResolutionParameters resolutionParams = TypeResolutionParameters.newParameters()
.graphQLInterfaceType((GraphQLInterfaceType) fieldType)
.field(field)
.value(source)
.argumentValues(arguments)
.context(executionContext.getContext())
.schema(executionContext.getGraphQLSchema()).build();
resolvedType = resolveTypeForInterface(resolutionParams);
} else if (fieldType instanceof GraphQLUnionType) {
TypeResolutionParameters resolutionParams = TypeResolutionParameters.newParameters()
.graphQLUnionType((GraphQLUnionType) fieldType)
.field(field)
.value(source)
.argumentValues(arguments)
.context(executionContext.getContext())
.schema(executionContext.getGraphQLSchema()).build();
resolvedType = resolveTypeForUnion(resolutionParams);
} else {
resolvedType = (GraphQLObjectType) fieldType;
}
return resolvedType;
}
public GraphQLObjectType resolveTypeForInterface(TypeResolutionParameters params) {
TypeResolutionEnvironment env = new TypeResolutionEnvironment(params.getValue(), params.getArgumentValues(), params.getField(), params.getGraphQLInterfaceType(), params.getSchema(), params.getContext());
GraphQLInterfaceType abstractType = params.getGraphQLInterfaceType();
TypeResolver typeResolver = params.getSchema().getCodeRegistry().getTypeResolver(abstractType);
GraphQLObjectType result = typeResolver.getType(env);
if (result == null) {
throw new UnresolvedTypeException(abstractType);
}
if (!params.getSchema().isPossibleType(abstractType, result)) {
throw new UnresolvedTypeException(abstractType, result);
}
return result;
}
public GraphQLObjectType resolveTypeForUnion(TypeResolutionParameters params) {
TypeResolutionEnvironment env = new TypeResolutionEnvironment(params.getValue(), params.getArgumentValues(), params.getField(), params.getGraphQLUnionType(), params.getSchema(), params.getContext());
GraphQLUnionType abstractType = params.getGraphQLUnionType();
TypeResolver typeResolver = params.getSchema().getCodeRegistry().getTypeResolver(abstractType);
GraphQLObjectType result = typeResolver.getType(env);
if (result == null) {
throw new UnresolvedTypeException(abstractType);
}
if (!params.getSchema().isPossibleType(abstractType, result)) {
throw new UnresolvedTypeException(abstractType, result);
}
return result;
}
}