jaydenseric / graphql-multipart-request-spec

A spec for GraphQL multipart form requests (file uploads).
993 stars 54 forks source link

Request payload has no file content #40

Closed codeashian closed 3 years ago

codeashian commented 3 years ago

Hi!

I have an issue when posting a file using apollo-client (I am posting to apollo-server-lambda). The POST request looks like this, in other words, it's empty where the file content should be (I think?)

{"1":["variables.file"]}
------WebKitFormBoundaryms9IIBb8QTb29vwl
Content-Disposition: form-data; name="1"; filename="74b233b0.jpg"
Content-Type: image/jpeg

------WebKitFormBoundaryms9IIBb8QTb29vwl--

The file sent to the server looks like this:

File {
  lastModified: 1598943888000,
  lastModifiedDate: Tue Sep 01 2020 09:04:48 GMT+0200 (Central European Summer Time){},
  name: "IMG_2439.JPG",
  size: 3955743,
  type: "image/jpeg",
  webkitRelativePath: ",
  __proto__: File
}

I'm using apollo-client-server like this:

  ....
  return new ApolloClient({
    ssrMode: typeof window === "undefined",
    link: createUploadLink({
      uri: "my-uri",
      headers: {
        authorization: `Bearer ${token}`,
      },
    }),
    cache: new InMemoryCache(),
  });

And here's my typedefs

gql`
  mutation createPerson($person: PersonInput!, $file: Upload!) : String
`

And the mutation query looks like this:

  createPerson({
      variables: { person: person, file: image },
      update: updateCache,
    });

I don't think I can google my problem more than I have. I would really appreciate som help <3

jaydenseric commented 3 years ago

Closing because this issue is more a usage question about an implementation of the GraphQL multipart request spec, whereas this repo is about documenting the spec itself.

I have an issue

What exactly is the issue? Is there an error message, and is it on the client or server?

it's empty where the file content should be (I think?)

Probably the data is there; the Chrome network inspector just hides the huge binary blob of data. Here is an example that is working:

Screen Shot 2020-09-23 at 12 03 26 am Screen Shot 2020-09-23 at 12 06 29 am

I'm using apollo-client-server like this:

Did you mean to say apollo-upload-client?

Note that graphql-upload doesn't officially support AWS Lambda; as a platform AWS Lambda isn’t very friendly to file uploads because it doesn't stream in requests. You can read more about it here:

https://github.com/jaydenseric/graphql-upload/issues/155#issuecomment-632998596

Despite this, apollo-server-lambda does support the GraphQL multipart request spec. If you think you have found a bug with it it's best to raise an issue in their repo :)