-
-
Notifications
You must be signed in to change notification settings - Fork 180
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added support for database transactions
- two new functions `GraphQLTx` and `GraphQLByNameTx` allows you to pass a db transaction to be used for the request - added a new `Tx` property to `ReqConfig` so you can also just use the existing functions with transactions
- Loading branch information
Showing
33 changed files
with
419 additions
and
932 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,20 +16,24 @@ import ( | |
|
||
func Example_insert() { | ||
gql := `mutation { | ||
users(insert: $data) { | ||
users(insert: { | ||
id: $id, | ||
email: $email, | ||
full_name: $fullName, | ||
stripe_id: $stripeID, | ||
category_counts: $categoryCounts | ||
}) { | ||
id | ||
} | ||
}` | ||
|
||
vars := json.RawMessage(`{ | ||
"data": { | ||
"id": 1001, | ||
"email": "[email protected]", | ||
"full_name": "User 1001", | ||
"stripe_id": "payment_id_1001", | ||
"category_counts": [{"category_id": 1, "count": 400},{"category_id": 2, "count": 600}] | ||
} | ||
"id": 1001, | ||
"email": "[email protected]", | ||
"fullName": "User 1001", | ||
"stripeID": "payment_id_1001", | ||
"categoryCounts": [{"category_id": 1, "count": 400},{"category_id": 2, "count": 600}] | ||
}`) | ||
|
||
conf := newConfig(&core.Config{DBType: dbType, DisableAllowList: true}) | ||
|
@@ -48,19 +52,26 @@ func Example_insert() { | |
// Output: {"users":[{"email":"[email protected]","id":1001}]} | ||
} | ||
|
||
func Example_insertInline() { | ||
func Example_insertWithTransaction() { | ||
gql := `mutation { | ||
users(insert: { id: $id, email: $email, full_name: $full_name }) { | ||
users(insert: { | ||
id: $id, | ||
email: $email, | ||
full_name: $fullName, | ||
stripe_id: $stripeID, | ||
category_counts: $categoryCounts | ||
}) { | ||
id | ||
full_name | ||
} | ||
}` | ||
|
||
vars := json.RawMessage(`{ | ||
"id": 1007, | ||
"email": "[email protected]", | ||
"full_name": "User 1007" | ||
"fullName": "User 1007", | ||
"stripeID": "payment_id_1007", | ||
"categoryCounts": [{"category_id": 1, "count": 400},{"category_id": 2, "count": 600}] | ||
}`) | ||
|
||
conf := newConfig(&core.Config{DBType: dbType, DisableAllowList: true}) | ||
|
@@ -69,14 +80,24 @@ func Example_insertInline() { | |
panic(err) | ||
} | ||
|
||
ctx := context.WithValue(context.Background(), core.UserIDKey, 3) | ||
res, err := gj.GraphQL(ctx, gql, vars, nil) | ||
c := context.Background() | ||
tx, err := db.BeginTx(c, nil) | ||
if err != nil { | ||
panic(err) | ||
} | ||
defer tx.Rollback() //nolint:errcheck | ||
|
||
c = context.WithValue(c, core.UserIDKey, 3) | ||
res, err := gj.GraphQLTx(c, tx, gql, vars, nil) | ||
if err != nil { | ||
fmt.Println(err) | ||
} else { | ||
printJSON(res.Data) | ||
return | ||
} | ||
if err := tx.Commit(); err != nil { | ||
panic(err) | ||
} | ||
// Output: {"users":[{"email":"[email protected]","full_name":"User 1007","id":1007}]} | ||
printJSON(res.Data) | ||
// Output: {"users":[{"email":"[email protected]","id":1007}]} | ||
} | ||
|
||
func Example_insertInlineWithValidation() { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
c7ed332
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
graphjin – ./
graphjin-dosco.vercel.app
graphjin.vercel.app
graphjin.com
www.graphjin.com
graphjin-git-master-dosco.vercel.app