-
Notifications
You must be signed in to change notification settings - Fork 26
/
gql.go
70 lines (64 loc) · 1.94 KB
/
gql.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package ndni
import (
"reflect"
"github.com/graphql-go/graphql"
"github.com/graphql-go/graphql/language/ast"
"github.com/usnistgov/ndn-dpdk/core/gqlserver"
"github.com/usnistgov/ndn-dpdk/core/nnduration"
"github.com/usnistgov/ndn-dpdk/ndn"
)
// GraphQL types.
var (
GqlNameType *graphql.Scalar
GqlInterestTemplateInput *graphql.InputObject
GqlInterestTemplateFieldTypes gqlserver.FieldTypes
GqlDataGenInput *graphql.InputObject
)
func init() {
GqlNameType = graphql.NewScalar(graphql.ScalarConfig{
Name: "Name",
Description: "The `Name` scalar type represents an NDN name.",
Serialize: func(value any) any {
switch v := value.(type) {
case ndn.Name:
return v.String()
case *ndn.Name:
return v.String()
}
return nil
},
ParseValue: func(value any) any {
switch v := value.(type) {
case string:
return ndn.ParseName(v)
case *string:
return ndn.ParseName(*v)
}
return nil
},
ParseLiteral: func(value ast.Value) any {
switch v := value.(type) {
case *ast.StringValue:
return ndn.ParseName(v.Value)
}
return nil
},
})
GqlInterestTemplateFieldTypes = gqlserver.FieldTypes{
reflect.TypeFor[ndn.Name](): gqlserver.NonNullString,
reflect.TypeFor[nnduration.Milliseconds](): nnduration.GqlMilliseconds,
}
GqlInterestTemplateInput = graphql.NewInputObject(graphql.InputObjectConfig{
Name: "InterestTemplateInput",
Description: "Interest template.",
Fields: gqlserver.BindInputFields[InterestTemplateConfig](GqlInterestTemplateFieldTypes),
})
GqlDataGenInput = graphql.NewInputObject(graphql.InputObjectConfig{
Name: "DataGenInput",
Description: "Data generator template.",
Fields: gqlserver.BindInputFields[DataGenConfig](gqlserver.FieldTypes{
reflect.TypeFor[ndn.Name](): gqlserver.NonNullString,
reflect.TypeFor[nnduration.Milliseconds](): nnduration.GqlMilliseconds,
}),
})
}