list

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ActionType = &ast.Definition{
		Kind: ast.Enum,
		Name: consts.SchemaDefResourceListActionType,
		EnumValues: []*ast.EnumValueDefinition{
			{
				Name: consts.SchemaDefListActionTypeBrowseQuery,
			},
			{
				Name: consts.SchemaDefListActionTypeBatchDeleteMutation,
			},
		},
	}
	ActionDirective = directives.InputObjectDirectiveDefinition{
		Definition: &ast.DirectiveDefinition{
			Name:        consts.SchemaDefDirectiveListActionName,
			Description: `This directive is used to mark the object as a resource list action`,
			Position:    &ast.Position{Src: &ast.Source{BuiltIn: false}},
			Arguments: ast.ArgumentDefinitionList{
				{
					Name: consts.SchemaDefActionDirectiveArgResource,
					Type: ast.NonNullNamedType("String", nil),
				},
				{
					Name: consts.SchemaDefActionDirectiveActionArgAction,
					Type: ast.NonNullNamedType(ActionType.Name, nil),
				},
				{
					Name: "Route",
					Type: ast.NamedType("String", nil),
				},
				{
					Name: "Pagination",
					Type: ast.NamedType("Boolean", nil),
				},
				sort.ResourceListActionArgumentDefinition,
				{
					Name: consts.SchemaDefActionDirectiveArgSchemaFieldName,
					Type: ast.NamedType("String", nil),
				},
			},
			Locations: []ast.DirectiveLocation{
				ast.LocationInputObject,
			},
			IsRepeatable: true,
		},
		Validate: func(directive *ast.Directive, def *ast.Definition) error {
			listActionDirective := def.Directives.ForName(consts.SchemaDefDirectiveListActionName)
			if listActionDirective == nil {
				return fmt.Errorf("directive %s not found", consts.SchemaDefDirectiveListActionName)
			}
			config := &generated.ListAction{}
			err := common.ArgsToStruct(listActionDirective.Arguments, config)

			if err != nil {
				return err
			}
			if config.Action == consts.SchemaDefListActionTypeBrowseQuery {
				idField := def.Fields.ForName("id")
				if idField == nil {
					return fmt.Errorf("id field required for %s action", consts.SchemaDefListActionTypeBrowseQuery)
				}
			}

			err = actions.PrepareActionDefaults(directive)
			if err != nil {
				return fmt.Errorf("failed to prepare action defaults: %w", err)
			}

			err = actions.PrepareListActionDefaults(directive)
			if err != nil {
				return fmt.Errorf("failed to prepare list action defaults: %w", err)
			}

			return nil
		},
	}
)

Functions

This section is empty.

Types

type XgenResourceListActionStruct

type XgenResourceListActionStruct struct {
	Resource   string
	Action     string
	Route      *string
	Pagination *bool
}

Jump to

Keyboard shortcuts

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