gqlutil

package
v0.0.0-...-ee70915 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 24, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BadUserInputError

func BadUserInputError(err error) *gqlerror.Error

BadUserInputError returns a new bad user input gql error from a given error.

func BadUserInputErrorf

func BadUserInputErrorf(message string, args ...interface{}) *gqlerror.Error

BadUserInputErrorf returns a new bad user input gql error from a given message.

func DecodeIDCursor

func DecodeIDCursor(cursor *string) (*uint64, error)

DecodeIDCursor decodes a cursor only supposed to contain a numeric ID

func DecodeSeedAndIDCursor

func DecodeSeedAndIDCursor(cursor *string) (*int64, *uint64, error)

DecodeSeedAndIDCursor decodes a cursor supposed to contain a seed and a numeric ID

func DecodeUUIDCursor

func DecodeUUIDCursor(cursor *string) (*string, error)

DecodeUUIDCursor decodes a cursor only supposed to contain a numeric UUID

func EncodeIDCursor

func EncodeIDCursor(ID uint64) string

EncodeIDCursor encodes a cursor from a given ID

func EncodeSeedAndIDCursor

func EncodeSeedAndIDCursor(seed int64, ID uint64) string

EncodeSeedAndIDCursor encodes a cursor from a given seed and ID

func EncodeSeedAndUUIDCursor

func EncodeSeedAndUUIDCursor(seed int64, UUID string) string

EncodeSeedAndUUIDCursor encodes a cursor from a given seed and UUID

func EncodeUUIDCursor

func EncodeUUIDCursor(UUID string) string

EncodeUUIDCursor encodes a cursor from a given UUID

func Error

func Error(code ErrorCode, err error) *gqlerror.Error

Error returns a new gql error from a given code and error.

func ErrorPresenter

func ErrorPresenter(ctx context.Context, err error) *gqlerror.Error

ErrorPresenter ensure that an error is of type gqlerror.Error and has the gql path and error code filled before serialization. It also removes the error message for internal server errors to prevent technical insight leak.

func Errorf

func Errorf(code ErrorCode, message string, args ...interface{}) *gqlerror.Error

Errorf returns a new gql error from a given code and message.

func ForbiddenError

func ForbiddenError(err error) *gqlerror.Error

ForbiddenError returns a new forbidden gql error from a given error.

func ForbiddenErrorf

func ForbiddenErrorf(message string, args ...interface{}) *gqlerror.Error

ForbiddenErrorf returns a new forbidden gql error from a given message.

func GiftCampaignExpiredError

func GiftCampaignExpiredError(err error) *gqlerror.Error

GiftCampaignExpiredError returns a new not found gql error from a given error.

func GiftCampaignExpiredErrorf

func GiftCampaignExpiredErrorf(message string, args ...interface{}) *gqlerror.Error

GiftCampaignExpiredErrorf returns a new not found gql error from a given message.

func GiftCodeAlreadyRedeemedError

func GiftCodeAlreadyRedeemedError(err error) *gqlerror.Error

GiftCodeAlreadyRedeemedError returns a new not found gql error from a given error.

func GiftCodeAlreadyRedeemedErrorf

func GiftCodeAlreadyRedeemedErrorf(message string, args ...interface{}) *gqlerror.Error

GiftCodeAlreadyRedeemedErrorf returns a new not found gql error from a given message.

func GiftCodeNotFoundError

func GiftCodeNotFoundError(err error) *gqlerror.Error

GiftCodeNotFoundError returns a new not found gql error from a given error.

func GiftCodeNotFoundErrorf

func GiftCodeNotFoundErrorf(message string, args ...interface{}) *gqlerror.Error

GiftCodeNotFoundErrorf returns a new not found gql error from a given message.

func GiftUserHasSubscriptionError

func GiftUserHasSubscriptionError(err error) *gqlerror.Error

GiftUserHasSubscriptionError returns a new not found gql error from a given error.

func GiftUserHasSubscriptionErrorf

func GiftUserHasSubscriptionErrorf(message string, args ...interface{}) *gqlerror.Error

GiftUserHasSubscriptionErrorf returns a new not found gql error from a given message.

func InternalServerError

func InternalServerError(err error) *gqlerror.Error

InternalServerError returns a new internal server gql error from a given error.

func InternalServerErrorf

func InternalServerErrorf(message string, args ...interface{}) *gqlerror.Error

InternalServerErrorf returns a new internal server gql error from a given error.

func NotFoundError

func NotFoundError(err error) *gqlerror.Error

NotFoundError returns a new not found gql error from a given error.

func NotFoundErrorf

func NotFoundErrorf(message string, args ...interface{}) *gqlerror.Error

NotFoundErrorf returns a new not found gql error from a given message.

func UnauthenticatedError

func UnauthenticatedError(err error) *gqlerror.Error

UnauthenticatedError returns a new unauthenticated gql error from a given error.

func UnauthenticatedErrorf

func UnauthenticatedErrorf(message string, args ...interface{}) *gqlerror.Error

