(sch *ast.Schema, typ *ast.Definition, field *ast.FieldDefinition, dir *ast.Directive, secrets map[string]x.Sensitive)
| 1661 | } |
| 1662 | |
| 1663 | func customDirectiveValidation(sch *ast.Schema, |
| 1664 | typ *ast.Definition, |
| 1665 | field *ast.FieldDefinition, |
| 1666 | dir *ast.Directive, |
| 1667 | secrets map[string]x.Sensitive) gqlerror.List { |
| 1668 | var errs []*gqlerror.Error |
| 1669 | |
| 1670 | // 1. Validating custom directive itself |
| 1671 | search := field.Directives.ForName(searchDirective) |
| 1672 | if search != nil { |
| 1673 | errs = append(errs, gqlerror.ErrorPosf( |
| 1674 | dir.Position, |
| 1675 | "Type %s; Field %s; custom directive not allowed along with @search directive.", |
| 1676 | typ.Name, field.Name)) |
| 1677 | } |
| 1678 | |
| 1679 | dgraph := field.Directives.ForName(dgraphDirective) |
| 1680 | if dgraph != nil { |
| 1681 | errs = append(errs, gqlerror.ErrorPosf( |
| 1682 | dir.Position, |
| 1683 | "Type %s; Field %s; custom directive not allowed along with @dgraph directive.", |
| 1684 | typ.Name, field.Name)) |
| 1685 | } |
| 1686 | |
| 1687 | defn := sch.Types[typ.Name] |
| 1688 | id := getIDField(defn, nil) |
| 1689 | xid := getXIDField(defn, nil) |
| 1690 | if !isQueryOrMutationType(typ) { |
| 1691 | if len(id) == 0 && len(xid) == 0 { |
| 1692 | errs = append(errs, gqlerror.ErrorPosf( |
| 1693 | dir.Position, |
| 1694 | "Type %s; Field %s; @custom directive is only allowed on fields where the type"+ |
| 1695 | " definition has a field with type ID! or a field with @id directive.", |
| 1696 | typ.Name, field.Name)) |
| 1697 | } |
| 1698 | } |
| 1699 | |
| 1700 | // 2. Validating arguments to custom directive |
| 1701 | l := len(dir.Arguments) |
| 1702 | if l == 0 || l > 1 { |
| 1703 | errs = append(errs, gqlerror.ErrorPosf( |
| 1704 | dir.Position, |
| 1705 | "Type %s; Field %s: has %d arguments for @custom directive, "+ |
| 1706 | "it should contain exactly one of `http` or `dql` arguments.", |
| 1707 | typ.Name, field.Name, l)) |
| 1708 | } |
| 1709 | |
| 1710 | httpArg := dir.Arguments.ForName(httpArg) |
| 1711 | dqlArg := dir.Arguments.ForName(dqlArg) |
| 1712 | |
| 1713 | if httpArg == nil && dqlArg == nil { |
| 1714 | errs = append(errs, gqlerror.ErrorPosf( |
| 1715 | dir.Position, |
| 1716 | "Type %s; Field %s: one of `http` or `dql` arguments must be present for @custom"+ |
| 1717 | " directive.", |
| 1718 | typ.Name, field.Name)) |
| 1719 | return errs |
| 1720 | } |
no test coverage detected