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

Recursive union types can not be used in Remix app #129

Open
estyrke opened this issue Jun 30, 2023 · 2 comments
Open

Recursive union types can not be used in Remix app #129

estyrke opened this issue Jun 30, 2023 · 2 comments

Comments

@estyrke
Copy link

estyrke commented Jun 30, 2023

As described in #108, when making a query on a union, the result type will include all fields of the union regardless if they were selected or not. This causes issues with recursive types in e.g. Remix loader functions.

See CodeSandbox at https://codesandbox.io/p/sandbox/xenodochial-hill-qckj7d for an example - the error is in app/routes/_index.tsx at line 22.

@remorses
Copy link
Owner

This looks like a problem with Remix very complex typescript type, i would just do this to fix the issue

export const loader = async (_args: LoaderArgs) => {
  const client = createClient({
    url: new URL("/graphql", _args.request.url).href,
  });
  const { me } = await client.query({ me: { id: true, firstname: true } });
  return ({ currentUser: me });
};

export default function Index() {
  const data: Awaited<ReturnType<typeof loader>> = useLoaderData<any>();

@estyrke
Copy link
Author

estyrke commented Jun 30, 2023

Thanks for the quick feedback! The reason for the json call is that the loader runs on the server and is sent serialized to the client. So some types, such as Dates will then be typed as Date in the Index function running on the client, while they have actually been converted to a string by Remix (I think that's what the Serialize* types are supposed to handle). But yeah, in this case it seems to work.

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