-
Notifications
You must be signed in to change notification settings - Fork 43
GraphQL/Apollo Support #1223
Comments
Hi @chrischen, You can easily refactor out the Aphrodite code if you are not using it. |
If you wanted to do this without a plugin, you could try to do something similar. You inject data by using |
Will take a look at the plugin method, but for the injecting script tag method, where would I do that from the application code? I'm assuming the script tag would be parsed after mounting which might be after when I would normally initialize ApolloProvider? |
A couple of things you do to determine when you are on the server or on the client:
In the browser |
Ok I decided to go with the non-plugin method so that I could keep client and server Apollo code relatively synchronized. For anyone else wondering how to implement this here are the steps I took: src/apps/main/Index.js
src/apps/main/routes.js |
Ok I found an issue with this implementation. The ApolloClient sometimes may need to send HTTP headers (for authorization, cookies, etc), which in my case are stored in cookies and sent to the server as part of the request headers. On browser renders I can access cookies, but on initial server renders I can't seem to access cookies until inside a container component. From what I can tell, I can only access serverProps or renderProps to access headers/cookies from the Is there any way to access the gluestick http headers from src/main/Index.js or from routes.js? |
The function used to return routes in routes.js gets passed the This is pretty buried but it's all done around here https://github.com/TrueCar/gluestick/blob/55d1da8c6fe9f81fe70629942c4126838f16d448/packages/gluestick/src/generator/templates/EntryWrapper.js |
So, if you use the |
I'm using Apollo's HttpLink which would do its own HTTP request. Is there any way to extract the cookies that are cached from the axios instance from the client request? |
Maybe you can use an axios instance with HttpLink with https://github.com/lifeomic/axios-fetch ? |
Ok I'll try that and report back. On that topic though, is there a way to use axios from redux-middlewares? I've been using isomorphic-fetch in a middleware and using cookies set in redux store from gsBeforeRoute. |
Yes, if you use the built in promise middleware it exposes
|
As it turns out when I wrapped So that brings me back to square 1. I got it to partially work by wrapping the My requirements are:
Potential workarounds:
|
Ok here's the final solution: gluestick/EntryWrapper.js MasterLayout.js
|
I'm trying to implement Apollo-client support while maintaining server-side-rendering compatibility. It seems that I can add ApolloProvider in the routes.js file but the only way to access application state (that can be passed to client) is through the redux store (not ideal as redux is superseded by apollo-client and its ability to manage client-only data). Is there a way to inject data to the "window" object from any of the application-side code to hydrate the apollo store on the client from data from the server render?
The text was updated successfully, but these errors were encountered: