Skip to content
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

add magic link field #282

Merged
merged 8 commits into from
Dec 28, 2024
Merged

Conversation

PatrykWalach
Copy link
Collaborator

This is a bit awkward at places because

  • I didn't extended Loadability, should we do that?
  • I don't know what will happen when we select __link @loadably, we should validate it as part of this PR
  • type Link is not imported right know, but it's not an issue since client pointers are not implemented yet

other then that It seems to work

@rbalicki2
Copy link
Collaborator

should we name the field link? I think __link looks ugly... :-D

@PatrykWalach
Copy link
Collaborator Author

PatrykWalach commented Nov 15, 2024

And do we fail if there's a link already, or do we ignore?
Ignoring will panic when adding server pointer, but we can warn in that case.

@PatrykWalach
Copy link
Collaborator Author

PatrykWalach commented Nov 15, 2024

type Link is not imported right know, but it's not an issue since client pointers are not implemented yet

And this is an issue, because __link can be selected manually so I guess I should fix this too

@rbalicki2
Copy link
Collaborator

I think we should panic with a helpful message. Eventually we can allow the user to provide a directive in a schema extension to rename the link field if they have a clash

@rbalicki2
Copy link
Collaborator

And maybe once we have namespaces, we can have an "internal" namespace, and the user can selected internal.link and internal.asUser etc or something

No more conflicts! Idk

Copy link
Collaborator

@rbalicki2 rbalicki2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some nits, overall looks great and I really like how this is turning out! Sorry that it took me a few days to review this.

@@ -196,28 +196,53 @@ pub(crate) fn generate_eager_reader_param_type_artifact(

let mut param_type_imports = BTreeSet::new();
let mut loadable_fields = BTreeSet::new();
let mut link_fields = BTreeSet::new();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be a bool?

@@ -199,6 +199,7 @@ pub struct UserWrittenClientFieldInfo {
pub enum ClientFieldVariant {
UserWritten(UserWrittenClientFieldInfo),
ImperativelyLoadedField(ImperativelyLoadedFieldVariant),
Link,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking out loud... yes, a link field is a client field. The id aspect of it is magical, though, so yes, it sounds like it should be a separate ClientFieldVariant. Okay. Sgtm.

crates/isograph_schema/src/add_link_fields.rs Outdated Show resolved Hide resolved
crates/isograph_schema/src/add_link_fields.rs Outdated Show resolved Hide resolved
@@ -56,7 +56,31 @@ impl UnvalidatedSchema {
Span::todo_generated(),
);

let condition_selection_set = vec![typename_selection];
let link_selection = WithSpan::new(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note to self got to here

Copy link
Collaborator

@rbalicki2 rbalicki2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just one nit and an open question, but otherwise, lgtm and we should land this!!!!

location: FieldType::ClientField(
match *subtype
.encountered_fields
.get(&"link".intern().into())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can "link".intern().into() be defined in a lazy_static block and we use that everywhere?

match *subtype
.encountered_fields
.get(&"link".intern().into())
.expect("Expected link to exist")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's ideal that .encountered_fields is just a hash map. IMO it would be better to have a struct with special slots for all the special fields: __typename, an optional id, link, etc. and a hash map for all of the regular fields. that way, we don't have to do more assertions here.

#295

&scalar_field_selection.arguments,
),
None => match newly_encountered_scalar_client_field.variant {
ClientFieldVariant::Link => {}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we merge the link field's selection set here? I can't actually get it to exhibit behavior in which the typename is not selected but should be, so I think that would be unnecessary. But can we rely on that behavior?

Anyway, I don't know the right answer here, happy to go with whatever you think is best

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we don't need to merge here, we are guaranteed to have __typename since cache uses two layers now

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok Sgtm

Copy link
Collaborator

@rbalicki2 rbalicki2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just one nit and an open question, but otherwise, lgtm and we should land this!!!!

Copy link
Collaborator

@rbalicki2 rbalicki2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shipittt

@rbalicki2 rbalicki2 changed the title add magic __link field add magic link field Dec 28, 2024
@rbalicki2 rbalicki2 merged commit 3a405a0 into isographlabs:main Dec 28, 2024
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants