From c9ab0678beb326dedc3cdd0e9bce0bde9b0812fa Mon Sep 17 00:00:00 2001 From: Sacha Al Himdani Date: Thu, 7 Aug 2025 18:34:26 +0200 Subject: [PATCH] Fix types generation Signed-off-by: Sacha Al Himdani --- pkg/server/api/console/v1/gqlgen.yaml | 4 +-- pkg/server/api/console/v1/schema/schema.go | 18 ++++++----- pkg/server/api/console/v1/types/cursorkey.go | 23 ++------------ pkg/server/api/console/v1/types/gid.go | 22 -------------- pkg/server/api/console/v1/types/pageinfo.go | 4 +-- pkg/server/api/trust/v1/gqlgen.yaml | 4 +-- pkg/server/api/trust/v1/schema/schema.go | 14 +++++---- pkg/server/api/trust/v1/types/cursorkey.go | 23 ++------------ pkg/server/api/trust/v1/types/gid.go | 22 -------------- pkg/server/api/trust/v1/types/pageinfo.go | 4 +-- .../types/cursor}/cursorkey.go | 30 ++++++++++++++++++- .../{api/types => graphql/types/gid}/gid.go | 4 ++- .../types/pageinfo}/pageinfo.go | 11 +++---- 13 files changed, 66 insertions(+), 117 deletions(-) delete mode 100644 pkg/server/api/console/v1/types/gid.go delete mode 100644 pkg/server/api/trust/v1/types/gid.go rename pkg/server/{api/types => graphql/types/cursor}/cursorkey.go (72%) rename pkg/server/{api/types => graphql/types/gid}/gid.go (97%) rename pkg/server/{api/types => graphql/types/pageinfo}/pageinfo.go (78%) diff --git a/pkg/server/api/console/v1/gqlgen.yaml b/pkg/server/api/console/v1/gqlgen.yaml index 5b20ca694..b1a295bbf 100644 --- a/pkg/server/api/console/v1/gqlgen.yaml +++ b/pkg/server/api/console/v1/gqlgen.yaml @@ -20,13 +20,13 @@ call_argument_directives_with_null: true models: ID: model: - - "github.com/getprobo/probo/pkg/server/api/console/v1/types.GIDScalar" + - "github.com/getprobo/probo/pkg/server/graphql/types/gid.GIDScalar" Datetime: model: - "github.com/99designs/gqlgen/graphql.Time" CursorKey: model: - - "github.com/getprobo/probo/pkg/server/api/console/v1/types.CursorKeyScalar" + - "github.com/getprobo/probo/pkg/server/graphql/types/cursor.CursorKeyScalar" Duration: model: - "github.com/99designs/gqlgen/graphql.Duration" diff --git a/pkg/server/api/console/v1/schema/schema.go b/pkg/server/api/console/v1/schema/schema.go index ed46549fe..1bda67736 100644 --- a/pkg/server/api/console/v1/schema/schema.go +++ b/pkg/server/api/console/v1/schema/schema.go @@ -18,6 +18,8 @@ import ( "github.com/getprobo/probo/pkg/gid" "github.com/getprobo/probo/pkg/page" "github.com/getprobo/probo/pkg/server/api/console/v1/types" + "github.com/getprobo/probo/pkg/server/graphql/types/cursor" + gid1 "github.com/getprobo/probo/pkg/server/graphql/types/gid" gqlparser "github.com/vektah/gqlparser/v2" "github.com/vektah/gqlparser/v2/ast" ) @@ -58548,13 +58550,13 @@ var ( ) func (ec *executionContext) unmarshalNCursorKey2githubᚗcomᚋgetproboᚋproboᚋpkgᚋpageᚐCursorKey(ctx context.Context, v any) (page.CursorKey, error) { - res, err := types.UnmarshalCursorKeyScalar(v) + res, err := cursor.UnmarshalCursorKeyScalar(v) return res, graphql.ErrorOnPath(ctx, err) } func (ec *executionContext) marshalNCursorKey2githubᚗcomᚋgetproboᚋproboᚋpkgᚋpageᚐCursorKey(ctx context.Context, sel ast.SelectionSet, v page.CursorKey) graphql.Marshaler { _ = sel - res := types.MarshalCursorKeyScalar(v) + res := cursor.MarshalCursorKeyScalar(v) if res == graphql.Null { if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) { ec.Errorf(ctx, "the requested element is null which the schema does not allow") @@ -59864,13 +59866,13 @@ func (ec *executionContext) marshalNGenerateFrameworkStateOfApplicabilityPayload } func (ec *executionContext) unmarshalNID2githubᚗcomᚋgetproboᚋproboᚋpkgᚋgidᚐGID(ctx context.Context, v any) (gid.GID, error) { - res, err := types.UnmarshalGIDScalar(v) + res, err := gid1.UnmarshalGIDScalar(v) return res, graphql.ErrorOnPath(ctx, err) } func (ec *executionContext) marshalNID2githubᚗcomᚋgetproboᚋproboᚋpkgᚋgidᚐGID(ctx context.Context, sel ast.SelectionSet, v gid.GID) graphql.Marshaler { _ = sel - res := types.MarshalGIDScalar(v) + res := gid1.MarshalGIDScalar(v) if res == graphql.Null { if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) { ec.Errorf(ctx, "the requested element is null which the schema does not allow") @@ -62366,7 +62368,7 @@ func (ec *executionContext) unmarshalOCursorKey2ᚖgithubᚗcomᚋgetproboᚋpro if v == nil { return nil, nil } - res, err := types.UnmarshalCursorKeyScalar(v) + res, err := cursor.UnmarshalCursorKeyScalar(v) return &res, graphql.ErrorOnPath(ctx, err) } @@ -62376,7 +62378,7 @@ func (ec *executionContext) marshalOCursorKey2ᚖgithubᚗcomᚋgetproboᚋprobo } _ = sel _ = ctx - res := types.MarshalCursorKeyScalar(*v) + res := cursor.MarshalCursorKeyScalar(*v) return res } @@ -62616,7 +62618,7 @@ func (ec *executionContext) unmarshalOID2ᚖgithubᚗcomᚋgetproboᚋproboᚋpk if v == nil { return nil, nil } - res, err := types.UnmarshalGIDScalar(v) + res, err := gid1.UnmarshalGIDScalar(v) return &res, graphql.ErrorOnPath(ctx, err) } @@ -62626,7 +62628,7 @@ func (ec *executionContext) marshalOID2ᚖgithubᚗcomᚋgetproboᚋproboᚋpkg } _ = sel _ = ctx - res := types.MarshalGIDScalar(*v) + res := gid1.MarshalGIDScalar(*v) return res } diff --git a/pkg/server/api/console/v1/types/cursorkey.go b/pkg/server/api/console/v1/types/cursorkey.go index e7b1911b5..c7d226dc7 100644 --- a/pkg/server/api/console/v1/types/cursorkey.go +++ b/pkg/server/api/console/v1/types/cursorkey.go @@ -16,7 +16,7 @@ package types import ( "github.com/getprobo/probo/pkg/page" - sharedTypes "github.com/getprobo/probo/pkg/server/api/types" + "github.com/getprobo/probo/pkg/server/graphql/types/cursor" ) func NewCursor[O page.OrderField]( @@ -26,24 +26,5 @@ func NewCursor[O page.OrderField]( before *page.CursorKey, orderBy page.OrderBy[O], ) *page.Cursor[O] { - var ( - size int - from *page.CursorKey - direction = page.Head - ) - - if first != nil { - size = *first - direction = page.Head - from = after - } else if last != nil { - size = *last - direction = page.Tail - from = before - } - - return page.NewCursor(size, from, direction, orderBy) + return cursor.NewCursor(first, after, last, before, orderBy) } - -var MarshalCursorKeyScalar = sharedTypes.MarshalCursorKeyScalar -var UnmarshalCursorKeyScalar = sharedTypes.UnmarshalCursorKeyScalar diff --git a/pkg/server/api/console/v1/types/gid.go b/pkg/server/api/console/v1/types/gid.go deleted file mode 100644 index 90a62b18c..000000000 --- a/pkg/server/api/console/v1/types/gid.go +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright (c) 2025 Probo Inc . -// -// Permission to use, copy, modify, and/or distribute this software for any -// purpose with or without fee is hereby granted, provided that the above -// copyright notice and this permission notice appear in all copies. -// -// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH -// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY -// AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, -// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM -// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR -// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR -// PERFORMANCE OF THIS SOFTWARE. - -package types - -import ( - sharedTypes "github.com/getprobo/probo/pkg/server/api/types" -) - -var MarshalGIDScalar = sharedTypes.MarshalGIDScalar -var UnmarshalGIDScalar = sharedTypes.UnmarshalGIDScalar diff --git a/pkg/server/api/console/v1/types/pageinfo.go b/pkg/server/api/console/v1/types/pageinfo.go index fce0bb517..6d62e455c 100644 --- a/pkg/server/api/console/v1/types/pageinfo.go +++ b/pkg/server/api/console/v1/types/pageinfo.go @@ -16,11 +16,11 @@ package types import ( "github.com/getprobo/probo/pkg/page" - sharedTypes "github.com/getprobo/probo/pkg/server/api/types" + "github.com/getprobo/probo/pkg/server/graphql/types/pageinfo" ) func NewPageInfo[T page.Paginable[O], O page.OrderField](p *page.Page[T, O]) *PageInfo { - data := sharedTypes.NewPageInfoData(p) + data := pageinfo.NewPageInfo(p) return &PageInfo{ HasNextPage: data.HasNextPage, HasPreviousPage: data.HasPreviousPage, diff --git a/pkg/server/api/trust/v1/gqlgen.yaml b/pkg/server/api/trust/v1/gqlgen.yaml index c31e646ee..9382dd6ba 100644 --- a/pkg/server/api/trust/v1/gqlgen.yaml +++ b/pkg/server/api/trust/v1/gqlgen.yaml @@ -20,10 +20,10 @@ call_argument_directives_with_null: true models: ID: model: - - "github.com/getprobo/probo/pkg/server/api/trust/v1/types.GIDScalar" + - "github.com/getprobo/probo/pkg/server/graphql/types/gid.GIDScalar" Datetime: model: - "github.com/99designs/gqlgen/graphql.Time" CursorKey: model: - - "github.com/getprobo/probo/pkg/server/api/trust/v1/types.CursorKeyScalar" + - "github.com/getprobo/probo/pkg/server/graphql/types/cursor.CursorKeyScalar" diff --git a/pkg/server/api/trust/v1/schema/schema.go b/pkg/server/api/trust/v1/schema/schema.go index 36e728dd8..77c711f3b 100644 --- a/pkg/server/api/trust/v1/schema/schema.go +++ b/pkg/server/api/trust/v1/schema/schema.go @@ -17,6 +17,8 @@ import ( "github.com/getprobo/probo/pkg/gid" "github.com/getprobo/probo/pkg/page" "github.com/getprobo/probo/pkg/server/api/trust/v1/types" + "github.com/getprobo/probo/pkg/server/graphql/types/cursor" + gid1 "github.com/getprobo/probo/pkg/server/graphql/types/gid" gqlparser "github.com/vektah/gqlparser/v2" "github.com/vektah/gqlparser/v2/ast" ) @@ -7333,13 +7335,13 @@ func (ec *executionContext) marshalNBoolean2bool(ctx context.Context, sel ast.Se } func (ec *executionContext) unmarshalNCursorKey2githubᚗcomᚋgetproboᚋproboᚋpkgᚋpageᚐCursorKey(ctx context.Context, v any) (page.CursorKey, error) { - res, err := types.UnmarshalCursorKeyScalar(v) + res, err := cursor.UnmarshalCursorKeyScalar(v) return res, graphql.ErrorOnPath(ctx, err) } func (ec *executionContext) marshalNCursorKey2githubᚗcomᚋgetproboᚋproboᚋpkgᚋpageᚐCursorKey(ctx context.Context, sel ast.SelectionSet, v page.CursorKey) graphql.Marshaler { _ = sel - res := types.MarshalCursorKeyScalar(v) + res := cursor.MarshalCursorKeyScalar(v) if res == graphql.Null { if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) { ec.Errorf(ctx, "the requested element is null which the schema does not allow") @@ -7490,13 +7492,13 @@ func (ec *executionContext) marshalNFramework2ᚖgithubᚗcomᚋgetproboᚋprobo } func (ec *executionContext) unmarshalNID2githubᚗcomᚋgetproboᚋproboᚋpkgᚋgidᚐGID(ctx context.Context, v any) (gid.GID, error) { - res, err := types.UnmarshalGIDScalar(v) + res, err := gid1.UnmarshalGIDScalar(v) return res, graphql.ErrorOnPath(ctx, err) } func (ec *executionContext) marshalNID2githubᚗcomᚋgetproboᚋproboᚋpkgᚋgidᚐGID(ctx context.Context, sel ast.SelectionSet, v gid.GID) graphql.Marshaler { _ = sel - res := types.MarshalGIDScalar(v) + res := gid1.MarshalGIDScalar(v) if res == graphql.Null { if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) { ec.Errorf(ctx, "the requested element is null which the schema does not allow") @@ -7978,7 +7980,7 @@ func (ec *executionContext) unmarshalOCursorKey2ᚖgithubᚗcomᚋgetproboᚋpro if v == nil { return nil, nil } - res, err := types.UnmarshalCursorKeyScalar(v) + res, err := cursor.UnmarshalCursorKeyScalar(v) return &res, graphql.ErrorOnPath(ctx, err) } @@ -7988,7 +7990,7 @@ func (ec *executionContext) marshalOCursorKey2ᚖgithubᚗcomᚋgetproboᚋprobo } _ = sel _ = ctx - res := types.MarshalCursorKeyScalar(*v) + res := cursor.MarshalCursorKeyScalar(*v) return res } diff --git a/pkg/server/api/trust/v1/types/cursorkey.go b/pkg/server/api/trust/v1/types/cursorkey.go index e7b1911b5..c7d226dc7 100644 --- a/pkg/server/api/trust/v1/types/cursorkey.go +++ b/pkg/server/api/trust/v1/types/cursorkey.go @@ -16,7 +16,7 @@ package types import ( "github.com/getprobo/probo/pkg/page" - sharedTypes "github.com/getprobo/probo/pkg/server/api/types" + "github.com/getprobo/probo/pkg/server/graphql/types/cursor" ) func NewCursor[O page.OrderField]( @@ -26,24 +26,5 @@ func NewCursor[O page.OrderField]( before *page.CursorKey, orderBy page.OrderBy[O], ) *page.Cursor[O] { - var ( - size int - from *page.CursorKey - direction = page.Head - ) - - if first != nil { - size = *first - direction = page.Head - from = after - } else if last != nil { - size = *last - direction = page.Tail - from = before - } - - return page.NewCursor(size, from, direction, orderBy) + return cursor.NewCursor(first, after, last, before, orderBy) } - -var MarshalCursorKeyScalar = sharedTypes.MarshalCursorKeyScalar -var UnmarshalCursorKeyScalar = sharedTypes.UnmarshalCursorKeyScalar diff --git a/pkg/server/api/trust/v1/types/gid.go b/pkg/server/api/trust/v1/types/gid.go deleted file mode 100644 index 90a62b18c..000000000 --- a/pkg/server/api/trust/v1/types/gid.go +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright (c) 2025 Probo Inc . -// -// Permission to use, copy, modify, and/or distribute this software for any -// purpose with or without fee is hereby granted, provided that the above -// copyright notice and this permission notice appear in all copies. -// -// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH -// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY -// AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, -// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM -// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR -// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR -// PERFORMANCE OF THIS SOFTWARE. - -package types - -import ( - sharedTypes "github.com/getprobo/probo/pkg/server/api/types" -) - -var MarshalGIDScalar = sharedTypes.MarshalGIDScalar -var UnmarshalGIDScalar = sharedTypes.UnmarshalGIDScalar diff --git a/pkg/server/api/trust/v1/types/pageinfo.go b/pkg/server/api/trust/v1/types/pageinfo.go index fce0bb517..6d62e455c 100644 --- a/pkg/server/api/trust/v1/types/pageinfo.go +++ b/pkg/server/api/trust/v1/types/pageinfo.go @@ -16,11 +16,11 @@ package types import ( "github.com/getprobo/probo/pkg/page" - sharedTypes "github.com/getprobo/probo/pkg/server/api/types" + "github.com/getprobo/probo/pkg/server/graphql/types/pageinfo" ) func NewPageInfo[T page.Paginable[O], O page.OrderField](p *page.Page[T, O]) *PageInfo { - data := sharedTypes.NewPageInfoData(p) + data := pageinfo.NewPageInfo(p) return &PageInfo{ HasNextPage: data.HasNextPage, HasPreviousPage: data.HasPreviousPage, diff --git a/pkg/server/api/types/cursorkey.go b/pkg/server/graphql/types/cursor/cursorkey.go similarity index 72% rename from pkg/server/api/types/cursorkey.go rename to pkg/server/graphql/types/cursor/cursorkey.go index 7aecddfda..d385451ae 100644 --- a/pkg/server/api/types/cursorkey.go +++ b/pkg/server/graphql/types/cursor/cursorkey.go @@ -12,7 +12,7 @@ // OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR // PERFORMANCE OF THIS SOFTWARE. -package types +package cursor import ( "errors" @@ -23,6 +23,34 @@ import ( "github.com/getprobo/probo/pkg/page" ) +type CursorKeyScalar = page.CursorKey + +func NewCursor[O page.OrderField]( + first *int, + after *page.CursorKey, + last *int, + before *page.CursorKey, + orderBy page.OrderBy[O], +) *page.Cursor[O] { + var ( + size int + from *page.CursorKey + direction = page.Head + ) + + if first != nil { + size = *first + direction = page.Head + from = after + } else if last != nil { + size = *last + direction = page.Tail + from = before + } + + return page.NewCursor(size, from, direction, orderBy) +} + func MarshalCursorKeyScalar(ck page.CursorKey) graphql.Marshaler { return graphql.WriterFunc(func(w io.Writer) { _, _ = w.Write([]byte(strconv.Quote(ck.String()))) diff --git a/pkg/server/api/types/gid.go b/pkg/server/graphql/types/gid/gid.go similarity index 97% rename from pkg/server/api/types/gid.go rename to pkg/server/graphql/types/gid/gid.go index 2f7ca1869..fbc9718ef 100644 --- a/pkg/server/api/types/gid.go +++ b/pkg/server/graphql/types/gid/gid.go @@ -12,7 +12,7 @@ // OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR // PERFORMANCE OF THIS SOFTWARE. -package types +package gid import ( "errors" @@ -23,6 +23,8 @@ import ( "github.com/getprobo/probo/pkg/gid" ) +type GIDScalar = gid.GID + func MarshalGIDScalar(id gid.GID) graphql.Marshaler { return graphql.WriterFunc(func(w io.Writer) { w.Write([]byte(strconv.Quote(id.String()))) diff --git a/pkg/server/api/types/pageinfo.go b/pkg/server/graphql/types/pageinfo/pageinfo.go similarity index 78% rename from pkg/server/api/types/pageinfo.go rename to pkg/server/graphql/types/pageinfo/pageinfo.go index 57919dd8c..f25c9b891 100644 --- a/pkg/server/api/types/pageinfo.go +++ b/pkg/server/graphql/types/pageinfo/pageinfo.go @@ -12,24 +12,21 @@ // OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR // PERFORMANCE OF THIS SOFTWARE. -package types +package pageinfo import ( "github.com/getprobo/probo/pkg/page" "go.gearno.de/x/ref" ) -// PageInfoData contains the raw data for constructing PageInfo structs -type PageInfoData struct { +type PageInfo struct { HasNextPage bool HasPreviousPage bool StartCursor *page.CursorKey EndCursor *page.CursorKey } -// NewPageInfoData creates PageInfo data from a Page result. -// This can be used by local packages to construct their PageInfo structs. -func NewPageInfoData[T page.Paginable[O], O page.OrderField](p *page.Page[T, O]) PageInfoData { +func NewPageInfo[T page.Paginable[O], O page.OrderField](p *page.Page[T, O]) *PageInfo { var ( startCursor *page.CursorKey endCursor *page.CursorKey @@ -40,7 +37,7 @@ func NewPageInfoData[T page.Paginable[O], O page.OrderField](p *page.Page[T, O]) endCursor = ref.Ref(p.Last().CursorKey(p.Cursor.OrderBy.Field)) } - return PageInfoData{ + return &PageInfo{ HasNextPage: p.Info.HasNext, HasPreviousPage: p.Info.HasPrev, StartCursor: startCursor,