| 14 | ) |
| 15 | |
| 16 | func Example_insert() { |
| 17 | gql := `mutation { |
| 18 | users(insert: { |
| 19 | id: $id, |
| 20 | email: $email, |
| 21 | full_name: $fullName, |
| 22 | stripe_id: $stripeID, |
| 23 | category_counts: $categoryCounts |
| 24 | }) { |
| 25 | id |
| 26 | email |
| 27 | } |
| 28 | }` |
| 29 | |
| 30 | vars := json.RawMessage(`{ |
| 31 | "id": 1001, |
| 32 | "email": "user1001@test.com", |
| 33 | "fullName": "User 1001", |
| 34 | "stripeID": "payment_id_1001", |
| 35 | "categoryCounts": [{"category_id": 1, "count": 400},{"category_id": 2, "count": 600}] |
| 36 | }`) |
| 37 | |
| 38 | conf := newConfig(&core.Config{DBType: dbType, DisableAllowList: true, Debug: true}) |
| 39 | gj, err := core.NewGraphJin(conf, db) |
| 40 | if err != nil { |
| 41 | panic(err) |
| 42 | } |
| 43 | defer gj.Close() |
| 44 | |
| 45 | ctx := context.WithValue(context.Background(), core.UserIDKey, 3) |
| 46 | res, err := gj.GraphQL(ctx, gql, vars, nil) |
| 47 | if err != nil { |
| 48 | fmt.Println(err) |
| 49 | fmt.Println("SQL:", res.SQL()) |
| 50 | return |
| 51 | } |
| 52 | printJSON(res.Data) |
| 53 | // Output: {"users":[{"email":"user1001@test.com","id":1001}]} |
| 54 | } |
| 55 | |
| 56 | func Example_insertWithTransaction() { |
| 57 | gql := `mutation { |