scalars

package
v0.0.0-...-6b7534b Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ScalarBoolString = graphql.NewScalar(
	graphql.ScalarConfig{
		Name:        "BoolString",
		Description: "BoolString converts a boolean to/from a string",
		Serialize: func(value any) (any, error) {
			valStr := fmt.Sprintf("%v", value)
			return valStr == "true" || valStr == "1", nil
		},
		ParseValue: func(value any) (any, error) {
			b, ok := value.(bool)
			if !ok {
				return "false", nil
			} else if b {
				return "true", nil
			}
			return "false", nil
		},
		ParseLiteral: func(astValue ast.Value) (any, error) {
			value := astValue.GetValue()
			b, ok := value.(bool)
			if !ok {
				return "false", nil
			} else if b {
				return "true", nil
			}
			return "false", nil
		},
	},
)

ScalarBoolString converts boolean to a string

View Source
var ScalarJSON = graphql.NewScalar(
	graphql.ScalarConfig{
		Name:        "JSON",
		Description: "The `JSON` scalar type represents JSON values as specified by [ECMA-404](http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-404.pdf)",
		Serialize: func(value any) (any, error) {
			return value, nil
		},
		ParseValue: func(value any) (any, error) {
			return value, nil
		},
		ParseLiteral: parseLiteralJSONFn,
	},
)

ScalarJSON a scalar JSON type

View Source
var ScalarQueryDocument = graphql.NewScalar(
	graphql.ScalarConfig{
		Name:         "QueryDocument",
		Description:  "MongoDB style query document",
		Serialize:    serializeQueryDocFn,
		ParseValue:   parseValueQueryDocFn,
		ParseLiteral: parseLiteralQueryDocFn,
	},
)

ScalarQueryDocument a mongodb style query document

View Source
var ScalarStringSet = graphql.NewScalar(
	graphql.ScalarConfig{
		Name:        "StringSet",
		Description: "StringSet allows either a string or list of strings",
		Serialize:   serializeStringSetFn,
		ParseValue:  ensureArray,
		ParseLiteral: func(astValue ast.Value) (any, error) {
			val, err := parseLiteralJSONFn(astValue)
			if err != nil {
				return nil, err
			}
			return ensureArray(val)
		},
	},
)

ScalarStringSet allows string or array of strings stores as an array of strings

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

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