Skip to content

Commit

Permalink
Update Mutation (#136)
Browse files Browse the repository at this point in the history
* Add update mutation
  • Loading branch information
karatakis authored Oct 9, 2023
1 parent d9282e6 commit 44ec378
Show file tree
Hide file tree
Showing 9 changed files with 678 additions and 29 deletions.
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

0 comments on commit 44ec378

Please sign in to comment.