Closed phantom10111 closed 8 years ago
@denvned Are you going to take a look at this anytime soon?
@phantom10111, I'm sorry for replying so late.
Do you know about: https://github.com/relay-tools/relay-local-schema? Probably you can already use it with isomorphic-relay to achieve that you want, without any modifications to the isomorphic-relay code. And I think it's good, because I'd love to keep this project as simple as possible.
P.S.
Have you performed any benchmarks to compare performance of your solution to the Relay.DefaultNetworkLayer
connected to a GraphQL server on the localhost? As far as I know localhost networking is really fast...
@denvned Thanks for pointing me to relay-local-schema, I didn't know about it. It doesn't help that it's a project separate from everything else. I'll definitely check it out.
To be honest I haven't performed any benchmarks, but however fast localhost networking may be, it intuitively seems wrong to send http requests over localhost to the same process. I don't think it should ever be necessary.
Perhaps it would be worth it to at least mention relay-local-schema in the README, so that other users of isomorphic-relay will know about it?
@phantom10111 did you try https://github.com/relay-tools/relay-local-schema ? Is it working for you?
Just in case anyone is reading this, I implemented relay-local-schema and it seems to do the job fairly well for my purposes.
Currently when rendering on the server, you are suggesting to just use standard
Relay.DefaultNetworkLayer
, which will always make HTTP requests. I think it's a pretty common use case to render on the same server where GraphQL is, thus eliminating the need to send those requests.This PR adds a small utility class
LocalNetworkLayer
to do just that. All you need to do is to give it a reference to GraphQL schema and root value in the constructor, and it will execute all queries locally. It cannot handle file uploads, but if you are trying to upload files locally from your server to your server, you are doing something seriously wrong.I have also added a
graphql
peer dependency, because it is required to execute those queries locally.Of course, this will only be really useful when relay merges your PR to contextualize network layer. Then you should be able to pass a new instance with a different root value for each rendering.