From 9485ef977208abb8d41d04681b5ca396d8019769 Mon Sep 17 00:00:00 2001 From: Noah Metz Date: Mon, 3 Jul 2023 18:58:15 -0600 Subject: [PATCH] Added self subscription --- gql_graph.go | 21 +++++++++++++++++++++ graph.go | 1 + 2 files changed, 22 insertions(+) diff --git a/gql_graph.go b/gql_graph.go index 2aa310f..80e1af6 100644 --- a/gql_graph.go +++ b/gql_graph.go @@ -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) { server, ok := p.Context.Value("gql_server").(*GQLThread) if ok == false { @@ -734,6 +740,21 @@ func GQLSubscribeFn(p graphql.ResolveParams, fn func(GraphSignal, graphql.Resolv 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 func GQLSubscriptionUpdate() * graphql.Field { if gql_subscription_update == nil { diff --git a/graph.go b/graph.go index 25a7f66..260aa24 100644 --- a/graph.go +++ b/graph.go @@ -95,6 +95,7 @@ func NewGQLContext(additional_types TypeList, extended_types ObjTypeMap, extende subscriptions := graphql.Fields{ "Update": GQLSubscriptionUpdate(), + "Self": GQLSubscriptionSelf(), } for key, val := range(extended_subscriptions) {