MCPcopy Index your code
hub / github.com/dosco/graphjin / Example_insertBulk

Function Example_insertBulk

tests/insert_test.go:235–276  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

233}
234
235func Example_insertBulk() {
236
237 gql := `mutation {
238 users(insert: $data) {
239 id
240 email
241 }
242 }`
243
244 vars := json.RawMessage(`{
245 "data": [{
246 "id": 1002,
247 "email": "user1002@test.com",
248 "full_name": "User 1002",
249 "stripe_id": "payment_id_1002",
250 "category_counts": [{"category_id": 1, "count": 400},{"category_id": 2, "count": 600}]
251 },
252 {
253 "id": 1003,
254 "email": "user1003@test.com",
255 "full_name": "User 1003",
256 "stripe_id": "payment_id_1003",
257 "category_counts": [{"category_id": 2, "count": 400},{"category_id": 3, "count": 600}]
258 }]
259 }`)
260
261 conf := newConfig(&core.Config{DBType: dbType, DisableAllowList: true})
262 gj, err := core.NewGraphJin(conf, db)
263 if err != nil {
264 panic(err)
265 }
266 defer gj.Close()
267
268 ctx := context.WithValue(context.Background(), core.UserIDKey, 3)
269 res, err := gj.GraphQL(ctx, gql, vars, nil)
270 if err != nil {
271 fmt.Println(err)
272 } else {
273 printJSON(res.Data)
274 }
275 // Output: {"users":[{"email":"user1002@test.com","id":1002},{"email":"user1003@test.com","id":1003}]}
276}
277
278func Example_insertIntoMultipleRelatedTables() {
279 // snowflake: cat 4 linear mutation — nested insert child→parent PK flow not yet wired in dialect

Callers

nothing calls this directly

Calls 4

CloseMethod · 0.95
GraphQLMethod · 0.95
newConfigFunction · 0.85
printJSONFunction · 0.85

Tested by

no test coverage detected