Skip to content

Commit 0cd84ad

Browse files
committed
expose applied directives on schema object
1 parent 937b0ca commit 0cd84ad

File tree

1 file changed

+36
-21
lines changed

1 file changed

+36
-21
lines changed

schema.go

Lines changed: 36 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
package graphql
22

33
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+
Extensions []Extension
1011
}
1112

1213
type TypeMap map[string]Type
@@ -16,24 +17,27 @@ type TypeMap map[string]Type
1617
// query, mutation (optional) and subscription (optional). A schema definition is then supplied to the
1718
// validator and executor.
1819
// Example:
19-
// myAppSchema, err := NewSchema(SchemaConfig({
20-
// Query: MyAppQueryRootType,
21-
// Mutation: MyAppMutationRootType,
22-
// Subscription: MyAppSubscriptionRootType,
23-
// });
20+
//
21+
// myAppSchema, err := NewSchema(SchemaConfig({
22+
// Query: MyAppQueryRootType,
23+
// Mutation: MyAppMutationRootType,
24+
// Subscription: MyAppSubscriptionRootType,
25+
// });
26+
//
2427
// Note: If an array of `directives` are provided to GraphQLSchema, that will be
2528
// the exact list of directives represented and allowed. If `directives` is not
2629
// provided then a default set of the specified directives (e.g. @include and
2730
// @skip) will be used. If you wish to provide *additional* directives to these
2831
// specified directives, you must explicitly declare them. Example:
2932
//
30-
// const MyAppSchema = new GraphQLSchema({
31-
// ...
32-
// directives: specifiedDirectives.concat([ myCustomDirective ]),
33-
// })
33+
// const MyAppSchema = new GraphQLSchema({
34+
// ...
35+
// directives: specifiedDirectives.concat([ myCustomDirective ]),
36+
// })
3437
type Schema struct {
35-
typeMap TypeMap
36-
directives []*Directive
38+
typeMap TypeMap
39+
directives []*Directive
40+
appliedDirectives []*AppliedDirective
3741

3842
queryType *Object
3943
mutationType *Object
@@ -76,6 +80,8 @@ func NewSchema(config SchemaConfig) (Schema, error) {
7680
}
7781
}
7882

83+
schema.appliedDirectives = config.AppliedDirectives
84+
7985
// Build type map now to detect any errors within this schema.
8086
typeMap := TypeMap{}
8187
initialTypes := []Type{}
@@ -145,8 +151,8 @@ func NewSchema(config SchemaConfig) (Schema, error) {
145151
return schema, nil
146152
}
147153

148-
//Added Check implementation of interfaces at runtime..
149-
//Add Implementations at Runtime..
154+
// Added Check implementation of interfaces at runtime..
155+
// Add Implementations at Runtime..
150156
func (gq *Schema) AddImplementation() error {
151157

152158
// Keep track of all implementations by interface name.
@@ -181,8 +187,8 @@ func (gq *Schema) AddImplementation() error {
181187
return nil
182188
}
183189

184-
//Edited. To check add Types at RunTime..
185-
//Append Runtime schema to typeMap
190+
// Edited. To check add Types at RunTime..
191+
// Append Runtime schema to typeMap
186192
func (gq *Schema) AppendType(objectType Type) error {
187193
if objectType.Error() != nil {
188194
return objectType.Error()
@@ -543,3 +549,12 @@ func isTypeSubTypeOf(schema *Schema, maybeSubType Type, superType Type) bool {
543549
// Otherwise, the child type is not a valid subtype of the parent type.
544550
return false
545551
}
552+
553+
func (gq *Schema) AppendAppliedDirective(appliedDirectiveType AppliedDirective) error {
554+
gq.appliedDirectives = append(gq.appliedDirectives, &appliedDirectiveType)
555+
return nil
556+
}
557+
558+
func (gq *Schema) AppliedDirectives() []*AppliedDirective {
559+
return gq.appliedDirectives
560+
}

0 commit comments

Comments
 (0)