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] Isograph router integration #252

Open
rbalicki2 opened this issue Nov 5, 2024 · 0 comments
Open

[epic] Isograph router integration #252

rbalicki2 opened this issue Nov 5, 2024 · 0 comments

Comments

@rbalicki2
Copy link
Collaborator

This is a sketch of how routing in Isograph might work.

  • Certain entrypoints are associated with URLs, e.g. entrypoint Query.PetDetailPage($id: ID!) associated with pet/:id.
  • At build time, a type is generated, such as:
type AnyRoute = {
  kind: 'Query.PetDetailPage',
  params: { id: number },
} | /* other routes */

creating an instance of this type is assumed to be cheap. i.e. doing so doesn't send a network request!

  • Client fields have a navigateToEntrypoint function, e.g.:
function MyClientField({ data, navigateToEntrypoint, preloadEntrypoint }) {
  const onClick = () => navigateToEntrypoint({ kind: 'Query.PetDetailPage', params: { id: 123 } });
}
  • The router has a generated function that turns an AnyRoute object into what we need:
function preloadRoute(route: AnyRoute, shouldFetch: ShouldFetch): RouteState {
  switch (route.kind) {
    case 'Query.PetDetailPage': {
      // pseudo code here
      const entrypointImport = import('../__isograph/Query/PetDetailPage/entrypoint.tsx')
      entrypointImport.then(value => makeNetworkRequest(value.entrypoint);
      return entrypointImport;
    }
  }
}
  • Certain entrypoints can be pre-loaded (i.e. hard required) in the router if you choose
  • In particular, we can probably pre-fetch: nothing, just the NetworkRequestInfo (with or without normalization Ast), the NetworkRequestInfo and the readerWithRefetchQueries, etc.

THIS WILL BE SO GOOD

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

1 participant