delete unused Params generic type from payload

This commit is contained in:
Laurent Le Houerou 2024-03-27 08:38:51 +04:00
parent 2f98cf2f2c
commit 026bd11ebc
4 changed files with 29 additions and 28 deletions

3
go.mod
View File

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

View File

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

View File

@ -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,
}
}

View File

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