2

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
  make(
    ~cache=Cache.InMemoryCache.make(),
    ~connectToDevTools=true,
    ~defaultOptions=DefaultOptions.make(
      ~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

Ihar
  • 31
  • 2

1 Answers1

1
@module("apollo-upload-client")
external createUploadLink: {"uri": string} => ApolloClient.Types.ApolloLink.t = "createUploadLink"

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

and one of my mistakes was that I tried to use my own types for File instead of standard Js.Json.t when got the data from the input

Ihar
  • 31
  • 2