RevereCRE / relay-nextjs

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

Unable to parse a query variable as string #14

Closed imbhargav5 closed 3 years ago

imbhargav5 commented 3 years ago

First of all, Love this package!

I am running into a scenario where a route query that I want to parse as number chapter/2 is being used as a string with my graphql endpoint and is tripping it off. Unfortunately I can't edit the endpoint.

Is there a way to add extra options to sanitise/modify variables that will be used to load the query?

https://github.com/RevereCRE/relay-nextjs/blob/main/src/wired/component.tsx#L113

rrdelaney commented 3 years ago

See https://github.com/RevereCRE/relay-nextjs/pull/12 for more discussion on this

rrdelaney commented 3 years ago

This was implemented in 92d54f6ad5b5f871acdea5a38382ca9c32966e6f with the introduction of the variablesFromContext option.

imbhargav5 commented 3 years ago

Thanks a ton!! @rrdelaney Amazing stuff. Going to try this out! 💛

imbhargav5 commented 3 years ago

Hi @rrdelaney I tried this out. Looks like _document and hydration issues are there. The original variables from the routes are still being used in rerenders. Are there any other places where these variablesFromContext need to be used? I think something maybe missing in the preload phase.

rrdelaney commented 3 years ago

You should only need to use it at the page's config. Make sure that the function will always return the exact same values on both the client side and server side, i.e. only use the ctx param and build-time constants to derive the value.

imbhargav5 commented 3 years ago

Hmm. I have been doing that but I still see the original query values sometimes. Let me try with a fresh mind again and see. :D

rrdelaney commented 3 years ago

Oh I think there might be a bug in the implementation. I recently added support for re-loading the query when router.query changes, and it looks like the re-load doesn't call the config function. Will fix soon.

rrdelaney commented 3 years ago

Should be fixed in v0.4.0 that I just published to npm!