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.
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.
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.
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.
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,
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With