Skip to content

Commit 62a54ad

Browse files
committed
expose applied directives on schema object
1 parent 937b0ca commit 62a54ad

File tree

1 file changed

+35
-33
lines changed

1 file changed

+35
-33
lines changed

schema.go

+35-33
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
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
1010
}
1111

1212
type TypeMap map[string]Type
@@ -16,31 +16,33 @@ type TypeMap map[string]Type
1616
// query, mutation (optional) and subscription (optional). A schema definition is then supplied to the
1717
// validator and executor.
1818
// 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+
//
2426
// Note: If an array of `directives` are provided to GraphQLSchema, that will be
2527
// the exact list of directives represented and allowed. If `directives` is not
2628
// provided then a default set of the specified directives (e.g. @include and
2729
// @skip) will be used. If you wish to provide *additional* directives to these
2830
// specified directives, you must explicitly declare them. Example:
2931
//
30-
// const MyAppSchema = new GraphQLSchema({
31-
// ...
32-
// directives: specifiedDirectives.concat([ myCustomDirective ]),
33-
// })
32+
// const MyAppSchema = new GraphQLSchema({
33+
// ...
34+
// directives: specifiedDirectives.concat([ myCustomDirective ]),
35+
// })
3436
type Schema struct {
35-
typeMap TypeMap
36-
directives []*Directive
37+
typeMap TypeMap
38+
directives []*Directive
39+
appliedDirectives []*AppliedDirective
3740

3841
queryType *Object
3942
mutationType *Object
4043
subscriptionType *Object
4144
implementations map[string][]*Object
4245
possibleTypeMap map[string]map[string]bool
43-
extensions []Extension
4446
}
4547

4648
func NewSchema(config SchemaConfig) (Schema, error) {
@@ -76,6 +78,8 @@ func NewSchema(config SchemaConfig) (Schema, error) {
7678
}
7779
}
7880

81+
schema.appliedDirectives = config.AppliedDirectives
82+
7983
// Build type map now to detect any errors within this schema.
8084
typeMap := TypeMap{}
8185
initialTypes := []Type{}
@@ -136,17 +140,11 @@ func NewSchema(config SchemaConfig) (Schema, error) {
136140
}
137141
}
138142
}
139-
140-
// Add extensions from config
141-
if len(config.Extensions) != 0 {
142-
schema.extensions = config.Extensions
143-
}
144-
145143
return schema, nil
146144
}
147145

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..
150148
func (gq *Schema) AddImplementation() error {
151149

152150
// Keep track of all implementations by interface name.
@@ -181,8 +179,8 @@ func (gq *Schema) AddImplementation() error {
181179
return nil
182180
}
183181

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
186184
func (gq *Schema) AppendType(objectType Type) error {
187185
if objectType.Error() != nil {
188186
return objectType.Error()
@@ -262,11 +260,6 @@ func (gq *Schema) IsPossibleType(abstractType Abstract, possibleType *Object) bo
262260
return false
263261
}
264262

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-
270263
// map-reduce
271264
func typeMapReducer(schema *Schema, typeMap TypeMap, objectType Type) (TypeMap, error) {
272265
var err error
@@ -543,3 +536,12 @@ func isTypeSubTypeOf(schema *Schema, maybeSubType Type, superType Type) bool {
543536
// Otherwise, the child type is not a valid subtype of the parent type.
544537
return false
545538
}
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

Comments
 (0)