From 0cd84ad8cb5a619dd32e41b3936db12a01f354a6 Mon Sep 17 00:00:00 2001 From: dariuszkuc <9501705+dariuszkuc@users.noreply.github.com> Date: Wed, 19 Oct 2022 11:42:18 -0500 Subject: [PATCH] expose applied directives on schema object --- schema.go | 57 +++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 36 insertions(+), 21 deletions(-) diff --git a/schema.go b/schema.go index 35519ac4..821438cf 100644 --- a/schema.go +++ b/schema.go @@ -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 @@ -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 @@ -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{} @@ -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. @@ -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() @@ -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 +}