OneGraph/graphiql-code-exporter

Correct reason-apollo Query format

Closed this issue · 0 comments

let inMemoryCache = ApolloInMemoryCache.createInMemoryCache();

let serverUrl = "https://serve.onegraph.com/dynamic?app_id=...";

let httpLink =
  ApolloLinks.createHttpLink(~uri=serverUrl, ~credentials="include", ());

let auth = OneGraphAuth.newAuth(OneGraphAuth.config);

let authLink =
  ApolloLinks.createContextLink(
    OneGraphAuth.(
      () => {
        "headers": {
          "authorization": auth |> authHeaders |> authenticationHeaderGet,
        },
      }
    ),
  );

let instance =
  ReasonApollo.createApolloClient(
    ~link=ApolloLinks.from([|authLink, httpLink|]),
    ~cache=inMemoryCache,
    (),
  );

module Test = [%graphql
  {|
query test($email: String!, $limit: Int = 50) {
  clearbit {
    enrich(email: $email) {
      company {
        twitter {
          timeline(first: $limit) {
            tweets {
              id
            }
          }
        }
      }
    }
  }
}
|}
];

module TestQuery = ReasonApollo.CreateQuery(Test);

let component = ReasonReact.statelessComponent("TestComp");

let make = (~email, ~limit=? _children) => {
  ...component,
  render: _ => {
    let payload = Test.make(~email, ~limit, ());
    <TestQuery variables=payload##variables>
      ...(
           ({result}) =>
             switch (result) {
             | Loading => <div> (ReasonReact.string("Loading")) </div>
             | Error(error) =>
               <div> (ReasonReact.string(error##message)) </div>
             | Data(response) =>
               <div>
                 <pre>
                   (
                     response
                     |> Js.Json.stringifyAny
                     |> Belt.Option.getExn
                     |> ReasonReact.string
                   )
                 </pre>
               </div>
             }
         )
    </TestQuery>;
  },
};