3

when I'm trying to upload file via Graphql mutation (apollo-angular) with parameter $file: Upload!, the variable value is shown as an empty object in developer tools: value of file variable is empty object

But I'm checking the value of the variable right before the request and the value is correct, it is in fact a File, not an empty object.

import gql from 'graphql-tag';
import { Apollo } from 'apollo-angular';

  this.apollo.mutate(
    {
      mutation: gql`
        ${uploadMutation}
      `,
      variables: {
        companyId,
        file <-- Here the value is correct, it is a File
      },
      context: {
        hasUpload: true,
        useMultipart: true
      }
    },
    'upload'
  );

Code is simplified for the sake of this example.

Is it just developer tools issue, am I doing something wrong or what is the problem please?

Laker
  • 1,622
  • 4
  • 20
  • 32
  • https://github.com/jaydenseric/graphql-multipart-request-spec – xadm Oct 25 '21 at 15:36
  • Based on this, it looks like my implementation is correct, no? @xadm – Laker Oct 26 '21 at 08:17
  • not ... do you see FormData request, `operations` field and `file` nulled? – xadm Oct 26 '21 at 11:19
  • Did you figure it out yet? – Rooh Al-mahaba Aug 30 '22 at 10:55
  • I didn't so I completely reworked it and found out that there was a problem with FormData in the first place. If I remember correctly, when creating the project, some properties were causing a problem. I'm not sure, I don't have access to the repo so I can't refresh my memory, sorry. – Laker Sep 20 '22 at 08:25

1 Answers1

0

You have to config the Apollo client with this:

import { createUploadLink } from 'apollo-upload-client'

const link = createUploadLink(/* Options */)

Resource: https://github.com/jaydenseric/apollo-upload-client/issues/89#issuecomment-384923295

Malus
  • 39
  • 5