-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
generate client pointer param types #434
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,7 +24,7 @@ use lazy_static::lazy_static; | |
use crate::{ | ||
refetch_strategy::RefetchStrategy, schema_validation_state::SchemaValidationState, | ||
ClientFieldVariant, NormalizationKey, OutputFormat, ServerFieldTypeAssociatedData, | ||
ValidatedClientField, ValidatedClientPointer, | ||
ValidatedClientField, ValidatedClientPointer, ValidatedSchemaServerField, | ||
}; | ||
|
||
lazy_static! { | ||
|
@@ -134,12 +134,79 @@ pub enum FieldType<TServer, TClient> { | |
ClientField(TClient), | ||
} | ||
|
||
pub type LinkedType< | ||
'a, | ||
ServerFieldTypeAssociatedData, | ||
ClientTypeSelectionScalarFieldAssociatedData, | ||
ClientTypeSelectionLinkedFieldAssociatedData, | ||
VariableDefinitionInnerType, | ||
TOutputFormat, | ||
> = FieldType< | ||
&'a SchemaServerField< | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it makes me sad that |
||
ServerFieldTypeAssociatedData, | ||
VariableDefinitionInnerType, | ||
TOutputFormat, | ||
>, | ||
&'a ClientPointer< | ||
ClientTypeSelectionScalarFieldAssociatedData, | ||
ClientTypeSelectionLinkedFieldAssociatedData, | ||
VariableDefinitionInnerType, | ||
TOutputFormat, | ||
>, | ||
>; | ||
|
||
#[derive(Debug, Clone, Copy, Ord, PartialOrd, PartialEq, Eq, Hash)] | ||
pub enum ClientType<TField, TPointer> { | ||
ClientField(TField), | ||
ClientPointer(TPointer), | ||
} | ||
|
||
impl< | ||
ServerFieldTypeAssociatedData, | ||
TClientTypeSelectionScalarFieldAssociatedData, | ||
TClientTypeSelectionLinkedFieldAssociatedData, | ||
TClientTypeVariableDefinitionAssociatedData: Ord + Debug, | ||
TOutputFormat: OutputFormat, | ||
> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. weird rust fmt behavior ! Anyway, all good (it's formatting it), just surprising |
||
FieldType< | ||
&SchemaServerField< | ||
ServerFieldTypeAssociatedData, | ||
TClientTypeVariableDefinitionAssociatedData, | ||
TOutputFormat, | ||
>, | ||
&ClientPointer< | ||
TClientTypeSelectionScalarFieldAssociatedData, | ||
TClientTypeSelectionLinkedFieldAssociatedData, | ||
TClientTypeVariableDefinitionAssociatedData, | ||
TOutputFormat, | ||
>, | ||
> | ||
{ | ||
pub fn description(&self) -> Option<DescriptionValue> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's at some point consolidate these into an interface, so that e.g. the second param here can be |
||
match self { | ||
FieldType::ServerField(server_field) => server_field.description, | ||
FieldType::ClientField(client_field) => client_field.description, | ||
} | ||
} | ||
} | ||
|
||
impl<TOutputFormat: OutputFormat> | ||
FieldType<&ValidatedSchemaServerField<TOutputFormat>, &ValidatedClientPointer<TOutputFormat>> | ||
{ | ||
pub fn output_type_annotation(&self) -> TypeAnnotation<ServerObjectId> { | ||
match self { | ||
FieldType::ClientField(client_pointer) => client_pointer.to.clone(), | ||
FieldType::ServerField(server_field) => match &server_field.associated_data { | ||
SelectionType::Scalar(_) => panic!( | ||
"output_type_id should be an object. \ | ||
This is indicative of a bug in Isograph.", | ||
), | ||
SelectionType::Object(associated_data) => associated_data.type_name.clone(), | ||
}, | ||
} | ||
} | ||
} | ||
|
||
pub type ClientTypeId = ClientType<ClientFieldId, ClientPointerId>; | ||
|
||
pub type ValidatedClientType<'a, TOutputFormat> = | ||
|
@@ -299,6 +366,26 @@ impl<TSchemaValidationState: SchemaValidationState, TOutputFormat: OutputFormat> | |
} | ||
} | ||
|
||
pub fn linked_type( | ||
&self, | ||
field_id: FieldType<ServerFieldId, ClientPointerId>, | ||
) -> LinkedType< | ||
TSchemaValidationState::ServerFieldTypeAssociatedData, | ||
TSchemaValidationState::ClientTypeSelectionScalarFieldAssociatedData, | ||
TSchemaValidationState::ClientTypeSelectionLinkedFieldAssociatedData, | ||
TSchemaValidationState::VariableDefinitionInnerType, | ||
TOutputFormat, | ||
> { | ||
match field_id { | ||
FieldType::ServerField(server_field_id) => { | ||
FieldType::ServerField(self.server_field(server_field_id)) | ||
} | ||
FieldType::ClientField(client_pointer_id) => { | ||
FieldType::ClientField(self.client_pointer(client_pointer_id)) | ||
} | ||
} | ||
} | ||
|
||
/// Get a reference to a given client pointer by its id. | ||
pub fn client_pointer( | ||
&self, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice, good catch!