Skip to content

Commit c9a98c0

Browse files
committed
Add Subscribe function to make easier to create Subscription Handlers
1 parent 02caa89 commit c9a98c0

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

definition.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,7 @@ type Object struct {
339339
PrivateName string `json:"name"`
340340
PrivateDescription string `json:"description"`
341341
IsTypeOf IsTypeOfFn
342+
Subscribe SubscribeFn
342343

343344
typeConfig ObjectConfig
344345
initialisedFields bool
@@ -368,12 +369,15 @@ type IsTypeOfFn func(p IsTypeOfParams) bool
368369

369370
type InterfacesThunk func() []*Interface
370371

372+
type SubscribeFn func(p ResolveParams) error
373+
371374
type ObjectConfig struct {
372375
Name string `json:"name"`
373376
Interfaces interface{} `json:"interfaces"`
374377
Fields interface{} `json:"fields"`
375378
IsTypeOf IsTypeOfFn `json:"isTypeOf"`
376379
Description string `json:"description"`
380+
Subscribe SubscribeFn `json:"-"`
377381
}
378382

379383
type FieldsThunk func() Fields
@@ -396,6 +400,7 @@ func NewObject(config ObjectConfig) *Object {
396400
objectType.PrivateDescription = config.Description
397401
objectType.IsTypeOf = config.IsTypeOf
398402
objectType.typeConfig = config
403+
objectType.Subscribe = config.Subscribe
399404

400405
return objectType
401406
}
@@ -535,6 +540,7 @@ func defineFieldMap(ttype Named, fieldMap Fields) (FieldDefinitionMap, error) {
535540
Type: field.Type,
536541
Resolve: field.Resolve,
537542
DeprecationReason: field.DeprecationReason,
543+
Subscribe: field.Subscribe,
538544
}
539545

540546
fieldDef.Args = []*Argument{}
@@ -602,10 +608,11 @@ type ResolveInfo struct {
602608
type Fields map[string]*Field
603609

604610
type Field struct {
605-
Name string `json:"name"` // used by graphlql-relay
611+
Name string `json:"name"` // used by graphql-relay
606612
Type Output `json:"type"`
607613
Args FieldConfigArgument `json:"args"`
608614
Resolve FieldResolveFn `json:"-"`
615+
Subscribe SubscribeFn `json:"-"`
609616
DeprecationReason string `json:"deprecationReason"`
610617
Description string `json:"description"`
611618
}
@@ -625,6 +632,7 @@ type FieldDefinition struct {
625632
Type Output `json:"type"`
626633
Args []*Argument `json:"args"`
627634
Resolve FieldResolveFn `json:"-"`
635+
Subscribe SubscribeFn `json:"-"`
628636
DeprecationReason string `json:"deprecationReason"`
629637
}
630638

0 commit comments

Comments
 (0)