-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generate an enum for
@oneOf
input (#450)
* Add `is_one_of` to input * Extract struct building from input codegen * Generate enums for `oneOf` input * Clippy fixes * Empty commit for CI --------- Co-authored-by: Surma <surma@surma.dev>
- Loading branch information
Showing
10 changed files
with
180 additions
and
53 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
use graphql_client::*; | ||
use serde_json::*; | ||
|
||
#[derive(GraphQLQuery)] | ||
#[graphql( | ||
schema_path = "tests/one_of_input/schema.graphql", | ||
query_path = "tests/one_of_input/query.graphql", | ||
variables_derives = "Clone" | ||
)] | ||
pub struct OneOfMutation; | ||
|
||
#[test] | ||
fn one_of_input() { | ||
use one_of_mutation::*; | ||
|
||
let author = Param::Author(Author { id: 1 }); | ||
let _ = Param::Name("Mark Twain".to_string()); | ||
let _ = Param::RecursiveDirect(Box::new(author.clone())); | ||
let _ = Param::RecursiveIndirect(Box::new(Recursive { | ||
param: Box::new(author.clone()), | ||
})); | ||
let _ = Param::RequiredInts(vec![1]); | ||
let _ = Param::OptionalInts(vec![Some(1)]); | ||
|
||
let query = OneOfMutation::build_query(Variables { param: author }); | ||
assert_eq!( | ||
json!({ "param": { "author":{ "id": 1 } } }), | ||
serde_json::to_value(&query.variables).expect("json"), | ||
); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
mutation OneOfMutation($param: Param!) { | ||
oneOfMutation(query: $param) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
schema { | ||
mutation: Mutation | ||
} | ||
|
||
type Mutation { | ||
oneOfMutation(mutation: Param!): Int | ||
} | ||
|
||
input Param @oneOf { | ||
author: Author | ||
name: String | ||
recursiveDirect: Param | ||
recursiveIndirect: Recursive | ||
requiredInts: [Int!] | ||
optionalInts: [Int] | ||
} | ||
|
||
input Author { | ||
id: Int! | ||
} | ||
|
||
input Recursive { | ||
param: Param! | ||
} |
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