From d8355ab78696cdf892d327cdf98c70edc48672c7 Mon Sep 17 00:00:00 2001 From: Noah Metz Date: Mon, 31 Jul 2023 17:15:52 -0600 Subject: [PATCH] Added Self query to gql --- gql.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/gql.go b/gql.go index 1d58ef3..6727c8c 100644 --- a/gql.go +++ b/gql.go @@ -898,6 +898,25 @@ func NewGQLExtContext() *GQLExtContext { panic(err) } + context.Query.AddFieldConfig("Self", &graphql.Field{ + Type: context.Interfaces["Node"].Interface, + Resolve: func(p graphql.ResolveParams) (interface{}, error) { + ctx, err := PrepResolve(p) + if err != nil { + return nil, err + } + + nodes, err := ResolveNodes(ctx, p, []NodeID{ctx.Server.ID}) + if err != nil { + return nil, err + } else if len(nodes) != 1 { + return nil, fmt.Errorf("wrong length of resolved nodes returned") + } + + return nodes[0], nil + }, + }) + context.Query.AddFieldConfig("Node", &graphql.Field{ Type: context.Interfaces["Node"].Interface, Args: graphql.FieldConfigArgument{