Skip to content

Commit

Permalink
Support __typename on variants inside inline fragment. (#616)
Browse files Browse the repository at this point in the history
We were extracting the __typename to use for variant selection, but then not passing it into the inner type that we needed to deserialize, so it was failing.
  • Loading branch information
obmarg committed Feb 17, 2023
1 parent f74030f commit 9d23984
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 2 deletions.
7 changes: 7 additions & 0 deletions cynic/src/private/inline_fragment_de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ where
let key = key.into_inner();
if key == "__typename" {
let typename = access.next_value::<CowStr<'_>>()?.into_inner();

// Put __typename into the buffer incase it's needed by the inner decoder
buffer.push((
Cow::Borrowed("__typename"),
Content::String(typename.as_ref().to_string()),
));

return T::deserialize_variant(
typename.as_ref(),
BufferDeserializer { access, buffer },
Expand Down
1 change: 1 addition & 0 deletions examples/examples/querying-interfaces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ enum Node {
#[derive(cynic::QueryFragment, Debug)]
#[cynic(schema_path = "../schemas/starwars.schema.graphql")]
struct Film {
__typename: String,
title: Option<String>,
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
---
source: examples/examples/querying-interfaces.rs
assertion_line: 115
expression: result.data
---
Some(
Query {
node: Some(
Film(
Film {
__typename: "Film",
title: Some(
"A New Hope",
),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
---
source: examples/examples/querying-interfaces.rs
assertion_line: 106
expression: query.query
---
query($id: ID!) {
node(id: $id) {
__typename
... on Film {
__typename
title
}
... on Planet {
Expand Down

0 comments on commit 9d23984

Please sign in to comment.