Added Self query to gql

gql_cataclysm
noah metz 2023-07-31 17:15:52 -06:00
parent 887a976263
commit d8355ab786
1 changed files with 19 additions and 0 deletions

@ -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{