Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Subscribe function to make easier to create Subscription Handlers #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ type Object struct {
PrivateName string `json:"name"`
PrivateDescription string `json:"description"`
IsTypeOf IsTypeOfFn
Subscribe SubscribeFn

typeConfig ObjectConfig
initialisedFields bool
Expand Down Expand Up @@ -368,12 +369,15 @@ type IsTypeOfFn func(p IsTypeOfParams) bool

type InterfacesThunk func() []*Interface

type SubscribeFn func(p ResolveParams) error

type ObjectConfig struct {
Name string `json:"name"`
Interfaces interface{} `json:"interfaces"`
Fields interface{} `json:"fields"`
IsTypeOf IsTypeOfFn `json:"isTypeOf"`
Description string `json:"description"`
Subscribe SubscribeFn `json:"-"`
}

type FieldsThunk func() Fields
Expand All @@ -396,6 +400,7 @@ func NewObject(config ObjectConfig) *Object {
objectType.PrivateDescription = config.Description
objectType.IsTypeOf = config.IsTypeOf
objectType.typeConfig = config
objectType.Subscribe = config.Subscribe

return objectType
}
Expand Down Expand Up @@ -535,6 +540,7 @@ func defineFieldMap(ttype Named, fieldMap Fields) (FieldDefinitionMap, error) {
Type: field.Type,
Resolve: field.Resolve,
DeprecationReason: field.DeprecationReason,
Subscribe: field.Subscribe,
}

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

type Field struct {
Name string `json:"name"` // used by graphlql-relay
Name string `json:"name"` // used by graphql-relay
Type Output `json:"type"`
Args FieldConfigArgument `json:"args"`
Resolve FieldResolveFn `json:"-"`
Subscribe SubscribeFn `json:"-"`
DeprecationReason string `json:"deprecationReason"`
Description string `json:"description"`
}
Expand All @@ -625,6 +632,7 @@ type FieldDefinition struct {
Type Output `json:"type"`
Args []*Argument `json:"args"`
Resolve FieldResolveFn `json:"-"`
Subscribe SubscribeFn `json:"-"`
DeprecationReason string `json:"deprecationReason"`
}

Expand Down