diff --git a/parser/src/parse/mod.rs b/parser/src/parse/mod.rs index 3a3e4259..5a584764 100644 --- a/parser/src/parse/mod.rs +++ b/parser/src/parse/mod.rs @@ -150,7 +150,11 @@ fn parse_number(pair: Pair, pc: &mut PositionCalculator) -> Result = self .types .values() .filter_map(|ty| match ty { diff --git a/src/types/connection/cursor.rs b/src/types/connection/cursor.rs index dccd9799..fdb67319 100644 --- a/src/types/connection/cursor.rs +++ b/src/types/connection/cursor.rs @@ -31,6 +31,30 @@ impl CursorType for usize { } } +impl CursorType for i32 { + type Error = ParseIntError; + + fn decode_cursor(s: &str) -> Result { + s.parse() + } + + fn encode_cursor(&self) -> String { + self.to_string() + } +} + +impl CursorType for i64 { + type Error = ParseIntError; + + fn decode_cursor(s: &str) -> Result { + s.parse() + } + + fn encode_cursor(&self) -> String { + self.to_string() + } +} + impl CursorType for String { type Error = Infallible; diff --git a/tests/federation.rs b/tests/federation.rs index d335ad91..711c2fbd 100644 --- a/tests/federation.rs +++ b/tests/federation.rs @@ -252,3 +252,36 @@ pub async fn test_find_entity_with_context() { }] ); } + +#[tokio::test] +pub async fn test_entity_union() { + #[derive(SimpleObject)] + struct MyObj { + a: i32, + } + + struct Query; + + #[Object] + impl Query { + #[graphql(entity)] + async fn find_obj(&self, _id: i32) -> MyObj { + todo!() + } + } + + let schema = Schema::new(Query, EmptyMutation, EmptySubscription); + let query = r#"{ + __type(name: "_Entity") { possibleTypes { name } } + }"#; + assert_eq!( + schema.execute(query).await.into_result().unwrap().data, + value!({ + "__type": { + "possibleTypes": [ + {"name": "MyObj"}, + ] + } + }) + ); +}