bytewitchcraft / apollo-absinthe-upload-link

A network interface for Apollo that enables file-uploading to Absinthe back ends.
61 stars 37 forks source link

Mutation's context.fetchOptions not being added to actual fetch event. #16

Closed baleeds closed 5 years ago

baleeds commented 5 years ago

In trying to add progress bars to file uploads, I was led to this comment, where a solution is proposed that uses a fetch wrapper for xhr to provide hooks for progress events.

  const httpLink = createUploadLink({
    uri: API_URL,
    fetch: buildAxiosFetch(axios, (config, input, init) => ({
      ...config,
      onUploadProgress: init.onUploadProgress,
    })),
  });

These hooks fire an event that is added to the fetch options, called onUploadProgress.

apolloClient.mutate({
  mutation: UPLOAD_FILE,
  variables: { file },
  context: {
    fetchOptions: {
      onUploadProgress: (progress => {
        console.info(progress);
      }),
    }
  },
});

The problem is that in apollo-absinthe-upload-link, the context.fetchOptions from a mutation are not being added to the fetch.

ihorkatkov commented 5 years ago

Hey. Thanks for the issue and PR. I merged it. Unfortunately, I am in vacation and my laptop is broken, so I will publish the library to NPM as soon as I repair my laptop

juddey commented 5 years ago

Thanks for the fix, just discoverted this today :)