Make private members optional
@@ -35,10 +35,10 @@ pub struct Schema {
clientid_field_name: StringKey,
typename_field_name: StringKey,
- string_type: Type,
- id_type: Type,
+ string_type: Option<Type>,
+ id_type: Option<Type>,
- unchecked_argument_type_sentinel: TypeReference,
+ unchecked_argument_type_sentinel: Option<TypeReference>,
directives: HashMap<StringKey, Directive>,
@@ -81,7 +81,7 @@ impl Schema {
///
/// TODO: we probably want to replace this with a proper `Unknown` type.
pub fn unchecked_argument_type_sentinel(&self) -> &TypeReference {
- &self.unchecked_argument_type_sentinel
+ self.unchecked_argument_type_sentinel.as_ref().unwrap()
}
pub fn is_type_subtype_of(
@@ -187,7 +187,7 @@ impl Schema {
}
pub fn is_string(&self, type_: Type) -> bool {
- type_ == self.string_type
+ type_ == self.string_type.unwrap()
}
fn write_type_string<W: Write>(&self, writer: &mut W, type_: &TypeReference) -> FormatResult {
@@ -316,7 +316,7 @@ impl Schema {
}
pub fn is_id(&self, type_: Type) -> bool {
- type_ == self.id_type
+ type_ == self.id_type.unwrap()
}
pub fn get_type_map(&self) -> impl Iterator<Item = (&StringKey, &Type)> {
@@ -695,8 +695,9 @@ impl Schema {
let string_type = *type_map.get(&"String".intern()).unwrap();
let id_type = *type_map.get(&"ID".intern()).unwrap();
- let unchecked_argument_type_sentinel =
- TypeReference::Named(*type_map.get(&"Boolean".intern()).unwrap());
+ let unchecked_argument_type_sentinel = Some(TypeReference::Named(
+ *type_map.get(&"Boolean".intern()).unwrap(),
+ ));
let mut schema = Schema {
query_type: None,
@@ -707,8 +708,8 @@ impl Schema {
typename_field: FieldID(0), // dummy value, overwritten later
clientid_field_name: "__id".intern(),
typename_field_name: "__typename".intern(),
- string_type,
- id_type,
+ string_type: Some(string_type),
+ id_type: Some(id_type),
unchecked_argument_type_sentinel,
directives: HashMap::with_capacity(directive_count),
enums: Vec::with_capacity(next_enum_id.try_into().unwrap()),
