profusion / apollo-federation-file-upload

Add file upload support to Apollo Federated services.
32 stars 27 forks source link

Apollo 3 Integration #31

Closed fullStackDataSolutions closed 2 years ago

fullStackDataSolutions commented 3 years ago

Hello,

When will this have Apollo 3.0 integration?

TheAschr commented 3 years ago

I am also wondering this. We upgraded to Apollo version 3 and are getting

POST body missing, invalid Content-Type, or JSON object has no keys.

when we upload files now.

softeng71 commented 3 years ago

Part of apollo server causing error is here in runHttpQuery.ts `switch (httpRequest.method) { case 'POST': if ( !httpRequest.query || typeof httpRequest.query === 'string' || Buffer.isBuffer(httpRequest.query) || Object.keys(httpRequest.query).length === 0 ) { throw new HttpQueryError( 400, 'POST body missing, invalid Content-Type, or JSON object has no keys.', ); }

  requestPayload = httpRequest.query;
  break;`
cabelitos commented 3 years ago

Not sure if you guys are aware, but apollo-server does not supports file uploads directly out-of-the-box on v3. You have to manually enabled it.

Since you`re not configuring the file-upload middleware you receive the error about:

POST body missing, invalid Content-Type, or JSON object has no keys.

Please check on how to enable it: https://github.com/apollographql/apollo-server/blob/release-3.0/docs/source/data/file-uploads.md

Please make sure you guys are using the latest version of this package as well.

Once the file upload middleware is configured on your apollo-server, everything will work fine.

In case you guys have doubts, the tests performed by this package already uses the new way to configure the file-upload support: https://github.com/profusion/apollo-federation-file-upload/blob/master/test/gateway.ts#L38, which works like a charm.

Thank you.

fullStackDataSolutions commented 3 years ago

That’s all good, but I did what it said on the Apollo site and this didn’t work. The directions are pretty vague though to be honest.

Best,

Andrew On Jul 28, 2021, 1:45 PM -0700, Guilherme Íscaro @.***>, wrote:

Not sure if you guys are aware, but apollo-server does not supports file uploads directly out-of-the-box on v3. You have to manually enabled it. https://github.com/apollographql/apollo-server/blob/release-3.0/docs/source/data/file-uploads.md Please make sure you guys are using the latest version of this package as well. Thank you. — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.

fullStackDataSolutions commented 3 years ago

It would be extremely useful to see an example of this plugin working with Apollo 3. I’m sure we are just missing some small thing. But there’s just not much data on how to do it.

Best,

Andrew On Jul 28, 2021, 12:36 PM -0700, softeng71 @.***>, wrote:

Part of apollo server causing error is here in runHttpQuery.ts switch (httpRequest.method) { case 'POST': if ( !httpRequest.query || typeof httpRequest.query === 'string' || Buffer.isBuffer(httpRequest.query) || Object.keys(httpRequest.query).length === 0 ) { throw new HttpQueryError( 400, 'POST body missing, invalid Content-Type, or JSON object has no keys.', ); } requestPayload = httpRequest.query; break; — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.

cabelitos commented 3 years ago

@blazestudios23 First of way you can't use the apollo-server stand alone package. If have to use apollo-server-express or any other installation (fastify, hapi, and etc). I'll stick with apollo-server-express which is the most used.

The first thing to do is install apollo-server-express, express and graphql-upload as dependencies.

After that you'll need to create the express app as seen in:

https://github.com/profusion/apollo-federation-file-upload/blob/master/test/gateway.ts#L37

Then you import from graphqlUploadExpress from graphql-upload and tell express to use it.

https://github.com/profusion/apollo-federation-file-upload/blob/master/test/gateway.ts#L38

After that, you create Apollo server as usual: https://github.com/profusion/apollo-federation-file-upload/blob/master/test/gateway.ts#L39

After the server is created call await server.start(), where server is the apollo-server that was created.

Then you apply the express middleware to the apollo-server:

https://github.com/profusion/apollo-federation-file-upload/blob/master/test/gateway.ts#L45

Then you're good to go. Just start express by running app.listen(): https://github.com/profusion/apollo-federation-file-upload/blob/master/test/gateway.ts#L48

Remember that you need to do these steps on all services that run apollo-server. (The gateway and all micro-services).

Let me know if you still need help.

I can create more examples on this later. (I do not have access to a computer right now)

softeng71 commented 3 years ago

Once I added the graphql-upload to the router as well all worked as expected. Thank you @cabelitos for pointing out my flaw. This works with Apollo server 3 well and I consider that this can be closed

barbieri commented 3 years ago

@cabelitos could you the required bits in our README.md, giving some highlight to that part? Lots of people moving to Apollo 3...

cabelitos commented 2 years ago

I'm closing this one, since we already support apollo v3.