From 026bd11ebcabd61b43b3ae7eb9e2070c3e5225c2 Mon Sep 17 00:00:00 2001 From: Laurent Le Houerou Date: Wed, 27 Mar 2024 08:38:51 +0400 Subject: [PATCH] delete unused Params generic type from payload --- go.mod | 3 ++- graphql/mutation.go | 2 +- graphql/payload.go | 50 ++++++++++++++++++++++----------------------- graphql/query.go | 2 +- 4 files changed, 29 insertions(+), 28 deletions(-) diff --git a/go.mod b/go.mod index fd7b1e4..164a258 100644 --- a/go.mod +++ b/go.mod @@ -15,6 +15,8 @@ require ( golang.org/x/time v0.5.0 ) +require golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect + require ( github.com/hashicorp/go-cleanhttp v0.5.2 // indirect github.com/klauspost/compress v1.16.7 // indirect @@ -22,6 +24,5 @@ require ( github.com/mattn/go-isatty v0.0.19 // indirect golang.org/x/net v0.21.0 // indirect golang.org/x/sys v0.18.0 // indirect - golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect nhooyr.io/websocket v1.8.7 // indirect ) diff --git a/graphql/mutation.go b/graphql/mutation.go index 8cd368a..f76ecd9 100644 --- a/graphql/mutation.go +++ b/graphql/mutation.go @@ -53,7 +53,7 @@ func (m *Mutation[Payload, Params]) Execute(ctx context.Context, params Params) } gqltype = fmt.Sprintf("%s(%s)", gqltype, strings.Join(keys, ",")) } - q := NewPayload[Payload, Params](gqltype) + q := NewPayload[Payload](gqltype) for k, v := range m.additionalQueryParams { paramsMap[k] = v } diff --git a/graphql/payload.go b/graphql/payload.go index ca3a718..d142088 100644 --- a/graphql/payload.go +++ b/graphql/payload.go @@ -1,10 +1,10 @@ package graphql -type Payload[T any, P any] struct { - OutermostLayer ContainerLayer[T, P] +type Payload[T any] struct { + OutermostLayer ContainerLayer[T] } -func (q *Payload[T, P]) GetValue() T { +func (q *Payload[T]) GetValue() T { if q.OutermostLayer == nil { var res T return res @@ -16,74 +16,74 @@ func (q *Payload[T, P]) GetValue() T { return layer.GetValue() } -func NewPayload[T any, P any](gqlType string, containerLayers ...string) *Payload[T, P] { +func NewPayload[T any](gqlType string, containerLayers ...string) *Payload[T] { if len(containerLayers) == 0 { - return &Payload[T, P]{ - OutermostLayer: NewWrapper[T, P](gqlType), + return &Payload[T]{ + OutermostLayer: NewWrapper[T](gqlType), } } - var buildLayer func(index int) ContainerLayer[T, P] - buildLayer = func(index int) ContainerLayer[T, P] { + var buildLayer func(index int) ContainerLayer[T] + buildLayer = func(index int) ContainerLayer[T] { if index == len(containerLayers) { - return NewWrapper[T, P](gqlType) + return NewWrapper[T](gqlType) } - return &NestedLayer[T, P]{ + return &NestedLayer[T]{ gqlType: containerLayers[index], InnerLayer: buildLayer(index + 1), } } - return &Payload[T, P]{OutermostLayer: buildLayer(0)} + return &Payload[T]{OutermostLayer: buildLayer(0)} } -type ContainerLayer[T any, P any] interface { - GetInnerLayer() ContainerLayer[T, P] +type ContainerLayer[T any] interface { + GetInnerLayer() ContainerLayer[T] GetValue() T GetGraphQLType() string } -type NestedLayer[T any, P any] struct { +type NestedLayer[T any] struct { gqlType string `graphql:"-"` - InnerLayer ContainerLayer[T, P] + InnerLayer ContainerLayer[T] } -func (nl *NestedLayer[T, P]) GetInnerLayer() ContainerLayer[T, P] { +func (nl *NestedLayer[T]) GetInnerLayer() ContainerLayer[T] { return nl.InnerLayer } -func (nl *NestedLayer[T, P]) GetValue() T { +func (nl *NestedLayer[T]) GetValue() T { var res T return res } -func (nl *NestedLayer[T, P]) GetGraphQLType() string { +func (nl *NestedLayer[T]) GetGraphQLType() string { return nl.gqlType } -type Wrapper[T any, P any] struct { +type Wrapper[T any] struct { gqlType string `graphql:"-"` Value T } -func (w Wrapper[T, P]) GetInnerLayer() ContainerLayer[T, P] { +func (w Wrapper[T]) GetInnerLayer() ContainerLayer[T] { return nil } -func (w Wrapper[T, P]) GetValue() T { +func (w Wrapper[T]) GetValue() T { return w.Value } -func (w Wrapper[T, P]) GetGraphQLWrapped() T { +func (w Wrapper[T]) GetGraphQLWrapped() T { return w.Value } -func (w Wrapper[T, P]) GetGraphQLType() string { +func (w Wrapper[T]) GetGraphQLType() string { return w.gqlType } -func NewWrapper[T any, P any](gqlType string) *Wrapper[T, P] { - return &Wrapper[T, P]{ +func NewWrapper[T any](gqlType string) *Wrapper[T] { + return &Wrapper[T]{ gqlType: gqlType, } } diff --git a/graphql/query.go b/graphql/query.go index 1d5cc77..63fe3e5 100644 --- a/graphql/query.go +++ b/graphql/query.go @@ -65,7 +65,7 @@ func (r *Query[ReturnType, Params]) Get(ctx context.Context, params Params) (Ret for k, v := range r.additionalQueryParams { paramsMap[k] = v } - q := NewPayload[ReturnType, Params](gqltype, r.containerLayers...) + q := NewPayload[ReturnType](gqltype, r.containerLayers...) err := r.c.Query(ctx, q, paramsMap) if err != nil { var res ReturnType