Repository navigation
Expand file tree
/
Copy pathWiringFactory.java
More file actions
119 lines (107 loc) · 3.71 KB
/
Copy pathWiringFactory.java
File metadata and controls
119 lines (107 loc) · 3.71 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
package graphql.schema.idl;
import graphql.PublicSpi;
import graphql.schema.DataFetcher;
import graphql.schema.DataFetcherFactory;
import graphql.schema.PropertyDataFetcher;
import graphql.schema.TypeResolver;
import static graphql.Assert.assertShouldNeverHappen;
/**
* A WiringFactory allows you to more dynamically wire in {@link TypeResolver}s and {@link DataFetcher}s
* based on the IDL definitions. For example you could look at the directives say to build a more dynamic
* set of type resolvers and data fetchers.
*/
@PublicSpi
public interface WiringFactory {
/**
* This is called to ask if this factory can provide a type resolver for the interface
*
* @param environment the wiring environment
*
* @return true if the factory can give out a type resolver
*/
default boolean providesTypeResolver(InterfaceWiringEnvironment environment) {
return false;
}
/**
* Returns a {@link TypeResolver} given the type interface
*
* @param environment the wiring environment
*
* @return a {@link TypeResolver}
*/
default TypeResolver getTypeResolver(InterfaceWiringEnvironment environment) {
return assertShouldNeverHappen();
}
/**
* This is called to ask if this factory can provide a type resolver for the union
*
* @param environment the wiring environment
*
* @return true if the factory can give out a type resolver
*/
default boolean providesTypeResolver(UnionWiringEnvironment environment) {
return false;
}
/**
* Returns a {@link TypeResolver} given the type union
*
* @param environment the union wiring environment
*
* @return a {@link TypeResolver}
*/
default TypeResolver getTypeResolver(UnionWiringEnvironment environment) {
return assertShouldNeverHappen();
}
/**
* This is called to ask if this factory can provide a {@link graphql.schema.DataFetcherFactory} for the definition
*
* @param environment the wiring environment
*
* @return true if the factory can give out a data fetcher factory
*/
default boolean providesDataFetcherFactory(FieldWiringEnvironment environment) {
return false;
}
/**
* Returns a {@link graphql.schema.DataFetcherFactory} given the type definition
*
* @param environment the wiring environment
* @param <T> the type of the data fetcher
*
* @return a {@link graphql.schema.DataFetcherFactory}
*/
default <T> DataFetcherFactory<T> getDataFetcherFactory(FieldWiringEnvironment environment) {
return assertShouldNeverHappen();
}
/**
* This is called to ask if this factory can provide a data fetcher for the definition
*
* @param environment the wiring environment
*
* @return true if the factory can give out a data fetcher
*/
default boolean providesDataFetcher(FieldWiringEnvironment environment) {
return false;
}
/**
* Returns a {@link DataFetcher} given the type definition
*
* @param environment the wiring environment
*
* @return a {@link DataFetcher}
*/
default DataFetcher getDataFetcher(FieldWiringEnvironment environment) {
return assertShouldNeverHappen();
}
/**
* All fields need a data fetcher of some sort and this method is called to provide the data fetcher
* that will be used if no specific one has been provided
*
* @param environment the wiring environment
*
* @return a {@link DataFetcher}
*/
default DataFetcher getDefaultDataFetcher(FieldWiringEnvironment environment) {
return new PropertyDataFetcher(environment.getFieldDefinition().getName());
}
}