scalars

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2023 License: MIT Imports: 7 Imported by: 1

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 interface{}) interface{} {
			valStr := fmt.Sprintf("%v", value)
			return valStr == "true" || valStr == "1"
		},
		ParseValue: func(value interface{}) interface{} {
			b, ok := value.(bool)
			if !ok {
				return "false"
			} else if b {
				return "true"
			}
			return "false"
		},
		ParseLiteral: func(astValue ast.Value) interface{} {
			value := astValue.GetValue()
			b, ok := value.(bool)
			if !ok {
				return "false"
			} else if b {
				return "true"
			}
			return "false"
		},
	},
)

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 interface{}) interface{} {
			return value
		},
		ParseValue: func(value interface{}) interface{} {
			return value
		},
		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: func(value interface{}) interface{} {
			return ensureArray(value)
		},
		ParseLiteral: func(astValue ast.Value) interface{} {
			return ensureArray(parseLiteralJSONFn(astValue))
		},
	},
)

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