1
1
package com .nfl .glitr ;
2
2
3
- import com .nfl .glitr .exception .GlitrException ;
4
3
import com .nfl .glitr .registry .TypeRegistry ;
5
4
import com .nfl .glitr .relay .RelayHelper ;
6
5
import com .nfl .glitr .util .ObjectMapper ;
7
6
import com .nfl .glitr .util .QueryComplexityCalculator ;
8
7
import graphql .schema .GraphQLObjectType ;
9
8
import graphql .schema .GraphQLSchema ;
9
+ import graphql .schema .visibility .GraphqlFieldVisibility ;
10
10
11
11
import javax .annotation .Nullable ;
12
12
@@ -22,11 +22,11 @@ public class Glitr {
22
22
private static ObjectMapper objectMapper ;
23
23
24
24
25
- public Glitr (TypeRegistry typeRegistry , Class queryRoot , @ Nullable ObjectMapper objectMapper , @ Nullable Class mutationRoot , @ Nullable QueryComplexityCalculator queryComplexityCalculator ) {
26
- this (typeRegistry , queryRoot , objectMapper , null , mutationRoot , queryComplexityCalculator );
25
+ public Glitr (TypeRegistry typeRegistry , Class queryRoot , @ Nullable GraphqlFieldVisibility fieldVisibility , @ Nullable ObjectMapper objectMapper , @ Nullable Class mutationRoot , @ Nullable QueryComplexityCalculator queryComplexityCalculator ) {
26
+ this (typeRegistry , queryRoot , fieldVisibility , objectMapper , null , mutationRoot , queryComplexityCalculator );
27
27
}
28
28
29
- public Glitr (TypeRegistry typeRegistry , Class queryRoot , @ Nullable ObjectMapper objectMapper , @ Nullable RelayHelper relayHelper , @ Nullable Class mutationRoot , @ Nullable QueryComplexityCalculator queryComplexityCalculator ) {
29
+ public Glitr (TypeRegistry typeRegistry , Class queryRoot , @ Nullable GraphqlFieldVisibility fieldVisibility , @ Nullable ObjectMapper objectMapper , @ Nullable RelayHelper relayHelper , @ Nullable Class mutationRoot , @ Nullable QueryComplexityCalculator queryComplexityCalculator ) {
30
30
assertNotNull (typeRegistry , "TypeRegistry can't be null" );
31
31
assertNotNull (queryRoot , "queryRoot class can't be null" );
32
32
this .typeRegistry = typeRegistry ;
@@ -37,7 +37,7 @@ public Glitr(TypeRegistry typeRegistry, Class queryRoot, @Nullable ObjectMapper
37
37
.withQueryComplexityExcludeNodes (typeRegistry .getQueryComplexityExcludeNodes ());
38
38
}
39
39
Glitr .objectMapper = objectMapper ;
40
- this .schema = buildSchema (queryRoot , mutationRoot );
40
+ this .schema = buildSchema (queryRoot , mutationRoot , fieldVisibility );
41
41
}
42
42
43
43
public TypeRegistry getTypeRegistry () {
@@ -65,22 +65,31 @@ public static ObjectMapper getObjectMapper() {
65
65
return objectMapper ;
66
66
}
67
67
68
- private GraphQLSchema buildSchema (Class queryRoot , Class mutationRoot ) {
68
+ private GraphQLSchema buildSchema (Class queryRoot , Class mutationRoot , GraphqlFieldVisibility fieldVisibility ) {
69
69
// create GraphQL Schema
70
70
GraphQLObjectType mutationType = null ;
71
71
if (mutationRoot != null ) {
72
72
mutationType = typeRegistry .createRelayMutationType (mutationRoot );
73
73
}
74
74
75
75
GraphQLObjectType queryType = (GraphQLObjectType ) typeRegistry .lookup (queryRoot );
76
+
77
+ if (fieldVisibility != null ) {
78
+ return GraphQLSchema .newSchema ()
79
+ .query (queryType )
80
+ .mutation (mutationType )
81
+ .fieldVisibility (fieldVisibility )
82
+ .build (typeRegistry .getTypeDictionary ());
83
+ }
84
+
76
85
return GraphQLSchema .newSchema ()
77
86
.query (queryType )
78
87
.mutation (mutationType )
79
88
.build (typeRegistry .getTypeDictionary ());
80
89
}
81
90
82
- public GraphQLSchema reloadSchema (Class queryRoot , Class mutationRoot ) {
83
- this .schema = buildSchema (queryRoot , mutationRoot );
91
+ public GraphQLSchema reloadSchema (Class queryRoot , Class mutationRoot , GraphqlFieldVisibility fieldVisibility ) {
92
+ this .schema = buildSchema (queryRoot , mutationRoot , fieldVisibility );
84
93
return this .schema ;
85
94
}
86
95
}
0 commit comments