-
Notifications
You must be signed in to change notification settings - Fork 0
/
field.go
46 lines (39 loc) · 887 Bytes
/
field.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package gql
import (
"context"
"fmt"
)
// Directive ..
type Directive struct {
Name string
Arguments []*Argument
}
// Field ...
type Field struct {
Name string
Description string
Depricated bool
DepricationReason string
Type Type
Arguments []*Argument
Resolver ResolverFunc
}
// ResolverFunc ..
type ResolverFunc func(context.Context, map[string]interface{}, interface{}) (interface{}, error)
// Fields ...
type Fields []*Field
// Get returns the field with the given name (if exists)
func (fs Fields) Get(name string) (*Field, error) {
for f := range fs {
if fs[f].Name == name {
return fs[f], nil
}
}
return nil, fmt.Errorf("there's no field named '%s'", name)
}
func (f *Field) Validate(ctx *ValidationContext) error {
if err := f.Type.Validate(ctx); err != nil {
return err
}
return nil
}