helper

package
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2024 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssignEmptyContent

func AssignEmptyContent(fieldDetails *protobuff.FieldInfo) interface{}

func FieldToSelectionBuilder

func FieldToSelectionBuilder(fields []*protobuff.FieldInfo) []ast.Selection

func MapApitoFieldType2

func MapApitoFieldType2(fieldInfo *protobuff.FieldInfo) *shared.FieldDetails

func ReturnAQLObjectBuilder

func ReturnAQLObjectBuilder(_var string, isArray bool, isParentArray bool, _map map[string]*shared.FieldDetails) ([]string, error)
func returnAQLObjectBuilderBk(_var string, _pv string, nestedMedia bool, _map map[string]*FieldDetails) ([]string, string, error) {
	var vals []string
	for k, v := range _map {
		if v.Value != nil {
			switch v.FieldType {
			case "repeated":
				if !contains([]string{"data", "meta", "created_by", "last_modified_by"}, k) { // skip for data object
					_nestedVar := utility.RandomVariableGenerator(4)
					_returns, _pvr, err := returnAQLObjectBuilderBk(_nestedVar, _pv, false, v.Value.(map[string]*FieldDetails))
					if err != nil {
						return nil, "", err
					}
					vals = append(vals, fmt.Sprintf(`"%s" : ( FOR %s in NOT_NULL(%s) ? %s : [] RETURN { %s } )`, k, _nestedVar, _pvr, _pvr, strings.Join(_returns, ", ")))
				} else {
					_returns, _, err := returnAQLObjectBuilderBk(_var, _pv, false, v.Value.(map[string]*FieldDetails))
					if err != nil {
						return nil, "", err
					}
					vals = append(vals, fmt.Sprintf(`"%s" : { %s }`, k, strings.Join(_returns, ", ")))
				}
				break
			case "media", "multiline", "geo":
				if v.Validation != nil && v.Validation.IsGallery { // multiple media is an array
					_nestedVar := utility.RandomVariableGenerator(4)
					_returns, _pvr, err := returnAQLObjectBuilderBk(_nestedVar, _pv, false, v.Value.(map[string]*FieldDetails))
					if err != nil {
						return nil, "", err
					}
					vals = append(vals, fmt.Sprintf(`"%s" : ( FOR %s in NOT_NULL(%s) ? %s : [] RETURN { %s } )`, k, _nestedVar, _pvr, _pvr, strings.Join(_returns, ", ")))
				} else {
					_returns, _pvr, err := returnAQLObjectBuilderBk(_var, _pv, true, v.Value.(map[string]*FieldDetails))
					if err != nil {
						return nil, "", err
					}
					_pv = _pvr
					vals = append(vals, fmt.Sprintf(`"%s" : { %s }`, k, strings.Join(_returns, ", ")))
				}
				break
			default:
				if _var == "" {
					vals = append(vals, fmt.Sprintf(`"%s" : %s`, k, v.Value.(string)))
				} else if nestedMedia { // media in repeated field
					if val, ok := v.Value.(string); ok {
						splits := strings.Split(val, ".")
						end := strings.Join(splits[len(splits)-2:len(splits)], ".")
						vals = append(vals, fmt.Sprintf(`"%s" : %s.%s`, k, _var, end))
						start := strings.Join(splits[:len(splits)-2], ".")
						_pv = start
					}
				} else {
					if val, ok := v.Value.(string); ok {
						splitAt := strings.LastIndex(val, ".")
						vals = append(vals, fmt.Sprintf(`"%s" : %s.%s`, k, _var, val[splitAt+1:len(val)]))
						_pv = val[:splitAt]
					}
				}
			}
		}
	}
	return vals, _pv, nil
}

func ReturnBuilder

func ReturnBuilder(_var string, local string, _fields *shared.FieldDetails, set ast.SelectionSet) map[string]*shared.FieldDetails

func SelectionToFieldBuilder

func SelectionToFieldBuilder(selections []ast.Selection) []*protobuff.FieldInfo

Types

This section is empty.

Jump to

Keyboard shortcuts

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