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

[epic] Inlined client pointers #360

Open
rbalicki2 opened this issue Feb 1, 2025 · 5 comments
Open

[epic] Inlined client pointers #360

rbalicki2 opened this issue Feb 1, 2025 · 5 comments

Comments

@rbalicki2
Copy link
Collaborator

rbalicki2 commented Feb 1, 2025

  • Client pointers by default create a follow up request, e.g.
iso(`
  pointer User.bestFriend to User {
    friends { id, closeness }
  }
`)(({ data }) => returnIdOfFriendWithMaxCloseness(data.friends))

iso(`
  field User.SomeField {
    bestFriend { name }
  }
`)(...)

would result in the parent query containing friends { id, closeness } and another request for node(id: $bestFriendId) { ... on User { name } }.

  • Instead, we should allow users to inline the selections of the client pointer into the parent field, e.g. in the above case issuing the query friends { id, closeness, name } (i.e. overfetching)

Other tasks

  • sub task refetch fields should be optional: The original assumption (by bad!) was that the refetch field would not be optional, because a client pointer will always result in a follow-up request. But that's not true! We can inline the client pointer results in the parent query, and avoid a follow up request. At this point, we don't need a refetch strategy. So, the task is to make the refetch field optional. This can be done as part of the work to support inlining.
@rbalicki2 rbalicki2 changed the title Client pointer refetch field should be optional [epic] Inlined client pointers Feb 1, 2025
@PatrykWalach
Copy link
Collaborator

How do we know where to inline the fields?

@rbalicki2
Copy link
Collaborator Author

Not sure. Directive in SomeField, I would think.

@PatrykWalach
Copy link
Collaborator

There should be one in bestFriend on friends to mark the spot, then another in SomeField to opt into in-lining?

@rbalicki2
Copy link
Collaborator Author

Great point. Yes you're right.


This works well with the project to make the parameter type of the pointer generic, in order to force you to return an ID you received from the parameter.

ie BestFriendPointer and expect a return value of T, and have all the potential target IDs be replaced with T (or links?)


Of course one should be able to not inline and thus return an arbitrary link, e.g. one stored in local state, in which case the parameter can't be generic

@rbalicki2
Copy link
Collaborator Author

rbalicki2 commented Feb 2, 2025

Actually one should be able to do both for the same pointer, so I guess the return type can be T (only inline), T |Link<User> (both) or Link (only external or never inlined)

We can probably do some cool stuff at runtime, like tagging the Link with an additional prop or putting it in a set, in order to warn if the user returns a Link from the parameter without indicating it could be inlined

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

No branches or pull requests

2 participants