Fix types generation

Signed-off-by: Sacha Al Himdani <sacha@getprobo.com>
This commit is contained in:
Sacha Al Himdani
2025-08-07 18:34:26 +02:00
parent 987c85652c
commit c9ab0678be
13 changed files with 66 additions and 117 deletions

View File

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

View File

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

View File

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

View File

@@ -1,22 +0,0 @@
// Copyright (c) 2025 Probo Inc <hello@getprobo.com>.
//
// 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

View File

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

View File

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

View File

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

View File

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

View File

@@ -1,22 +0,0 @@
// Copyright (c) 2025 Probo Inc <hello@getprobo.com>.
//
// 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

View File

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

View File

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

View File

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

View File

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