MCPcopy
hub / github.com/dosco/graphjin / Example_insert

Function Example_insert

tests/insert_test.go:16–54  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

14)
15
16func 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
56func Example_insertWithTransaction() {
57 gql := `mutation {

Callers

nothing calls this directly

Calls 5

CloseMethod · 0.95
GraphQLMethod · 0.95
newConfigFunction · 0.85
printJSONFunction · 0.85
SQLMethod · 0.65

Tested by

no test coverage detected