RevereCRE / relay-nextjs

⚡️ Relay integration for Next.js apps
https://reverecre.github.io/relay-nextjs/
MIT License
251 stars 30 forks source link

Redirect post query on relay-nextjs v2 #87

Closed julioxavierr closed 1 year ago

julioxavierr commented 1 year ago

Hi everyone,

I'm migrating from relay-nextjs v1 to v2, following the example migration. Everything seems to be working as expected and the new set up process is much simpler.

However, in my app there are some pages where the user is conditionally redirected based on data - that is, depending on some user info in the database, they are redirected to another page. Previously, we used serverSidePostQuery to do this:

export default withRelay(Report, ReportQuery, {
  serverSidePostQuery: (result, context) => {
    if (!viewerCanSee(result.data)) {
      context.res?.writeHead(302, { Location: "/dashboard" });
      context.res?.end();
    }
  },
});

With the upgrade to v2, this callback has been removed. I'd like to understand more about what the recommended strategy is for this use case. I'm also interested in contributing if necessary.

Thanks for your help.

FINDarkside commented 1 year ago

Seems like I'm going to have the same kind of problem when upgrading. We're using serverSidePostQuery to set HTTP 404 status when the requested entity isn't found. Haven't really looked into alternative ways to do it with 2.0 yet.

E: Lol forgot I was the one who added serverSidePostQuery in the first place 😄 #74 So I'll probably look into some way to make the same thing with v2 unless one already exist, but I'm not sure yet when we're going to upgrade. Could be a while.

rrdelaney commented 1 year ago

This was an unintended removal, I'll make sure it's fixed soon!

rrdelaney commented 1 year ago

This should be fixed in v2.0.1. Apologies for the breakage and thank you for opening this issue! Please re-open this issue if you continue to experience issues with this API or fetchPolicy.

julioxavierr commented 1 year ago

@rrdelaney wow, that was fast! Thank you!