Merge branch 'master' into async-graphql-v3

This commit is contained in:
Sunli 2021-11-13 09:16:24 +08:00
commit eeb1f73773
4 changed files with 63 additions and 2 deletions

View File

@ -150,7 +150,11 @@ fn parse_number(pair: Pair<Rule>, pc: &mut PositionCalculator) -> Result<Positio
debug_assert_eq!(pair.as_rule(), Rule::number);
let pos = pc.step(&pair);
Ok(Positioned::new(
pair.as_str().parse().expect("failed to parse number"),
pair.as_str().parse().map_err(|err| Error::Syntax {
message: format!("invalid number: {}", err),
start: pos,
end: None,
})?,
pos,
))
}

View File

@ -513,7 +513,7 @@ impl Registry {
}
fn create_entity_type(&mut self) {
let possible_types = self
let possible_types: IndexSet<String> = self
.types
.values()
.filter_map(|ty| match ty {

View File

@ -31,6 +31,30 @@ impl CursorType for usize {
}
}
impl CursorType for i32 {
type Error = ParseIntError;
fn decode_cursor(s: &str) -> Result<Self, Self::Error> {
s.parse()
}
fn encode_cursor(&self) -> String {
self.to_string()
}
}
impl CursorType for i64 {
type Error = ParseIntError;
fn decode_cursor(s: &str) -> Result<Self, Self::Error> {
s.parse()
}
fn encode_cursor(&self) -> String {
self.to_string()
}
}
impl CursorType for String {
type Error = Infallible;

View File

@ -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"},
]
}
})
);
}