Work around a terrible, terrible start.gg bug
I honestly don't even know what to say about this one.
This commit is contained in:
parent
361efe60a3
commit
847d879287
2 changed files with 37 additions and 19 deletions
|
|
@ -1,10 +1,29 @@
|
|||
use schema::schema;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::fmt::{Display, Error, Formatter};
|
||||
|
||||
// Types
|
||||
// HACK: Unfortunately, start.gg seems to use integers and strings
|
||||
// interchangeably for its ID types (... for some reason), whereas cynic always
|
||||
// assumes that IDs are strings. To get around that, we define new scalar types
|
||||
// that deserialize properly.
|
||||
|
||||
// HACK: Unfortunately, start.gg seems to use integers for its ID type, whereas
|
||||
// cynic always assumes that IDs are strings. To get around that, we define new
|
||||
// scalar types that deserialize to u64.
|
||||
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
|
||||
#[serde(untagged)]
|
||||
pub enum StringOrInt {
|
||||
String(String),
|
||||
Int(u64),
|
||||
}
|
||||
|
||||
impl Display for StringOrInt {
|
||||
fn fmt(&self, fmt: &mut Formatter) -> Result<(), Error> {
|
||||
match self {
|
||||
StringOrInt::String(x) => x.fmt(fmt),
|
||||
StringOrInt::Int(x) => x.fmt(fmt),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Scalar Types
|
||||
|
||||
#[derive(cynic::Scalar, Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
#[cynic(graphql_type = "ID")]
|
||||
|
|
@ -26,10 +45,10 @@ pub struct EntrantId(pub u64);
|
|||
#[repr(transparent)]
|
||||
pub struct PlayerId(pub u64);
|
||||
|
||||
#[derive(cynic::Scalar, Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
#[derive(cynic::Scalar, Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
#[cynic(graphql_type = "ID")]
|
||||
#[repr(transparent)]
|
||||
pub struct SetId(pub u64);
|
||||
pub struct SetId(pub StringOrInt);
|
||||
|
||||
#[derive(cynic::Scalar, Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
#[repr(transparent)]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue