Skip to content

Commit

Permalink
Get rid of client_field_ids on SchemaObject
Browse files Browse the repository at this point in the history
* A validated schema object will contain a HashMap mapping SelectableFieldName to
  either a client field ID or a server field ID
* These will also be present in the schema's vectors of client fields and server fields
* The schema object used to also contain a vector of its own client field ID's. But this
  isn't necessary, since we always start with a SelectableFieldName, rather than anything
  else.
* A follow up will be to remove the vector of server field IDs on a schema object, which
  is similarly unneeded.
  • Loading branch information
rbalicki2 committed May 11, 2024
1 parent f7b3e74 commit 205d2cd
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 38 deletions.
2 changes: 0 additions & 2 deletions crates/isograph_cli/src/refetch_fields.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,6 @@ fn add_refetch_field_to_object(
},
parent_object_id: object.id,
});

object.client_field_ids.push(next_client_field_id);
}
}
None
Expand Down
3 changes: 1 addition & 2 deletions crates/isograph_schema/src/add_fields_to_subtypes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ impl UnvalidatedSchema {
// Should we transfer server fields??? That makes no sense for
// GraphQL, but ... does it make sense otherwise? Who knows.
}
crate::FieldDefinitionLocation::Client(supertype_client_field_id) => {
crate::FieldDefinitionLocation::Client(_) => {
let subtype = self.server_field_data.object_mut(*subtype_id);

if let Some(_) = subtype
Expand All @@ -45,7 +45,6 @@ impl UnvalidatedSchema {
Location::generated(),
));
}
subtype.client_field_ids.push(*supertype_client_field_id);
}
}
}
Expand Down
1 change: 0 additions & 1 deletion crates/isograph_schema/src/expose_field_directive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,6 @@ impl UnvalidatedSchema {
Location::generated(),
));
}
client_field_parent.client_field_ids.push(client_field_id);

Ok(())
}
Expand Down
1 change: 0 additions & 1 deletion crates/isograph_schema/src/isograph_schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,6 @@ pub struct SchemaObject<TEncounteredField> {
/// to something else.
pub id_field: Option<ServerStrongIdFieldId>,
pub server_field_ids: Vec<ServerFieldId>,
pub client_field_ids: Vec<ClientFieldId>,
pub encountered_fields: HashMap<SelectableFieldName, TEncounteredField>,
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@ impl UnvalidatedSchema {
));
}

object.client_field_ids.push(next_client_field_id);

let name = client_field_declaration.item.client_field_name.item.into();
let variant = get_client_variant(&client_field_declaration.item);

Expand Down
1 change: 0 additions & 1 deletion crates/isograph_schema/src/process_type_definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,6 @@ impl UnvalidatedSchema {
name: object_type_definition.name.item,
id: next_object_id,
server_field_ids: server_fields,
client_field_ids: vec![],
encountered_fields,
id_field,
directives: object_type_definition.directives,
Expand Down
51 changes: 22 additions & 29 deletions crates/isograph_schema/src/validate_schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,7 @@ impl ValidatedSchema {
if errors.is_empty() {
let objects = objects
.into_iter()
.map(|object| {
transform_object_field_ids(&updated_fields, &updated_client_fields, object)
})
.map(|object| transform_object_field_ids(&updated_fields, object))
.collect();

Ok(Self {
Expand All @@ -171,7 +169,6 @@ impl ValidatedSchema {

fn transform_object_field_ids(
schema_fields: &[ValidatedSchemaServerField],
validated_client_fields: &[ValidatedClientField],
unvalidated_object: UnvalidatedSchemaObject,
) -> ValidatedSchemaObject {
let SchemaObject {
Expand All @@ -180,36 +177,33 @@ fn transform_object_field_ids(
description,
id,
encountered_fields: unvalidated_encountered_fields,
client_field_ids,
id_field,
directives,
} = unvalidated_object;

let validated_encountered_fields = unvalidated_encountered_fields
.into_iter()
.map(|(encountered_field_name, _)| {
for server_field_id in server_fields.iter() {
let field = &schema_fields[server_field_id.as_usize()];
if field.name.item == encountered_field_name {
return (
encountered_field_name,
FieldDefinitionLocation::Server(field.id),
);
}
}
for client_field_id in client_field_ids.iter() {
let client_field = &validated_client_fields[client_field_id.as_usize()];
if client_field.name == encountered_field_name {
return (
encountered_field_name,
FieldDefinitionLocation::Client(client_field.id),
);
}
}
panic!(
"field {:?} not found, probably a isograph bug but we should confirm",
encountered_field_name
);
.map(|(encountered_field_name, value)| match value {
FieldDefinitionLocation::Server(_) => (encountered_field_name, {
server_fields
.iter()
.find_map(|server_field_id| {
let field = &schema_fields[server_field_id.as_usize()];
if field.name.item == encountered_field_name {
Some(FieldDefinitionLocation::Server(*server_field_id))
} else {
None
}
})
.expect(&format!(
"Field {} not found, probably a bug in Isograph",
encountered_field_name
))
}),
FieldDefinitionLocation::Client(client_field_id) => (
encountered_field_name,
FieldDefinitionLocation::Client(client_field_id),
),
})
.collect();

Expand All @@ -219,7 +213,6 @@ fn transform_object_field_ids(
id,
server_field_ids: server_fields,
encountered_fields: validated_encountered_fields,
client_field_ids,
id_field,
directives,
}
Expand Down

0 comments on commit 205d2cd

Please sign in to comment.