From 251b052cbdfaeac9f600e3da7f66ea23303e309c Mon Sep 17 00:00:00 2001 From: xufeixiang Date: Fri, 1 Nov 2024 17:32:00 +0800 Subject: [PATCH] feat: upgrade graphql-go-tools with add directive asyncResolve for array node. --- go.mod | 4 +- go.sum | 4 +- .../directives/selection_asyncresolve.go | 39 +++++++++++++++++++ wundergraphGitSubmodule | 2 +- 4 files changed, 44 insertions(+), 5 deletions(-) create mode 100644 pkg/engine/directives/selection_asyncresolve.go diff --git a/go.mod b/go.mod index 62690d8..5942f3b 100644 --- a/go.mod +++ b/go.mod @@ -10,6 +10,7 @@ require ( github.com/getkin/kin-openapi v0.120.0 github.com/ghodss/yaml v1.0.0 github.com/go-openapi/jsonpointer v0.19.6 + github.com/goccy/go-json v0.10.2 github.com/google/uuid v1.3.0 github.com/gorilla/websocket v1.5.0 github.com/invopop/jsonschema v0.7.0 @@ -65,7 +66,6 @@ require ( github.com/go-openapi/swag v0.22.4 // indirect github.com/go-redis/cache/v8 v8.4.1 // indirect github.com/go-redis/redis/v8 v8.11.5 // indirect - github.com/goccy/go-json v0.10.2 // indirect github.com/gofrs/flock v0.8.1 // indirect github.com/golang-jwt/jwt v3.2.2+incompatible // indirect github.com/golang-jwt/jwt/v4 v4.4.2 // indirect @@ -168,6 +168,6 @@ replace ( github.com/flowchartsman/handlebars/v3 => github.com/fireboomio/handlebars/v3 v3.0.0-20230407011829-1693185f0572 github.com/getkin/kin-openapi => github.com/fireboomio/kin-openapi v0.0.0-20240110095352-e1b4433e41a8 github.com/prisma/prisma-client-go => github.com/fireboomio/prisma-client-go v0.0.0-20240614073744-961bb930abe4 - github.com/wundergraph/graphql-go-tools => github.com/fireboomio/graphql-go-tools v0.0.0-20240906084833-9d754bc747d6 + github.com/wundergraph/graphql-go-tools => github.com/fireboomio/graphql-go-tools v0.0.0-20241101081953-5de6406c15e8 github.com/wundergraph/wundergraph => ./wundergraphGitSubmodule ) diff --git a/go.sum b/go.sum index a8f7110..c9e0840 100644 --- a/go.sum +++ b/go.sum @@ -136,8 +136,8 @@ github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w= github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk= github.com/fatih/structs v1.1.0 h1:Q7juDM0QtcnhCpeyLGQKyg4TOIghuNXrkL32pHAUMxo= github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M= -github.com/fireboomio/graphql-go-tools v0.0.0-20240906084833-9d754bc747d6 h1:iKfU4DWaY7t2V3rM3gqkkgdLdZCeXWYLPIxfkpc5KTg= -github.com/fireboomio/graphql-go-tools v0.0.0-20240906084833-9d754bc747d6/go.mod h1:8Lj3WnDT5m+QGamBlqAqwn++OVcL30FXG+o6kf810bc= +github.com/fireboomio/graphql-go-tools v0.0.0-20241101081953-5de6406c15e8 h1:I7vFAEPdwl9USq5KvSwosrilSjLS9BG36InZdHOqU/I= +github.com/fireboomio/graphql-go-tools v0.0.0-20241101081953-5de6406c15e8/go.mod h1:8Lj3WnDT5m+QGamBlqAqwn++OVcL30FXG+o6kf810bc= github.com/fireboomio/handlebars/v3 v3.0.0-20230407011829-1693185f0572 h1:utP3HLcMr38qlFFzMwjQeUWM0jxg+MPgktKucOQ2t4I= github.com/fireboomio/handlebars/v3 v3.0.0-20230407011829-1693185f0572/go.mod h1:zdeQ3Qna7Bd2JQiobPXuZKDOG3j7Byo6uXDaMLXHVAw= github.com/fireboomio/kin-openapi v0.0.0-20240110095352-e1b4433e41a8 h1:KaancvImcVJEnUVUxDwugkP6F7Yvb2FgasDuVkknZeU= diff --git a/pkg/engine/directives/selection_asyncresolve.go b/pkg/engine/directives/selection_asyncresolve.go new file mode 100644 index 0000000..178dcaf --- /dev/null +++ b/pkg/engine/directives/selection_asyncresolve.go @@ -0,0 +1,39 @@ +// Package directives +/* + 实现VariableDirective接口,只能定义在LocationVariableDefinition上 + Resolve 标识参数内部传递,与@export组合使用 +*/ +package directives + +import ( + "fmt" + "github.com/getkin/kin-openapi/openapi3" + "github.com/vektah/gqlparser/v2/ast" +) + +const asyncResolveName = "asyncResolve" + +type asyncResolve struct{} + +func (s *asyncResolve) Directive() *ast.DirectiveDefinition { + return &ast.DirectiveDefinition{ + Name: asyncResolveName, + Locations: []ast.DirectiveLocation{ast.LocationField}, + } +} + +func (s *asyncResolve) Definitions() ast.DefinitionList { + return nil +} + +func (s *asyncResolve) Resolve(resolver *SelectionResolver) (err error) { + if resolver.Schema.Value.Type != openapi3.TypeArray { + err = fmt.Errorf("@%s directive only support on array type", asyncResolveName) + return + } + return +} + +func init() { + registerDirective(asyncResolveName, &asyncResolve{}) +} diff --git a/wundergraphGitSubmodule b/wundergraphGitSubmodule index ac2e797..0941dc2 160000 --- a/wundergraphGitSubmodule +++ b/wundergraphGitSubmodule @@ -1 +1 @@ -Subproject commit ac2e79742b4651825c11a301e395857d9a9152d0 +Subproject commit 0941dc2216dfad39f7972987d28b35db355d879f