Skip to content

Commit 5ad4dc1

Browse files
committed
Add extensions to schema
1 parent 228dbb5 commit 5ad4dc1

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

schema.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ type SchemaConfig struct {
1010
Subscription *Object
1111
Types []Type
1212
Directives []*Directive
13+
Extensions []Extension
1314
}
1415

1516
type TypeMap map[string]Type
@@ -43,6 +44,7 @@ type Schema struct {
4344
subscriptionType *Object
4445
implementations map[string][]*Object
4546
possibleTypeMap map[string]map[string]bool
47+
extensions []Extension
4648
}
4749

4850
func NewSchema(config SchemaConfig) (Schema, error) {
@@ -139,6 +141,11 @@ func NewSchema(config SchemaConfig) (Schema, error) {
139141
}
140142
}
141143

144+
// Add extensions from config
145+
if len(config.Extensions) != 0 {
146+
schema.extensions = config.Extensions
147+
}
148+
142149
return schema, nil
143150
}
144151

@@ -259,6 +266,11 @@ func (gq *Schema) IsPossibleType(abstractType Abstract, possibleType *Object) bo
259266
return false
260267
}
261268

269+
// AddExtensions can be used to add additional extensions to the schema
270+
func (gq *Schema) AddExtensions(e ...Extension) {
271+
gq.extensions = append(gq.extensions, e...)
272+
}
273+
262274
// map-reduce
263275
func typeMapReducer(schema *Schema, typeMap TypeMap, objectType Type) (TypeMap, error) {
264276
var err error

0 commit comments

Comments
 (0)