-
Notifications
You must be signed in to change notification settings - Fork 0
/
read.go
127 lines (120 loc) · 2.79 KB
/
read.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
package prisma
func (client *Client) GetOne(base *Exec, params interface{}, typeNames [2]string, instrName string, typeFields []string) *Exec {
var args []graphQLArg
if params != nil {
args = append(args, graphQLArg{
Name: "where",
Key: "where",
TypeName: typeNames[0],
Value: params,
})
}
var stack []instruction
if base != nil {
stack = make([]instruction, len(base.Stack), len(base.Stack)+1)
copy(stack, base.Stack)
}
stack = append(stack, instruction{
Name: instrName,
Field: graphQLField{
Name: instrName,
TypeName: typeNames[1],
TypeFields: typeFields,
},
Operation: "query",
Args: args,
})
return &Exec{
Client: client,
Stack: stack,
}
}
type WhereParams struct {
Where interface{} `json:"where,omitempty"`
OrderBy *string `json:"orderBy,omitempty"`
Skip *int32 `json:"skip,omitempty"`
After *string `json:"after,omitempty"`
Before *string `json:"before,omitempty"`
First *int32 `json:"first,omitempty"`
Last *int32 `json:"last,omitempty"`
}
func (client *Client) GetMany(base *Exec, params *WhereParams, typeNames [3]string, instrName string, typeFields []string) *Exec {
var args []graphQLArg
if params != nil {
if params.Where != nil {
args = append(args, graphQLArg{
Name: "where",
Key: "where",
TypeName: typeNames[0],
Value: params.Where,
})
}
if params.OrderBy != nil {
args = append(args, graphQLArg{
Name: "orderBy",
Key: "orderBy",
TypeName: typeNames[1],
Value: *params.OrderBy,
})
}
if params.Skip != nil {
args = append(args, graphQLArg{
Name: "skip",
Key: "skip",
TypeName: "Int",
Value: *params.Skip,
})
}
if params.After != nil {
args = append(args, graphQLArg{
Name: "after",
Key: "after",
TypeName: "String",
Value: *params.After,
})
}
if params.Before != nil {
args = append(args, graphQLArg{
Name: "before",
Key: "before",
TypeName: "String",
Value: *params.Before,
})
}
if params.First != nil {
args = append(args, graphQLArg{
Name: "first",
Key: "first",
TypeName: "Int",
Value: *params.First,
})
}
if params.Last != nil {
args = append(args, graphQLArg{
Name: "last",
Key: "last",
TypeName: "Int",
Value: *params.Last,
})
}
}
var stack []instruction
if base != nil {
stack = make([]instruction, len(base.Stack), len(base.Stack)+1)
copy(stack, base.Stack)
}
stack = append(stack, instruction{
Name: instrName,
Field: graphQLField{
Name: instrName,
TypeName: typeNames[2],
TypeFields: typeFields,
},
Operation: "query",
Args: args,
})
return &Exec{
Client: client,
Stack: stack,
}
}