| 54 | } |
| 55 | |
| 56 | func Example_insertWithTransaction() { |
| 57 | gql := `mutation { |
| 58 | users(insert: { |
| 59 | id: $id, |
| 60 | email: $email, |
| 61 | full_name: $fullName, |
| 62 | stripe_id: $stripeID, |
| 63 | category_counts: $categoryCounts |
| 64 | }) { |
| 65 | id |
| 66 | email |
| 67 | } |
| 68 | }` |
| 69 | |
| 70 | vars := json.RawMessage(`{ |
| 71 | "id": 1007, |
| 72 | "email": "user1007@test.com", |
| 73 | "fullName": "User 1007", |
| 74 | "stripeID": "payment_id_1007", |
| 75 | "categoryCounts": [{"category_id": 1, "count": 400},{"category_id": 2, "count": 600}] |
| 76 | }`) |
| 77 | |
| 78 | conf := newConfig(&core.Config{DBType: dbType, DisableAllowList: true}) |
| 79 | gj, err := core.NewGraphJin(conf, db) |
| 80 | if err != nil { |
| 81 | panic(err) |
| 82 | } |
| 83 | defer gj.Close() |
| 84 | |
| 85 | c := context.Background() |
| 86 | tx, err := db.BeginTx(c, nil) |
| 87 | if err != nil { |
| 88 | panic(err) |
| 89 | } |
| 90 | defer tx.Rollback() //nolint:errcheck |
| 91 | |
| 92 | c = context.WithValue(c, core.UserIDKey, 3) |
| 93 | res, err := gj.GraphQLTx(c, tx, gql, vars, nil) |
| 94 | if err != nil { |
| 95 | fmt.Println(err) |
| 96 | return |
| 97 | } |
| 98 | if err := tx.Commit(); err != nil { |
| 99 | panic(err) |
| 100 | } |
| 101 | printJSON(res.Data) |
| 102 | // Output: {"users":[{"email":"user1007@test.com","id":1007}]} |
| 103 | } |
| 104 | |
| 105 | func Example_insertInlineWithValidation() { |
| 106 | gql := `mutation |