chukwuyem

Client

Nov 17th, 2020
559
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React from "react";
  2. import { Meteor } from "meteor/meteor";
  3. import { render } from "react-dom";
  4. import { ApolloProvider } from "react-apollo";
  5. import ApolloClient from "apollo-client";
  6. import { createHttpLink } from "apollo-link-http";
  7. import { ApolloLink, from } from "apollo-link";
  8. import { HttpLink } from "apollo-link-http";
  9. import { InMemoryCache } from "apollo-cache-inmemory";
  10. import { meteorClientConfig } from "meteor/apollo";
  11. import { Accounts } from "meteor/accounts-base";
  12. // import ApolloClient from "apollo-boost";
  13. import { MeteorAccountsLink } from "meteor/apollo";
  14. import { DDPLink } from "apollo-link-ddp";
  15.  
  16. import App from "../../ui/App";
  17.  
  18. // const httpLink = new HttpLink({
  19. //   uri: Meteor.absoluteUrl("graphql"),
  20. // });
  21.  
  22. const authLink = new ApolloLink((operation, forward) => {
  23.   const token = Accounts._storedLoginToken();
  24.   operation.setContext(() => ({
  25.     headers: {
  26.       "meteor-login-token": token,
  27.     },
  28.   }));
  29.   return forward(operation);
  30. });
  31.  
  32. new DDPLink({
  33.   connection: Meteor.connection,
  34. });
  35.  
  36. const httpLink = new HttpLink({
  37.   uri: "/graphql",
  38. });
  39.  
  40. const cache = new InMemoryCache();
  41.  
  42. const client = new ApolloClient({
  43.   link: from([
  44.     httpLink,
  45.     // new MeteorAccountsLink({ headerName: "meteor-login-token" }),
  46.     authLink,
  47.   ]),
  48.   cache,
  49. });
  50.  
  51. const ApolloApp = () => (
  52.   <ApolloProvider client={client}>
  53.     <App />
  54.   </ApolloProvider>
  55. );
  56.  
  57. Meteor.startup(() => {
  58.   render(<ApolloApp />, document.getElementById("app"));
  59. });
  60.  
RAW Paste Data