Upload file with GraphQl

Hello everyone!
Does anyone work with ApolloGraphQl + Rescript?
I struggle with uploading files.
How to implement apollo-upload-client ?
As I understand I should modify httpLink using the createUploadLink, and this function change content-type in my request.

let httpLink = ApolloClient.Link.HttpLink.make(~uri=_ => Env.graphqlEndpoint, ())
let client = {
  open ApolloClient
      ~mutate=DefaultMutateOptions.make(~awaitRefetchQueries=true, ~errorPolicy=All, ()),
      ~query=DefaultQueryOptions.make(~fetchPolicy=NetworkOnly, ~errorPolicy=All, ()),
      ~watchQuery=DefaultWatchQueryOptions.make(~fetchPolicy=NetworkOnly, ~errorPolicy=All, ()),
    ~link=ApolloClient.Link.from([authTokenContextLink, httpLink]),

If someone helps me with it I’ll be really appreciated

1 Like

You’ll have to write a binding to the createUploadLink function. ReScript Apollo Client is looking for an ApolloLink.t, so here’s a quick and dirty example of how that might look:

external createUploadLink: {"uri": string} => ApolloClient.Types.ApolloLink.t = "createUploadLink"

let uploadLink = createUploadLink({"uri": "..."})

FWIW, quickly looking at their documentation, it doesn’t seem like you’re intended to modify httpLink, but instead replace it entirely.


Thanks a lot. It was very helpful!