Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Mutation #136

Merged
merged 35 commits into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
6271e86
WIP create_one mutation
karatakis Apr 24, 2023
e6e8bdc
Add type utilities
karatakis May 1, 2023
3edc270
Fix clippy
karatakis May 1, 2023
937df32
Fix types map
karatakis May 22, 2023
3260f33
fix fmt
karatakis Jul 22, 2023
d8ab5e3
Improve error reporting
karatakis Jul 22, 2023
0a2357f
Add auto register mutations
karatakis Jul 22, 2023
22c1ca6
Add tests
karatakis Jul 22, 2023
ce6fcb2
Fix fmt
karatakis Jul 22, 2023
458ce64
Fix tests
karatakis Jul 22, 2023
554b2d9
Fix tests
karatakis Jul 22, 2023
77422cb
Fix fmt
karatakis Jul 22, 2023
6232e49
Fix tests
karatakis Jul 22, 2023
38e85b3
Fix tests
karatakis Jul 22, 2023
4444fb2
Fix tests
karatakis Jul 22, 2023
96395ed
Fix test
karatakis Jul 22, 2023
96bef2b
Add filter_types_map
karatakis Jul 23, 2023
4ef6d88
Use output_conversions configuration
karatakis Jul 23, 2023
ba53a53
Fix fmt
karatakis Jul 24, 2023
5215d3f
Fix clippy
karatakis Jul 24, 2023
7f5fbdb
Fix temp test edge case
karatakis Jul 24, 2023
c62310c
Fix tests
karatakis Jul 24, 2023
7d6a5e4
Add create_batch mutation
karatakis Jul 24, 2023
6be965a
Remove duplicate code and add tests
karatakis Jul 26, 2023
ee735e1
Fix fmt & clippy
karatakis Jul 26, 2023
c87f672
Update tests and changelog
karatakis Jul 26, 2023
e3244d3
Fix tests
karatakis Jul 27, 2023
bf844d6
Fix tests
karatakis Jul 27, 2023
a61b792
Fix tests
karatakis Jul 27, 2023
53ba9a3
Add update mutation
karatakis Jul 28, 2023
2e65a25
Add update mutation tests
karatakis Jul 28, 2023
46f8c79
Cargo fmt
karatakis Jul 28, 2023
92f7b70
Merge branch 'main' into mutations-update
karatakis Oct 9, 2023
672e607
Fix fmt
karatakis Oct 9, 2023
6b54439
Update pgsql tests
karatakis Oct 9, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,14 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## 1.0.2 - 2023-10-09
## 1.0.3 - Pending

* add `update_mutation`

This module enabled the update mutation for entities. The update mutation takes an entity data object with a filter condition object,
applies the update to the database and returns the modified entities.

## 1.0.2 - Pending

* add `create_one_mutation`

Expand Down Expand Up @@ -41,14 +48,17 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

* start error handling

## 1.0.1 - 2023-03-25
## 1.0.1 - Pending

* slim down code generation for the `query_root.rs` file of a generated project

* update crates

* update examples

## 1.0.0 - Pending
=======

## 1.0.0 - 2023-03-25

Introduction the functional API of Seaography. Warning, this version has breaking changes, but it was a sacrifice in order to make the project easier to maintain. With this version we have support for field guards and field renames.
Expand Down
179 changes: 179 additions & 0 deletions examples/mysql/tests/mutation_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,3 +359,182 @@ async fn test_create_batch_mutation() {
"#,
)
}

