Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use apollo-link-http with apollo-upload-client?

Im trying to figure out how to use apollo-link-http with apollo-upload-client.

Both create a terminating link, but how could I use those 2 together? In my index.js I have like this, but it wont work because both links are terminating =>

const uploadLink = createUploadLink({ uri: process.env.REACT_APP_GRAPHQL_URL });

const httpLink = new HttpLink({ uri: process.env.REACT_APP_GRAPHQL_URL });

const client = new ApolloClient({
    link: ApolloLink.from([ authLink, logoutLink, stateLink, uploadLink, httpLink ]),
    cache,
});

Any help? I have not much experience with Apollo/Graphql, but I would like to use the file upload component.

like image 878
Jack M. Avatar asked Mar 27 '18 07:03

Jack M.


People also ask

How do I upload files to Apollo Client?

Set up an Apollo Server with TypeScript for file uploads. Setup your Apollo Client to upload files. Pipe an uploaded file to AWS S3. Get the URL of the uploaded file so that we can save it to our database.

What is Apollo link HTTP?

HttpLink is a terminating link that sends a GraphQL operation to a remote endpoint over HTTP. Apollo Client uses HttpLink by default when you provide the uri option to the ApolloClient constructor. HttpLink supports both POST and GET requests, and you can configure HTTP options on a per-operation basis.

How are HTTP requests sent ApolloClient authenticated?

Luckily, Apollo provides a nice way for authenticating all requests by using the concept of middleware, implemented as an Apollo Link. import { setContext } from '@apollo/client/link/context'; This middleware will be invoked every time ApolloClient sends a request to the server.


1 Answers

You do not need the http link if you use apollo-upload-client with version higher than 6.

You can try like this:

const uploadLink = createUploadLink({ uri: process.env.REACT_APP_GRAPHQL_URL });

const client = new ApolloClient({
    link: ApolloLink.from([ authLink, logoutLink, stateLink, uploadLink ]),
    cache,
});
like image 83
Locco0_0 Avatar answered Oct 19 '22 05:10

Locco0_0