peace
peace

Reputation: 57

file upload in react.js using apollo client

i was trying to upload file to my apollo server but i can't upload any file and it does not throw any error but i receive only empty object in resolver and it works find when i use GraphQL Client like Altair

output in server when using Altair Client

{
    filename: 'Copy of Massive Orange Summer Sale Animated-300x250px-MediumRectangle.png',
    mimetype: 'image/png',
    encoding: '7bit',
    createReadStream: [Function: createReadStream]
}

output in server when using @apollo/client package

{}

client code

client code

server code

server code

Upvotes: 2

Views: 7468

Answers (1)

Daniel Rearden
Daniel Rearden

Reputation: 84657

Uploads are not supported in Apollo Client by default. If you want to enable them, you need to use createUploadLink from apollo-upload-client as shown here.

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

const client = new ApolloClient({
  cache: new InMemoryCache(),
  link: createUploadLink(),
});

Upvotes: 6

Related Questions