#[tokio::test]
async fn test_update_mutation() {
let schema = get_schema().await;

assert_eq(
schema
.execute(
r#"
{
country(pagination: { page: { limit: 10, page: 0 } }) {
nodes {
country
countryId
}
}
}
"#,
)
.await,
r#"
{
"country": {
"nodes": [
{
"country": "Afghanistan",
"countryId": 1
},
{
"country": "Algeria",
"countryId": 2
},
{
"country": "American Samoa",
"countryId": 3
},
{
"country": "Angola",
"countryId": 4
},
{
"country": "Anguilla",
"countryId": 5
},
{
"country": "Argentina",
"countryId": 6
},
{
"country": "Armenia",
"countryId": 7
},
{
"country": "Australia",
"countryId": 8
},
{
"country": "Austria",
"countryId": 9
},
{
"country": "Azerbaijan",
"countryId": 10
}
]
}
}
"#,
);

assert_eq(
schema
.execute(
r#"
mutation {
countryUpdate(
data: { country: "[DELETED]" }
filter: { countryId: { lt: 6 } }
) {
countryId
country
}
}
"#,
)
.await,
r#"
{
"countryUpdate": [
{
"countryId": 1,
"country": "[DELETED]"
},
{
"countryId": 2,
"country": "[DELETED]"
},
{
"countryId": 3,
"country": "[DELETED]"
},
{
"countryId": 4,
"country": "[DELETED]"
},
{
"countryId": 5,
"country": "[DELETED]"
}
]
}
"#,
);

assert_eq(
schema
.execute(
r#"
{
country(pagination: { page: { limit: 10, page: 0 } }) {
nodes {
country
countryId
}
}
}
"#,
)
.await,
r#"
{
"country": {
"nodes": [
{
"country": "[DELETED]",
"countryId": 1
},
{
"country": "[DELETED]",
"countryId": 2
},
{
"country": "[DELETED]",
"countryId": 3
},
{
"country": "[DELETED]",
"countryId": 4
},
{
"country": "[DELETED]",
"countryId": 5
},
{
"country": "Argentina",
"countryId": 6
},
{
"country": "Armenia",
"countryId": 7
},
{
"country": "Australia",
"countryId": 8
},
{
"country": "Austria",
"countryId": 9
},
{
"country": "Azerbaijan",
"countryId": 10
}
]
}
}
"#,
);
}
149 changes: 148 additions & 1 deletion examples/postgres/tests/mutation_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ async fn test_simple_insert_one() {
filmActorCreateOne(data: { actorId: 1, filmId: 2, lastUpdate: "2030-01-01 11:11:11"}) {
actorId
filmId
__typename
__typename
}
}
"#,
Expand Down Expand Up @@ -361,3 +361,150 @@ async fn test_create_batch_mutation() {
"#,
)
}

#[tokio::test]
async fn test_update_mutation() {
let schema = get_schema().await;

assert_eq(
schema
.execute(
r#"
{
country(filters: { countryId: { lt: 7 } }, orderBy: { countryId: ASC }) {
nodes {
country
countryId
}
}
}
"#,
)
.await,
r#"
{
"country": {
"nodes": [
{
"country": "Afghanistan",
"countryId": 1
},
{
"country": "Algeria",
"countryId": 2
},
{
"country": "American Samoa",
"countryId": 3
},
{
"country": "Angola",
"countryId": 4
},
{
"country": "Anguilla",
"countryId": 5
},
{
"country": "Argentina",
"countryId": 6
}
]
}
}
"#,
);

assert_eq(
schema
.execute(
r#"
mutation {
countryUpdate(
data: { country: "[DELETED]" }
filter: { countryId: { lt: 6 } }
) {
countryId
country
}
}
"#,
)
.await,
r#"
{
"countryUpdate": [
{
"countryId": 1,
"country": "[DELETED]"
},
{
"countryId": 2,
"country": "[DELETED]"
},
{
"countryId": 3,
"country": "[DELETED]"
},
{
"countryId": 4,
"country": "[DELETED]"
},
{
"countryId": 5,
"country": "[DELETED]"
}
]
}
"#,
);

assert_eq(
schema
.execute(
r#"
{
country(filters: { countryId: { lt: 7 } }, orderBy: { countryId: ASC }) {
nodes {
country
countryId
}
}
}
"#,
)
.await,
r#"
{
"country": {
"nodes": [
{
"country": "[DELETED]",
"countryId": 1
},
{
"country": "[DELETED]",
"countryId": 2
},
{
"country": "[DELETED]",
"countryId": 3
},
{
"country": "[DELETED]",
"countryId": 4
},
{
"country": "[DELETED]",
"countryId": 5
},
{
"country": "Argentina",
"countryId": 6
}
]
}
}
"#,
);
}
Loading
Loading