Added self subscription

graph-rework-2
noah metz 2023-07-03 18:58:15 -06:00
parent 53b93d5e70
commit 9485ef9772
2 changed files with 22 additions and 0 deletions

@ -704,6 +704,12 @@ func GQLSubscribeSignal(p graphql.ResolveParams) (interface{}, error) {
}) })
} }
func GQLSubscribeSelf(p graphql.ResolveParams) (interface{}, error) {
return GQLSubscribeFn(p, func(signal GraphSignal, p graphql.ResolveParams)(interface{}, error) {
return p.Source, nil
})
}
func GQLSubscribeFn(p graphql.ResolveParams, fn func(GraphSignal, graphql.ResolveParams)(interface{}, error))(interface{}, error) { func GQLSubscribeFn(p graphql.ResolveParams, fn func(GraphSignal, graphql.ResolveParams)(interface{}, error))(interface{}, error) {
server, ok := p.Context.Value("gql_server").(*GQLThread) server, ok := p.Context.Value("gql_server").(*GQLThread)
if ok == false { if ok == false {
@ -734,6 +740,21 @@ func GQLSubscribeFn(p graphql.ResolveParams, fn func(GraphSignal, graphql.Resolv
return c, nil return c, nil
} }
var gql_subscription_self * graphql.Field = nil
func GQLSubscriptionSelf() * graphql.Field {
if gql_subscription_self == nil {
gql_subscription_self = &graphql.Field{
Type: GQLTypeGQLThread(),
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
return p.Source, nil
},
Subscribe: GQLSubscribeSelf,
}
}
return gql_subscription_update
}
var gql_subscription_update * graphql.Field = nil var gql_subscription_update * graphql.Field = nil
func GQLSubscriptionUpdate() * graphql.Field { func GQLSubscriptionUpdate() * graphql.Field {
if gql_subscription_update == nil { if gql_subscription_update == nil {

@ -95,6 +95,7 @@ func NewGQLContext(additional_types TypeList, extended_types ObjTypeMap, extende
subscriptions := graphql.Fields{ subscriptions := graphql.Fields{
"Update": GQLSubscriptionUpdate(), "Update": GQLSubscriptionUpdate(),
"Self": GQLSubscriptionSelf(),
} }
for key, val := range(extended_subscriptions) { for key, val := range(extended_subscriptions) {