VulcanJS / Vulcan

🌋 A toolkit to quickly build apps with React, GraphQL & Meteor
http://vulcanjs.org
MIT License
7.98k stars 1.88k forks source link

Apollo 2 Migration #2081

Closed SachaG closed 5 years ago

SachaG commented 5 years ago

I'm opening a new thread to track my progress on the migration to Apollo 2.0 (starter repo).

Main Tasks

SachaG commented 5 years ago

Related:

Also we will now use the official Meteor/Apollo integration:

SachaG commented 5 years ago

Here's a round-up of the relevant code that will need to be migrated/refactored/discarded:

vulcan:lib client

vulcan:lib modules

vulcan:lib server

vulcan:routing

See contents of https://github.com/VulcanJS/Vulcan/tree/devel/packages/vulcan-routing/lib Currently moved to vulcan:core/client/start.jsx.

eric-burel commented 5 years ago

Here is a summary of my latest commits. Globally, beware of bugs. The current branch should work fine, but I only tested it on the example-forms of the Starter package for the moment.

Server

But... there are a few things to handle, and I am not knowledgeable enough to fix them yet:

Other things to do:

Notes from my learning:

RR4

RR4 works but I did not take a look at the second point (adding callbacks, options). See https://github.com/VulcanJS/Vulcan/issues/2096 for example

Client

SSR

I did a test with using only an Express middleware, but this can only render dead HTML, as scripts are never injected by Meteor. So I ended up using meteor/server-render onPageLoad callback, which behave mostly the same as an Express middleware. SSR is simply adding relevant HTML to the body of the response generated by Meteor. Then Apollo and React will handle the rehydratation.

Less relevant stuffs:

Note: for the moment you should be able to disable SSR by commenting the line of apollo-server that triggers the enableSSR() function.

We will have to study thoroughly existing code in vulcan:routing (thanks @xavczen for the walkthrough!), as it handles many edge cases and provides options.

Backward compatibility and Vulcan-Starter

SachaG commented 5 years ago

Using Meteor forces us to keep using apollo-sever-express, though we don't need to explicitely create an app. There are currently no example of a Meteor integration with a standalone Apollo server (so without express, using only the builtin HTTP server).

Maybe someone from the Meteor/Apollo team could help us? Or maybe @lorensr would know?

lorensr commented 5 years ago

Don't know! I had this question as well: https://github.com/apollographql/apollo-client/pull/3739#issue-203997257

lorensr commented 5 years ago

@benjamn Is there a better way to set up Apollo Server inside Meteor? We're currently recommending https://www.apollographql.com/docs/react/recipes/meteor.html#Server

eric-burel commented 5 years ago

Hi,

Actually I think I figured this out wrong in the first place. It's not apollo-server-express that spawns the Express instance, it's just a connector. You always have to pass your own Express instance. meteor/webapp does however setup a full fledged server (with connect to be precise, I guess this is mostly the same thing as Express? Not familiar with Node subtleties), with cookies, compression, etc., and your custom handlers. Code is here So apolloServer.applyMiddleware({ app: Meteor.connectHandlers }) is roughly equivalent to apolloServer.applyMiddleware({app: yourExpressServer }). And thus you have to use apollo-server-express, since under the hood you are using Express when using meteor/webapp.

So my question itself does not make sense, you can't use the Apollo builtin server, at least not using the meteor/webapp package, because it's implementation rely on Express already. Anyway in Vulcan case it's a better idea to rely on Express due to 3rd party plugins compatibility (see graphql-voyager integration tested by @Apollinaire).

Edit: To sum it up:

eric-burel commented 5 years ago

Closing in favor to https://github.com/VulcanJS/Vulcan/issues/2171