forked from usnistgov/ndn-dpdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgql.go
78 lines (72 loc) · 2.44 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
71
72
73
74
75
76
77
78
package fileserver
import (
"reflect"
"github.com/graphql-go/graphql"
"github.com/usnistgov/ndn-dpdk/app/tg/tggql"
"github.com/usnistgov/ndn-dpdk/core/gqlserver"
"github.com/usnistgov/ndn-dpdk/iface"
"github.com/usnistgov/ndn-dpdk/ndn"
)
// GqlRetrieveByFaceID returns *FileServer associated with a face.
// It is assigned during package tg initialization.
var GqlRetrieveByFaceID func(id iface.ID) *Server
// GraphQL types.
var (
GqlMountInput *graphql.InputObject
GqlConfigInput *graphql.InputObject
GqlCountersType *graphql.Object
GqlServerType *gqlserver.NodeType[*Server]
)
func init() {
GqlMountInput = graphql.NewInputObject(graphql.InputObjectConfig{
Name: "FileServerMountInput",
Description: "File server mount definition.",
Fields: gqlserver.BindInputFields[Mount](gqlserver.FieldTypes{
reflect.TypeFor[ndn.Name](): gqlserver.NonNullString,
}),
})
GqlConfigInput = graphql.NewInputObject(graphql.InputObjectConfig{
Name: "FileServerConfigInput",
Description: "File server config.",
Fields: gqlserver.BindInputFields[Config](gqlserver.FieldTypes{
reflect.TypeFor[iface.PktQueueConfig](): iface.GqlPktQueueInput,
reflect.TypeFor[Mount](): GqlMountInput,
}),
})
GqlCountersType = graphql.NewObject(graphql.ObjectConfig{
Name: "FileServerCounters",
Description: "File server counters.",
Fields: gqlserver.BindFields[Counters](nil),
})
GqlServerType = gqlserver.NewNodeType(graphql.ObjectConfig{
Name: "FileServer",
Description: "File server.",
Fields: tggql.CommonFields(graphql.Fields{
"mounts": &graphql.Field{
Description: "Mount entries.",
Type: gqlserver.NonNullJSON,
Resolve: func(p graphql.ResolveParams) (any, error) {
return p.Source.(*Server).Mounts(), nil
},
},
"counters": &graphql.Field{
Description: "Counters.",
Type: graphql.NewNonNull(GqlCountersType),
Resolve: func(p graphql.ResolveParams) (any, error) {
return p.Source.(*Server).Counters(), nil
},
},
"versionBypassHi": &graphql.Field{
Description: "High 32 bits of special version values to bypass version check in benchmarks.",
Type: gqlserver.Uint32,
Resolve: func(p graphql.ResolveParams) (any, error) {
server := p.Source.(*Server)
if server.VersionBypassHi == 0 {
return nil, nil
}
return server.VersionBypassHi, nil
},
},
}),
}, tggql.NodeConfig(&GqlRetrieveByFaceID))
}