Use custom type for big int in graphql
Signed-off-by: Sacha Al Himdani <sacha@getprobo.com>
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* @generated SignedSource<<8f56e9dbd8ce8cf0c81d8f2e9f1ad06e>>
|
* @generated SignedSource<<4c861a832ad2f79bd9d6ddcc364f6898>>
|
||||||
* @lightSyntaxTransform
|
* @lightSyntaxTransform
|
||||||
* @nogrep
|
* @nogrep
|
||||||
*/
|
*/
|
||||||
@@ -11,7 +11,7 @@
|
|||||||
import { ReaderFragment } from 'relay-runtime';
|
import { ReaderFragment } from 'relay-runtime';
|
||||||
import { FragmentRefs } from "relay-runtime";
|
import { FragmentRefs } from "relay-runtime";
|
||||||
export type VendorComplianceTabFragment_report$data = {
|
export type VendorComplianceTabFragment_report$data = {
|
||||||
readonly fileSize: number;
|
readonly fileSize: any;
|
||||||
readonly fileUrl: string;
|
readonly fileUrl: string;
|
||||||
readonly id: string;
|
readonly id: string;
|
||||||
readonly reportDate: any;
|
readonly reportDate: any;
|
||||||
|
|||||||
@@ -30,3 +30,6 @@ models:
|
|||||||
Duration:
|
Duration:
|
||||||
model:
|
model:
|
||||||
- "github.com/99designs/gqlgen/graphql.Duration"
|
- "github.com/99designs/gqlgen/graphql.Duration"
|
||||||
|
BigInt:
|
||||||
|
model:
|
||||||
|
- "github.com/getprobo/probo/pkg/server/graphql/types/bigint.BigIntScalar"
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ scalar Void
|
|||||||
scalar Datetime
|
scalar Datetime
|
||||||
scalar Upload
|
scalar Upload
|
||||||
scalar Duration
|
scalar Duration
|
||||||
|
scalar BigInt
|
||||||
|
|
||||||
# Interfaces
|
# Interfaces
|
||||||
interface Node {
|
interface Node {
|
||||||
@@ -1719,7 +1720,7 @@ type VendorComplianceReport implements Node {
|
|||||||
validUntil: Datetime
|
validUntil: Datetime
|
||||||
reportName: String!
|
reportName: String!
|
||||||
fileUrl: String! @goField(forceResolver: true)
|
fileUrl: String! @goField(forceResolver: true)
|
||||||
fileSize: Int!
|
fileSize: BigInt!
|
||||||
createdAt: Datetime!
|
createdAt: Datetime!
|
||||||
updatedAt: Datetime!
|
updatedAt: Datetime!
|
||||||
}
|
}
|
||||||
@@ -1731,7 +1732,7 @@ type VendorBusinessAssociateAgreement implements Node {
|
|||||||
validUntil: Datetime
|
validUntil: Datetime
|
||||||
fileName: String!
|
fileName: String!
|
||||||
fileUrl: String! @goField(forceResolver: true)
|
fileUrl: String! @goField(forceResolver: true)
|
||||||
fileSize: Int!
|
fileSize: BigInt!
|
||||||
createdAt: Datetime!
|
createdAt: Datetime!
|
||||||
updatedAt: Datetime!
|
updatedAt: Datetime!
|
||||||
}
|
}
|
||||||
@@ -1763,7 +1764,7 @@ type VendorDataPrivacyAgreement implements Node {
|
|||||||
validUntil: Datetime
|
validUntil: Datetime
|
||||||
fileName: String!
|
fileName: String!
|
||||||
fileUrl: String! @goField(forceResolver: true)
|
fileUrl: String! @goField(forceResolver: true)
|
||||||
fileSize: Int!
|
fileSize: BigInt!
|
||||||
createdAt: Datetime!
|
createdAt: Datetime!
|
||||||
updatedAt: Datetime!
|
updatedAt: Datetime!
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import (
|
|||||||
"github.com/getprobo/probo/pkg/gid"
|
"github.com/getprobo/probo/pkg/gid"
|
||||||
"github.com/getprobo/probo/pkg/page"
|
"github.com/getprobo/probo/pkg/page"
|
||||||
"github.com/getprobo/probo/pkg/server/api/console/v1/types"
|
"github.com/getprobo/probo/pkg/server/api/console/v1/types"
|
||||||
|
"github.com/getprobo/probo/pkg/server/graphql/types/bigint"
|
||||||
"github.com/getprobo/probo/pkg/server/graphql/types/cursor"
|
"github.com/getprobo/probo/pkg/server/graphql/types/cursor"
|
||||||
gid1 "github.com/getprobo/probo/pkg/server/graphql/types/gid"
|
gid1 "github.com/getprobo/probo/pkg/server/graphql/types/gid"
|
||||||
gqlparser "github.com/vektah/gqlparser/v2"
|
gqlparser "github.com/vektah/gqlparser/v2"
|
||||||
@@ -8427,6 +8428,7 @@ scalar Void
|
|||||||
scalar Datetime
|
scalar Datetime
|
||||||
scalar Upload
|
scalar Upload
|
||||||
scalar Duration
|
scalar Duration
|
||||||
|
scalar BigInt
|
||||||
|
|
||||||
# Interfaces
|
# Interfaces
|
||||||
interface Node {
|
interface Node {
|
||||||
@@ -10128,7 +10130,7 @@ type VendorComplianceReport implements Node {
|
|||||||
validUntil: Datetime
|
validUntil: Datetime
|
||||||
reportName: String!
|
reportName: String!
|
||||||
fileUrl: String! @goField(forceResolver: true)
|
fileUrl: String! @goField(forceResolver: true)
|
||||||
fileSize: Int!
|
fileSize: BigInt!
|
||||||
createdAt: Datetime!
|
createdAt: Datetime!
|
||||||
updatedAt: Datetime!
|
updatedAt: Datetime!
|
||||||
}
|
}
|
||||||
@@ -10140,7 +10142,7 @@ type VendorBusinessAssociateAgreement implements Node {
|
|||||||
validUntil: Datetime
|
validUntil: Datetime
|
||||||
fileName: String!
|
fileName: String!
|
||||||
fileUrl: String! @goField(forceResolver: true)
|
fileUrl: String! @goField(forceResolver: true)
|
||||||
fileSize: Int!
|
fileSize: BigInt!
|
||||||
createdAt: Datetime!
|
createdAt: Datetime!
|
||||||
updatedAt: Datetime!
|
updatedAt: Datetime!
|
||||||
}
|
}
|
||||||
@@ -10172,7 +10174,7 @@ type VendorDataPrivacyAgreement implements Node {
|
|||||||
validUntil: Datetime
|
validUntil: Datetime
|
||||||
fileName: String!
|
fileName: String!
|
||||||
fileUrl: String! @goField(forceResolver: true)
|
fileUrl: String! @goField(forceResolver: true)
|
||||||
fileSize: Int!
|
fileSize: BigInt!
|
||||||
createdAt: Datetime!
|
createdAt: Datetime!
|
||||||
updatedAt: Datetime!
|
updatedAt: Datetime!
|
||||||
}
|
}
|
||||||
@@ -57837,9 +57839,9 @@ func (ec *executionContext) _VendorBusinessAssociateAgreement_fileSize(ctx conte
|
|||||||
}
|
}
|
||||||
return graphql.Null
|
return graphql.Null
|
||||||
}
|
}
|
||||||
res := resTmp.(int)
|
res := resTmp.(int64)
|
||||||
fc.Result = res
|
fc.Result = res
|
||||||
return ec.marshalNInt2int(ctx, field.Selections, res)
|
return ec.marshalNBigInt2int64(ctx, field.Selections, res)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ec *executionContext) fieldContext_VendorBusinessAssociateAgreement_fileSize(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
|
func (ec *executionContext) fieldContext_VendorBusinessAssociateAgreement_fileSize(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
|
||||||
@@ -57849,7 +57851,7 @@ func (ec *executionContext) fieldContext_VendorBusinessAssociateAgreement_fileSi
|
|||||||
IsMethod: false,
|
IsMethod: false,
|
||||||
IsResolver: false,
|
IsResolver: false,
|
||||||
Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) {
|
Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) {
|
||||||
return nil, errors.New("field of type Int does not have child fields")
|
return nil, errors.New("field of type BigInt does not have child fields")
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
return fc, nil
|
return fc, nil
|
||||||
@@ -58294,9 +58296,9 @@ func (ec *executionContext) _VendorComplianceReport_fileSize(ctx context.Context
|
|||||||
}
|
}
|
||||||
return graphql.Null
|
return graphql.Null
|
||||||
}
|
}
|
||||||
res := resTmp.(int)
|
res := resTmp.(int64)
|
||||||
fc.Result = res
|
fc.Result = res
|
||||||
return ec.marshalNInt2int(ctx, field.Selections, res)
|
return ec.marshalNBigInt2int64(ctx, field.Selections, res)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ec *executionContext) fieldContext_VendorComplianceReport_fileSize(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
|
func (ec *executionContext) fieldContext_VendorComplianceReport_fileSize(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
|
||||||
@@ -58306,7 +58308,7 @@ func (ec *executionContext) fieldContext_VendorComplianceReport_fileSize(_ conte
|
|||||||
IsMethod: false,
|
IsMethod: false,
|
||||||
IsResolver: false,
|
IsResolver: false,
|
||||||
Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) {
|
Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) {
|
||||||
return nil, errors.New("field of type Int does not have child fields")
|
return nil, errors.New("field of type BigInt does not have child fields")
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
return fc, nil
|
return fc, nil
|
||||||
@@ -59722,9 +59724,9 @@ func (ec *executionContext) _VendorDataPrivacyAgreement_fileSize(ctx context.Con
|
|||||||
}
|
}
|
||||||
return graphql.Null
|
return graphql.Null
|
||||||
}
|
}
|
||||||
res := resTmp.(int)
|
res := resTmp.(int64)
|
||||||
fc.Result = res
|
fc.Result = res
|
||||||
return ec.marshalNInt2int(ctx, field.Selections, res)
|
return ec.marshalNBigInt2int64(ctx, field.Selections, res)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ec *executionContext) fieldContext_VendorDataPrivacyAgreement_fileSize(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
|
func (ec *executionContext) fieldContext_VendorDataPrivacyAgreement_fileSize(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
|
||||||
@@ -59734,7 +59736,7 @@ func (ec *executionContext) fieldContext_VendorDataPrivacyAgreement_fileSize(_ c
|
|||||||
IsMethod: false,
|
IsMethod: false,
|
||||||
IsResolver: false,
|
IsResolver: false,
|
||||||
Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) {
|
Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) {
|
||||||
return nil, errors.New("field of type Int does not have child fields")
|
return nil, errors.New("field of type BigInt does not have child fields")
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
return fc, nil
|
return fc, nil
|
||||||
@@ -85858,6 +85860,22 @@ var (
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func (ec *executionContext) unmarshalNBigInt2int64(ctx context.Context, v any) (int64, error) {
|
||||||
|
res, err := bigint.UnmarshalBigIntScalar(v)
|
||||||
|
return res, graphql.ErrorOnPath(ctx, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ec *executionContext) marshalNBigInt2int64(ctx context.Context, sel ast.SelectionSet, v int64) graphql.Marshaler {
|
||||||
|
_ = sel
|
||||||
|
res := bigint.MarshalBigIntScalar(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")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|
||||||
func (ec *executionContext) unmarshalNBoolean2bool(ctx context.Context, v any) (bool, error) {
|
func (ec *executionContext) unmarshalNBoolean2bool(ctx context.Context, v any) (bool, error) {
|
||||||
res, err := graphql.UnmarshalBoolean(v)
|
res, err := graphql.UnmarshalBoolean(v)
|
||||||
return res, graphql.ErrorOnPath(ctx, err)
|
return res, graphql.ErrorOnPath(ctx, err)
|
||||||
|
|||||||
60
pkg/server/graphql/types/bigint/bigint.go
Normal file
60
pkg/server/graphql/types/bigint/bigint.go
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
// 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 bigint
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"github.com/99designs/gqlgen/graphql"
|
||||||
|
)
|
||||||
|
|
||||||
|
type BigIntScalar = int64
|
||||||
|
|
||||||
|
func MarshalBigIntScalar(i int64) graphql.Marshaler {
|
||||||
|
return graphql.WriterFunc(func(w io.Writer) {
|
||||||
|
w.Write([]byte(strconv.FormatInt(i, 10)))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func UnmarshalBigIntScalar(v any) (int64, error) {
|
||||||
|
switch val := v.(type) {
|
||||||
|
case string:
|
||||||
|
i, err := strconv.ParseInt(val, 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
return 0, fmt.Errorf("invalid BigInt value: %v", err)
|
||||||
|
}
|
||||||
|
return i, nil
|
||||||
|
case int:
|
||||||
|
return int64(val), nil
|
||||||
|
case int32:
|
||||||
|
return int64(val), nil
|
||||||
|
case int64:
|
||||||
|
return val, nil
|
||||||
|
case float32:
|
||||||
|
if val != float32(int64(val)) {
|
||||||
|
return 0, fmt.Errorf("BigInt cannot represent non-integer value: %v", val)
|
||||||
|
}
|
||||||
|
return int64(val), nil
|
||||||
|
case float64:
|
||||||
|
if val != float64(int64(val)) {
|
||||||
|
return 0, fmt.Errorf("BigInt cannot represent non-integer value: %v", val)
|
||||||
|
}
|
||||||
|
return int64(val), nil
|
||||||
|
default:
|
||||||
|
return 0, fmt.Errorf("cannot unmarshal %T into BigInt", v)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user