// relationalFieldDefinition returns true and current context if it is an RelationalFieldDefinition,
// nil and false otherwise.
4567
func relationalFieldDefinition(failIfNotSD bool) (*gorma.RelationalFieldDefinition, bool) {
	a, ok := dslengine.CurrentDefinition().(*gorma.RelationalFieldDefinition)
	if !ok && failIfNotSD {
		dslengine.IncompatibleDSL()
	}
	return a, ok
}
789054
func SQLTag(d string) {
	if r, ok := relationalModelDefinition(false); ok {
		r.SQLTag = d
	} else if f, ok := relationalFieldDefinition(false); ok {
		f.SQLTag = d
	}
}
1185069
func parseFieldDefinition(parser *Parser) (interface{}, error) {
	start := parser.Token.Start
	description, err := parseDescription(parser)
	if err != nil {
		return nil, err
	}
	name, err := parseName(parser)
	if err != nil {
		return nil, err
	}
	args, err := parseArgumentDefs(parser)
	if err != nil {
		return nil, err
	}
	_, err = expect(parser, lexer.COLON)
	if err != nil {
		return nil, err
	}
	ttype, err := parseType(parser)
	if err != nil {
		return nil, err
	}
	directives, err := parseDirectives(parser)
	if err != nil {
		return nil, err
	}
	return ast.NewFieldDefinition(&ast.FieldDefinition{
		Name:        name,
		Description: description,
		Arguments:   args,
		Type:        ttype,
		Directives:  directives,
		Loc:         loc(parser, start),
	}), nil
}
792433
func DefaultTypeInfoFieldDef(schema *Schema, parentType Type, fieldAST *ast.Field) *FieldDefinition {
	name := ""
	if fieldAST.Name != nil {
		name = fieldAST.Name.Value
	}
	if name == SchemaMetaFieldDef.Name &&
		schema.QueryType() == parentType {
		return SchemaMetaFieldDef
	}
	if name == TypeMetaFieldDef.Name &&
		schema.QueryType() == parentType {
		return TypeMetaFieldDef
	}
	if name == TypeNameMetaFieldDef.Name && parentType != nil {
		if t, ok := parentType.(*Object); ok && t != nil {
			return TypeNameMetaFieldDef
		}
		if t, ok := parentType.(*Interface); ok && t != nil {
			return TypeNameMetaFieldDef
		}
		if t, ok := parentType.(*Union); ok && t != nil {
			return TypeNameMetaFieldDef
		}
	}

	if parentType, ok := parentType.(*Object); ok && parentType != nil {
		field, _ := parentType.Fields()[name]
		return field
	}
	if parentType, ok := parentType.(*Interface); ok && parentType != nil {
		field, _ := parentType.Fields()[name]
		return field
	}
	return nil
}
182478
func Description(d string) {
	if a, ok := storageGroupDefinition(false); ok {
		a.Description = d
	} else if v, ok := relationalStoreDefinition(false); ok {
		v.Description = d
	} else if r, ok := relationalModelDefinition(false); ok {
		r.Description = d
	} else if f, ok := relationalFieldDefinition(false); ok {
		f.Description = d
	}
}
518060
func FieldsFromContext(ctx context.Context) map[string]interface{} {
	m := make(map[string]interface{})
	v := ctx.Value(RequestIDContextKey)
	if v != nil {
		m[log.FnRequestID] = v.(string)
	}
	return m
}
274348
func parseTypeExtensionDefinition(parser *Parser) (ast.Node, error) {
	start := parser.Token.Start
	_, err := expectKeyWord(parser, lexer.EXTEND)
	if err != nil {
		return nil, err
	}

	definition, err := parseObjectTypeDefinition(parser)
	if err != nil {
		return nil, err
	}
	return ast.NewTypeExtensionDefinition(&ast.TypeExtensionDefinition{
		Loc:        loc(parser, start),
		Definition: definition.(*ast.ObjectDefinition),
	}), nil
}
1018841
func (j *FieldDefinitions) Validate() error {
	if j == nil {
		return errs.New("fields not defined")
	}
	for name, field := range *j {
		if err := field.Validate(); err != nil {
			return errs.Wrapf(err, "failed to validate field %s", name)
		}
	}
	return nil
}
1335585
func NewRelationalModelDefinition() *RelationalModelDefinition {
	baseAttr := &design.AttributeDefinition{}
	utd := &design.UserTypeDefinition{
		AttributeDefinition: baseAttr,
	}
	utd.Type = design.Object{}
	m := &RelationalModelDefinition{
		RelationalFields: make(map[string]*RelationalFieldDefinition),
		BuiltFrom:        make(map[string]*design.UserTypeDefinition),
		RenderTo:         make(map[string]*design.MediaTypeDefinition),
		BelongsTo:        make(map[string]*RelationalModelDefinition),
		HasMany:          make(map[string]*RelationalModelDefinition),
		HasOne:           make(map[string]*RelationalModelDefinition),
		ManyToMany:       make(map[string]*ManyToManyDefinition),
		UserTypeDefinition: &design.UserTypeDefinition{
			AttributeDefinition: baseAttr,
		},
	}
	return m
}
119827
func (l *LinkDefinition) Attribute() *AttributeDefinition {
	p := l.Parent.ToObject()
	if p == nil {
		return nil
	}
	att, _ := p[l.Name]

	return att
}
661014
func (f *RelationalModelDefinition) PKWhere() string {
	var pkwhere []string
	for _, pk := range f.PrimaryKeys {
		def := fmt.Sprintf("%s = ?", pk.DatabaseFieldName)
		pkwhere = append(pkwhere, def)
	}
	return strings.Join(pkwhere, " and ")
}
516045
func docsDefinition() (*design.DocsDefinition, bool) {
	a, ok := dslengine.CurrentDefinition().(*design.DocsDefinition)
	if !ok {
		dslengine.IncompatibleDSL()
	}
	return a, ok
}
782461
func parseInputObjectTypeDefinition(parser *Parser) (ast.Node, error) {
	start := parser.Token.Start
	description, err := parseDescription(parser)
	if err != nil {
		return nil, err
	}
	_, err = expectKeyWord(parser, lexer.INPUT)
	if err != nil {
		return nil, err
	}
	name, err := parseName(parser)
	if err != nil {
		return nil, err
	}
	directives, err := parseDirectives(parser)
	if err != nil {
		return nil, err
	}
	iInputValueDefinitions, err := reverse(parser,
		lexer.BRACE_L, parseInputValueDef, lexer.BRACE_R,
		false,
	)
	if err != nil {
		return nil, err
	}
	fields := []*ast.InputValueDefinition{}
	for _, iInputValueDefinition := range iInputValueDefinitions {
		if iInputValueDefinition != nil {
			fields = append(fields, iInputValueDefinition.(*ast.InputValueDefinition))
		}
	}
	return ast.NewInputObjectDefinition(&ast.InputObjectDefinition{
		Name:        name,
		Description: description,
		Directives:  directives,
		Loc:         loc(parser, start),
		Fields:      fields,
	}), nil
}
1286924
func (field *RelationalFieldDefinition) Validate() *dslengine.ValidationErrors {
	fmt.Println("Validing Field")
	verr := new(dslengine.ValidationErrors)

	if field.Parent == nil {
		verr.Add(field, "missing relational model parent")
	}
	if field.FieldName == "" {
		verr.Add(field, "field name not defined")
	}
	return verr.AsError()
}
1318060
func responseDefinition() (*design.ResponseDefinition, bool) {
	r, ok := dslengine.CurrentDefinition().(*design.ResponseDefinition)
	if !ok {
		dslengine.IncompatibleDSL()
	}
	return r, ok
}
1204894
func (n *Namespace) decodeEnumDefinition(namespace string, schemaMap map[string]interface{}) (Definition, error) {
	typeStr, err := getMapString(schemaMap, "type")
	if err != nil {
		return nil, err
	}

	if typeStr != "enum" {
		return nil, fmt.Errorf("Type of enum must be 'enum'")
	}

	if _, ok := schemaMap["namespace"]; ok {
		namespace, err = getMapString(schemaMap, "namespace")
		if err != nil {
			return nil, err
		}
	}

	name, err := getMapString(schemaMap, "name")
	if err != nil {
		return nil, err
	}

	symbolSlice, err := getMapArray(schemaMap, "symbols")
	if err != nil {
		return nil, err
	}

	symbolStr, ok := interfaceSliceToStringSlice(symbolSlice)
	if !ok {
		return nil, fmt.Errorf("'symbols' must be an array of strings")
	}

	aliases, err := parseAliases(schemaMap, namespace)
	if err != nil {
		return nil, err
	}

	var docString string
	if doc, ok := schemaMap["doc"]; ok {
		if docString, ok = doc.(string); !ok {
			return nil, fmt.Errorf("'doc' must be a string")
		}
	}

	return NewEnumDefinition(ParseAvroName(namespace, name), aliases, symbolStr, docString, schemaMap), nil
}
1188061
func parseFieldTag(structField reflect.StructField, dosaAnnotation string) (*ColumnDefinition, error) {
	typ, isPointer, err := typify(structField.Type)
	if err != nil {
		return nil, err
	}
	return parseField(typ, isPointer, structField.Name, dosaAnnotation)
}