Merge branch 'master' into async-graphql-v3
This commit is contained in:
commit
eeb1f73773
|
@ -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,
|
||||
))
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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"},
|
||||
]
|
||||
}
|
||||
})
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user