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 62a54ad
Showing 1 changed file with 35 additions and 33 deletions.
68 changes: 35 additions & 33 deletions schema.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
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
}

type TypeMap map[string]Type
Expand All @@ -16,31 +16,33 @@ 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
subscriptionType *Object
implementations map[string][]*Object
possibleTypeMap map[string]map[string]bool
extensions []Extension
}

func NewSchema(config SchemaConfig) (Schema, error) {
Expand Down Expand Up @@ -76,6 +78,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 @@ -136,17 +140,11 @@ func NewSchema(config SchemaConfig) (Schema, error) {
}
}
}

// Add extensions from config
if len(config.Extensions) != 0 {
schema.extensions = config.Extensions
}

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 +179,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 @@ -262,11 +260,6 @@ func (gq *Schema) IsPossibleType(abstractType Abstract, possibleType *Object) bo
return false
}

// AddExtensions can be used to add additional extensions to the schema
func (gq *Schema) AddExtensions(e ...Extension) {
gq.extensions = append(gq.extensions, e...)
}

// map-reduce
func typeMapReducer(schema *Schema, typeMap TypeMap, objectType Type) (TypeMap, error) {
var err error
Expand Down Expand Up @@ -543,3 +536,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 62a54ad

Please sign in to comment.