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

type safety in multiple environments #299

Closed
mununki opened this issue Feb 18, 2022 · 4 comments
Closed

type safety in multiple environments #299

mununki opened this issue Feb 18, 2022 · 4 comments

Comments

@mununki
Copy link

mununki commented Feb 18, 2022

Hi, always appreciate your efforts and works!

I'm facing to have multiple environments which means multiple API endpoints. AFAIK, we can not have multiple schema files for relay config. Hence I'm gonna merge the multiple SDLs into a single schema file. At this point, I think we might have a runtime error, in case I write up the query, but if the closest relay context provider's environment doesn't work with that schema.

I think we can define this multiple environment case as a runtime issue, but is there any better way to handle it?

@zth
Copy link
Owner

zth commented Feb 19, 2022

This is tricky, because multiple schemas/environments really isn't something Relay was designed for.

My boring answer is going to be "don't do it". Is there any way you could stitch together everything under a single API? Just a slim service that stitches the schemas and delegates the resolution.

This question comes up from time to time, but unfortunately there's simply no good answer to it.

@mununki
Copy link
Author

mununki commented Feb 20, 2022

Making two APIs into a single one would be always the best solution. But, it has some circumstances not to make it. I came up with the idea to make fetchQuery in RelayEnv.res with Promise.allSettled to call both APIs and check the results from each API, then resolve the response. I didn't try it yet. This is the only workaround at this moment. Can I ask your thought and idea?

@zth
Copy link
Owner

zth commented Feb 20, 2022

I think that could work, but again, this is probably going to be very painful to maintain down the road 😃

Here's an issue on the Relay tracker about the same thing: facebook/relay#3153

Just to reiterate (I know I already said this, and I'm sure you have your reasons this cannot work for you) - If I was in the situation where I needed to query two separate APIs in the same app, I'd spend my time implementing a thin thin proxy backend that stitches the services together via schema stitching. Even if that is cumbersome (having to build and deploy another service), I strongly believe it'll be much less painful over time than the alternative. I'm assuming you might start running into naming conflicts at some point too, at which point concatenation of the schemas won't work.

Anyway, I'm interested in hearing how this works out for you. Keep us posted!

@zth
Copy link
Owner

zth commented Feb 25, 2022

@mattdamon108 I'm going to close this one for now since there's nothing to be done from the RescriptRelay side, but please feel free to add your comments to this issue about how this works out for you, so others in the same situation can benefit.

@zth zth closed this as completed Feb 25, 2022
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