| 233 | } |
| 234 | |
| 235 | func 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 | |
| 278 | func Example_insertIntoMultipleRelatedTables() { |
| 279 | // snowflake: cat 4 linear mutation — nested insert child→parent PK flow not yet wired in dialect |