directives

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package directives defines and provides helpers for Argo-specific GraphQL directives used to control serialization, deserialization, and other behaviors.

Index

Constants

View Source
const (
	ArgoDeduplicateDirectiveName = "ArgoDeduplicate"
	ArgoCodecDirectiveName       = "ArgoCodec"
)

Variables

View Source
var ArgoCodecDirective = &ast.DirectiveDefinition{
	Name:        ArgoCodecDirectiveName,
	Description: "Specifies encoding for a type, potentially as a block. Adding, changing, or removing this directive is typically a breaking change.",
	Locations: []ast.DirectiveLocation{
		ast.LocationScalar,
		ast.LocationEnum,
	},
	Arguments: ast.ArgumentDefinitionList{
		{
			Name:        "codec",
			Type:        ast.NamedType("ArgoCodecType", nil),
			Description: "If specified, defines the underlying Argo wire type for a scalar, enum, or the content of a block.",
		},
		{
			Name:        "key",
			Type:        ast.NamedType("String", nil),
			Description: "If specified, encodes this type as an Argo Block with the given string as the block key. Often used with @ArgoDeduplicate.",
		},
		{
			Name:        "fixedLength",
			Type:        ast.NamedType("Int", nil),
			Description: "For the FIXED codec only: the length of the encoded value in bytes. Required if codec is FIXED.",
		},
	},
	IsRepeatable: false,
}

ArgoCodecDirective represents the @ArgoCodec directive.

View Source
var ArgoCodecType = &ast.Definition{
	Kind:        ast.Enum,
	Name:        "ArgoCodecType",
	Description: "Specifies how to serialize and deserialize this scalar or the underlying type of a block.",
	EnumValues: ast.EnumValueList{
		{Name: string(ArgoCodecValueString), Description: "Serialize and deserialize a scalar as a GraphQL String (UTF-8)."},
		{Name: string(ArgoCodecValueInt), Description: "Serialize and deserialize a scalar as a GraphQL Int (implies Argo Varint)."},
		{Name: string(ArgoCodecValueFloat), Description: "Serialize and deserialize a scalar as a GraphQL Float (IEEE 754 double-precision floating-point)."},
		{Name: string(ArgoCodecValueBoolean), Description: "Serialize and deserialize a scalar as a GraphQL Boolean."},
		{Name: string(ArgoCodecValueBYTES), Description: "Serialize and deserialize a scalar as Argo BYTES: a variable-length length-prefixed byte array."},
		{Name: string(ArgoCodecValueFIXED), Description: "Serialize and deserialize a scalar as Argo FIXED: a fixed-length byte array. Requires fixedLength arg."},
		{Name: string(ArgoCodecValueDESC), Description: "Serialize and deserialize a scalar as Argo DESC: a flexible self-describing binary format."},
		{Name: string(ArgoCodecValuePATH), Description: "Serialize and deserialize a scalar as Argo PATH: a structured path, often used for hierarchical data."},
	},
}

ArgoCodecType is the GraphQL enum definition for the 'codec' argument of @ArgoCodec.

View Source
var ArgoDeduplicateDirective = &ast.DirectiveDefinition{
	Name:        ArgoDeduplicateDirectiveName,
	Description: "Deduplicate values of this type. Adding or removing this directive is typically a breaking change.",
	Locations: []ast.DirectiveLocation{
		ast.LocationScalar,
		ast.LocationEnum,
	},
	Arguments: ast.ArgumentDefinitionList{
		{
			Name: "deduplicate",
			Type: ast.NonNullNamedType("Boolean", nil),
			DefaultValue: &ast.Value{
				Raw:          "true",
				Kind:         ast.BooleanValue,
				ExpectedType: ast.NamedType("Boolean", nil),
			},
			Description: "Should values of this type be deduplicated?",
		},
	},
	IsRepeatable: false,
}

ArgoDeduplicateDirective represents the @ArgoDeduplicate directive. Marks a type for de-duplication. Works best with large values which re-appear often.

Functions

func GetArgoDeduplicateValue

func GetArgoDeduplicateValue(directives ast.DirectiveList) (value bool, isPresent bool, err error)

GetArgoDeduplicateValue parses an @ArgoDeduplicate directive from a list of directives. It returns the boolean value of the 'deduplicate' argument, a flag indicating if the directive was present, and an error if parsing fails. If the directive is not present, it returns (false, false, nil). If the directive is present but the argument is missing, it defaults to (true, true, nil).

Types

type ArgoCodecArgs

type ArgoCodecArgs struct {
	Codec       *ArgoCodecValue
	FixedLength *int
	Key         *string
}

ArgoCodecArgs holds the parsed arguments from an @ArgoCodec directive. Pointers are used for optional arguments.

func GetArgoCodecArgs

func GetArgoCodecArgs(directives ast.DirectiveList) (ArgoCodecArgs, error)

GetArgoCodecArgs parses an @ArgoCodec directive from a list of directives. It returns the populated ArgoCodecArgs struct and an error if parsing fails or if arguments are inconsistent (e.g., fixedLength without FIXED codec). If the directive is not present, it returns an empty ArgoCodecArgs and no error.

type ArgoCodecValue

type ArgoCodecValue string

ArgoCodec represents the available Argo codecs values from the @ArgoCodec directive's 'codec' argument. This is distinct from Argo Wire TypeKeys.

const (
	ArgoCodecValueString  ArgoCodecValue = "String"
	ArgoCodecValueInt     ArgoCodecValue = "Int"
	ArgoCodecValueFloat   ArgoCodecValue = "Float"
	ArgoCodecValueBoolean ArgoCodecValue = "Boolean"
	ArgoCodecValueBYTES   ArgoCodecValue = "BYTES"
	ArgoCodecValueFIXED   ArgoCodecValue = "FIXED"
	ArgoCodecValueDESC    ArgoCodecValue = "DESC"
	ArgoCodecValuePATH    ArgoCodecValue = "PATH"
)

Jump to

Keyboard shortcuts

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