1
1
package graphql
2
2
3
3
type SchemaConfig struct {
4
- Query * Object
5
- Mutation * Object
6
- Subscription * Object
7
- Types []Type
8
- Directives []* Directive
9
- Extensions [] Extension
4
+ Query * Object
5
+ Mutation * Object
6
+ Subscription * Object
7
+ Types []Type
8
+ Directives []* Directive
9
+ AppliedDirectives [] * AppliedDirective
10
10
}
11
11
12
12
type TypeMap map [string ]Type
@@ -16,31 +16,33 @@ type TypeMap map[string]Type
16
16
// query, mutation (optional) and subscription (optional). A schema definition is then supplied to the
17
17
// validator and executor.
18
18
// Example:
19
- // myAppSchema, err := NewSchema(SchemaConfig({
20
- // Query: MyAppQueryRootType,
21
- // Mutation: MyAppMutationRootType,
22
- // Subscription: MyAppSubscriptionRootType,
23
- // });
19
+ //
20
+ // myAppSchema, err := NewSchema(SchemaConfig({
21
+ // Query: MyAppQueryRootType,
22
+ // Mutation: MyAppMutationRootType,
23
+ // Subscription: MyAppSubscriptionRootType,
24
+ // });
25
+ //
24
26
// Note: If an array of `directives` are provided to GraphQLSchema, that will be
25
27
// the exact list of directives represented and allowed. If `directives` is not
26
28
// provided then a default set of the specified directives (e.g. @include and
27
29
// @skip) will be used. If you wish to provide *additional* directives to these
28
30
// specified directives, you must explicitly declare them. Example:
29
31
//
30
- // const MyAppSchema = new GraphQLSchema({
31
- // ...
32
- // directives: specifiedDirectives.concat([ myCustomDirective ]),
33
- // })
32
+ // const MyAppSchema = new GraphQLSchema({
33
+ // ...
34
+ // directives: specifiedDirectives.concat([ myCustomDirective ]),
35
+ // })
34
36
type Schema struct {
35
- typeMap TypeMap
36
- directives []* Directive
37
+ typeMap TypeMap
38
+ directives []* Directive
39
+ appliedDirectives []* AppliedDirective
37
40
38
41
queryType * Object
39
42
mutationType * Object
40
43
subscriptionType * Object
41
44
implementations map [string ][]* Object
42
45
possibleTypeMap map [string ]map [string ]bool
43
- extensions []Extension
44
46
}
45
47
46
48
func NewSchema (config SchemaConfig ) (Schema , error ) {
@@ -76,6 +78,8 @@ func NewSchema(config SchemaConfig) (Schema, error) {
76
78
}
77
79
}
78
80
81
+ schema .appliedDirectives = config .AppliedDirectives
82
+
79
83
// Build type map now to detect any errors within this schema.
80
84
typeMap := TypeMap {}
81
85
initialTypes := []Type {}
@@ -136,17 +140,11 @@ func NewSchema(config SchemaConfig) (Schema, error) {
136
140
}
137
141
}
138
142
}
139
-
140
- // Add extensions from config
141
- if len (config .Extensions ) != 0 {
142
- schema .extensions = config .Extensions
143
- }
144
-
145
143
return schema , nil
146
144
}
147
145
148
- //Added Check implementation of interfaces at runtime..
149
- //Add Implementations at Runtime..
146
+ // Added Check implementation of interfaces at runtime..
147
+ // Add Implementations at Runtime..
150
148
func (gq * Schema ) AddImplementation () error {
151
149
152
150
// Keep track of all implementations by interface name.
@@ -181,8 +179,8 @@ func (gq *Schema) AddImplementation() error {
181
179
return nil
182
180
}
183
181
184
- //Edited. To check add Types at RunTime..
185
- //Append Runtime schema to typeMap
182
+ // Edited. To check add Types at RunTime..
183
+ // Append Runtime schema to typeMap
186
184
func (gq * Schema ) AppendType (objectType Type ) error {
187
185
if objectType .Error () != nil {
188
186
return objectType .Error ()
@@ -262,11 +260,6 @@ func (gq *Schema) IsPossibleType(abstractType Abstract, possibleType *Object) bo
262
260
return false
263
261
}
264
262
265
- // AddExtensions can be used to add additional extensions to the schema
266
- func (gq * Schema ) AddExtensions (e ... Extension ) {
267
- gq .extensions = append (gq .extensions , e ... )
268
- }
269
-
270
263
// map-reduce
271
264
func typeMapReducer (schema * Schema , typeMap TypeMap , objectType Type ) (TypeMap , error ) {
272
265
var err error
@@ -543,3 +536,12 @@ func isTypeSubTypeOf(schema *Schema, maybeSubType Type, superType Type) bool {
543
536
// Otherwise, the child type is not a valid subtype of the parent type.
544
537
return false
545
538
}
539
+
540
+ func (gq * Schema ) AppendAppliedDirective (appliedDirectiveType AppliedDirective ) error {
541
+ gq .appliedDirectives = append (gq .appliedDirectives , & appliedDirectiveType )
542
+ return nil
543
+ }
544
+
545
+ func (gq * Schema ) AppliedDirectives () []* AppliedDirective {
546
+ return gq .appliedDirectives
547
+ }
0 commit comments