Skip to content

Commit

Permalink
expose applied directives on schema object
Browse files Browse the repository at this point in the history
  • Loading branch information
dariuszkuc committed Oct 19, 2022
1 parent 937b0ca commit d6a745e
Showing 1 changed file with 36 additions and 21 deletions.
57 changes: 36 additions & 21 deletions schema.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package graphql

type SchemaConfig struct {
Query *Object
Mutation *Object
Subscription *Object
Types []Type
Directives []*Directive
Extensions []Extension
Query *Object
Mutation *Object
Subscription *Object
Types []Type
Directives []*Directive
AppliedDirectives []*AppliedDirective
Extensions []Extension
}

type TypeMap map[string]Type
Expand All @@ -16,24 +17,27 @@ type TypeMap map[string]Type
// query, mutation (optional) and subscription (optional). A schema definition is then supplied to the
// validator and executor.
// Example:
// myAppSchema, err := NewSchema(SchemaConfig({
// Query: MyAppQueryRootType,
// Mutation: MyAppMutationRootType,
// Subscription: MyAppSubscriptionRootType,
// });
//
// myAppSchema, err := NewSchema(SchemaConfig({
// Query: MyAppQueryRootType,
// Mutation: MyAppMutationRootType,
// Subscription: MyAppSubscriptionRootType,
// });
//
// Note: If an array of `directives` are provided to GraphQLSchema, that will be
// the exact list of directives represented and allowed. If `directives` is not
// provided then a default set of the specified directives (e.g. @include and
// @skip) will be used. If you wish to provide *additional* directives to these
// specified directives, you must explicitly declare them. Example:
//
// const MyAppSchema = new GraphQLSchema({
// ...
// directives: specifiedDirectives.concat([ myCustomDirective ]),
// })
// const MyAppSchema = new GraphQLSchema({
// ...
// directives: specifiedDirectives.concat([ myCustomDirective ]),
// })
type Schema struct {
typeMap TypeMap
directives []*Directive
typeMap TypeMap
directives []*Directive
appliedDirectives []*AppliedDirective

queryType *Object
mutationType *Object
Expand Down Expand Up @@ -76,6 +80,8 @@ func NewSchema(config SchemaConfig) (Schema, error) {
}
}

schema.appliedDirectives = config.AppliedDirectives

// Build type map now to detect any errors within this schema.
typeMap := TypeMap{}
initialTypes := []Type{}
Expand Down Expand Up @@ -145,8 +151,8 @@ func NewSchema(config SchemaConfig) (Schema, error) {
return schema, nil
}

//Added Check implementation of interfaces at runtime..
//Add Implementations at Runtime..
// Added Check implementation of interfaces at runtime..
// Add Implementations at Runtime..
func (gq *Schema) AddImplementation() error {

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

//Edited. To check add Types at RunTime..
//Append Runtime schema to typeMap
// Edited. To check add Types at RunTime..
// Append Runtime schema to typeMap
func (gq *Schema) AppendType(objectType Type) error {
if objectType.Error() != nil {
return objectType.Error()
Expand Down Expand Up @@ -543,3 +549,12 @@ func isTypeSubTypeOf(schema *Schema, maybeSubType Type, superType Type) bool {
// Otherwise, the child type is not a valid subtype of the parent type.
return false
}

func (gq *Schema) AppendAppliedDirective(appliedDirectiveType AppliedDirective) error {
gq.appliedDirectives = append(gq.appliedDirectives, &appliedDirectiveType)
return nil
}

func (gq *Schema) AppliedDirectives() []*AppliedDirective {
return gq.appliedDirectives
}

0 comments on commit d6a745e

Please sign in to comment.