UnauthenticatedErrorf returns a new unauthenticated gql error from a given message.

func ValidatePaginationArguments

func ValidatePaginationArguments(before *uint64, after *uint64, first *int, last *int) error

ValidatePaginationArguments validates pagination arguments.

Types

type ErrorCode

type ErrorCode string

ErrorCode is a string representing an error code.

const (
	// InternalServerErrorCode should be returned on internal server error.
	// Equivalent to http 50x codes.
	InternalServerErrorCode ErrorCode = "INTERNAL_SERVER_ERROR"
	// UnauthenticatedCode should be returned when an unauthenticated user
	// is trying to access a auth only resource.
	// Equivalent to http 401 code.
	UnauthenticatedCode ErrorCode = "UNAUTHENTICATED"
	// ForbiddenCode should be returned when an authenticated user
	// does not have access to a resource.
	// Equivalent to http 403 code.
	ForbiddenCode ErrorCode = "FORBIDDEN"
	// BadUserInputCode should be returned on input data validation
	// failure.
	// Equivalent to 400 http code.
	BadUserInputCode ErrorCode = "BAD_USER_INPUT"
	// NotFoundCode should when a requested resource is not found.
	// Equivalent to 404 http code.
	NotFoundCode ErrorCode = "NOT_FOUND"
	// GiftCodeNotFound should be returned when the code doesn’t exist.
	// Equivalent to 404 http code.
	GiftCodeNotFound ErrorCode = "GIFT_CODE_NOT_FOUND"
	// GiftCodeAlreadyRedeemed should be returned when the code
	// has already been redeemed
	GiftCodeAlreadyRedeemed ErrorCode = "GIFT_CODE_ALREADY_REDEEMED"
	// GiftUserHasSubscription should be returned when
	// the user already has an active subscription
	GiftUserHasSubscription ErrorCode = "GIFT_USER_HAS_SUBSCRIPTION"
	// GiftCampaignExpired should be returned when the campaign
	// expiration date is in the past or if the campaign is canceled
	GiftCampaignExpired ErrorCode = "GIFT_CAMPAIGN_EXPIRED"

	// GQLValidationFailed should be returned when there's a query
	// validation error.
	GQLValidationFailed ErrorCode = errcode.ValidationFailed
	// GQLParseFailed should be returned when there's a query
	// parsing error.
	GQLParseFailed ErrorCode = errcode.ParseFailed
)

func GetErrorCode

func GetErrorCode(err error) ErrorCode

GetErrorCode returns the error code. InternalServerErrorCode by default.

type ID

type ID uint64

ID present a model ID, which is exposed as a string (ID type) in GraphQL but is a uint64 internally

func NewIDFromString

func NewIDFromString(v string) ID

NewIDFromString instanciate a new ID from a given string

func (ID) Int

func (id ID) Int() uint64

Int returns actual uint64 value of the ID

func (ID) MarshalGQL

func (id ID) MarshalGQL(w io.Writer)

MarshalGQL implements the graphql.Marshaler interface

func (ID) String

func (id ID) String() string

String returns string value of the ID

func (*ID) UnmarshalGQL

func (id *ID) UnmarshalGQL(v interface{}) error

UnmarshalGQL implements the graphql.Unmarshaler interface

type PageInfo

type PageInfo struct {
	HasNextPage     bool    `json:"hasNextPage"`
	HasPreviousPage bool    `json:"hasPreviousPage"`
	StartCursor     *string `json:"startCursor"`
	EndCursor       *string `json:"endCursor"`
}

PageInfo represents the PageInfo type in GraphQL

func PaginateIDEdges

func PaginateIDEdges(allEdges []uint64, before *uint64, after *uint64, first *int, last *int, seed *int64) ([]uint64, *PageInfo, error)

PaginateIDEdges returns a specific page of a slice of IDs with a corresponding new PageInfo. Implements the relay cursor connection spec: https://relay.dev/graphql/connections.htm

func PaginateIDs

func PaginateIDs(IDs []uint64, first int, cursor *uint64, seed *int64) ([]uint64, *PageInfo, error)

PaginateIDs returns a specific page of a slice of IDs with a corresponding new PageInfo. Deprecated (use PaginateItems instead).

func PaginateUUIDs

func PaginateUUIDs(UUIDs []string, first int, cursor *string, seed *int64) ([]string, *PageInfo, error)

PaginateUUIDs returns a specific page of a slice of UUIDs with a corresponding new PageInfo

type UUID

type UUID string

UUID present a model UUID, which is exposed as a string (UUID type) in GraphQL but is a uint64 internally

func (UUID) MarshalGQL

func (uuid UUID) MarshalGQL(w io.Writer)

MarshalGQL implements the graphql.Marshaler interface

func (UUID) String

func (uuid UUID) String() string

String returns string value of the UUID

func (*UUID) UnmarshalGQL

func (uuid *UUID) UnmarshalGQL(v interface{}) error

UnmarshalGQL implements the graphql.Unmarshaler interface

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL