-
Notifications
You must be signed in to change notification settings - Fork 0
/
fix.go
44 lines (37 loc) · 1.02 KB
/
fix.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
package humus
//StaticQuery represents a static query.
type StaticQuery struct {
Query string
vars map[string]string
}
//SetVar sets the variable in the GraphQL query map.
//Since it is a static query the type is expected to be supplied
//in the string part of the query and not here.
func (s *StaticQuery) SetVar(key string, val interface{}) *StaticQuery {
if s.vars == nil {
s.vars = make(map[string]string)
}
s.vars[key], _ = processInterface(val)
return s
}
func (s StaticQuery) names() []string {
return defaultName
}
//Process the query in order to send to DGraph.
func (s StaticQuery) Process() (string, error) {
return s.Query, nil
}
func (s StaticQuery) queryVars() map[string]string {
return s.vars
}
//NewStaticQuery creates a formatted query.
//Use fmt.Sprintf as well as SetVar to supply parameters.
func NewStaticQuery(query string) StaticQuery {
return StaticQuery{Query: query}
}
func (s StaticQuery) QueryWithVars(vars map[string]string) StaticQuery {
return StaticQuery{
Query: s.Query,
vars: vars,
}
}