How to use the apollo-link.ApolloLink.from function in apollo-link

To help you get started, we’ve selected a few apollo-link examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github revskill10 / next-template / modules / core / lib / utils / init-apollo.js View on Github external
)

  const errorLink = onError(
    ({ graphQLErrors, networkError }) => {
      if (graphQLErrors) {
        graphQLErrors.map(err => {
          store.dispatch(openSnackbar({message: err.message, autoHideDuration: 3000}))
        })
      }
      if (networkError) {
        store.dispatch(openSnackbar({message: networkError, autoHideDuration: 3000}))
      }
    }
  )

  let link = ApolloLink.from([errorLink, contextLink, httpLink])

  if (!ssrMode) {

    const wsLink = new WebSocketLink(
      createSubscriptionClient({
        wsUrl: WS_URL,
        store,
        getToken,
      })
    )
    const subscriptionLink = ApolloLink.from([errorLink, wsLink])
        
    // using the ability to split links, you can send data to each link
    // depending on what kind of operation is being sent
    link = split(
      isSubscriptionOperation,
github mbaranovski / nextjs-apollo-oauth-prisma / lib / initApollo.js View on Github external
function create(initialState) {
  const httpLink = createHttpLink({
    uri: `${uri()}/graphql`,
    credentials: "same-origin"
  });

  // Check out https://github.com/zeit/next.js/pull/4611 if you want to use the AWSAppSyncClient
  return new ApolloClient({
    connectToDevTools: process.browser,
    ssrMode: !process.browser,
    link: ApolloLink.from([
      errorLink,
      httpLink,
    ]),
    cache: new InMemoryCache().restore(initialState || {})
  });
}
github tcerdaITBA / Serverless-Graphql-Next.js-boilerplate / web / lib / withApollo.js View on Github external
graphQLErrors.forEach(err => console.error(`[GraphQL error]: Message: ${err.message}`));
    }

    if (networkError) {
      console.error(`[Network error]: ${networkError}`);
    }
  });

  const contextLink = setContext((_, { headers }) => ({
    headers: {
      ...headers,
      authorization: auth.isLogged(ctx) ? `Bearer ${auth.token(ctx)}` : ''
    }
  }));

  const link = ApolloLink.from([errorLink, contextLink, httpLink]);

  return new ApolloClient({
    link,
    ssrMode: !process.browser,
    cache: new InMemoryCache().restore(initialState || {})
  });
});
github SaraVieira / apollo-link-state-example / src / index.js View on Github external
}
        }

        cache.writeQuery({ query, data })
        return null;
      },
      resetCurrentGame: (_, d, { cache }) => {
        cache.writeData({ data : defaultState })
        return null;
      }
    }
  }
})

const client = new ApolloClient({
  link: ApolloLink.from([
    stateLink,
    new HttpLink({
      uri: 'https://api.graph.cool/simple/v1/cjbl0bxmq04570186hqlvgpmg'
    })
  ]),
  cache
})

ReactDOM.render(
  
    
      <div>
        
        
      </div>
github elastic / kibana / x-pack / plugins / siem / public / lib / compose / kibana_compose.ts View on Github external
const cache = new InMemoryCache({
    dataIdFromObject: () => null,
    fragmentMatcher: new IntrospectionFragmentMatcher({
      introspectionQueryResultData,
    }),
  });

  const observableApi = new AppKibanaObservableApiAdapter({
    basePath: chrome.getBasePath(),
    xsrfToken: chrome.getXsrfToken(),
  });

  const graphQLOptions = {
    connectToDevTools: process.env.NODE_ENV !== 'production',
    cache,
    link: ApolloLink.from(getLinks(cache)),
  };

  const apolloClient = new ApolloClient(graphQLOptions);

  const appModule = uiModules.get('app/siem');

  const framework = new AppKibanaFrameworkAdapter(appModule, uiRoutes, timezoneProvider);

  const libs: AppFrontendLibs = {
    apolloClient,
    framework,
    observableApi,
  };
  return libs;
}
github apollographql / apollo-client / packages / apollo-boost / src / index.ts View on Github external
handle.unsubscribe();
                }
              };
            }),
        )
      : false;

    const httpLink = new HttpLink({
      uri: uri || '/graphql',
      fetch,
      fetchOptions: fetchOptions || {},
      credentials: credentials || 'same-origin',
      headers: headers || {},
    });

    const link = ApolloLink.from([errorLink, requestHandler, httpLink].filter(
      x => !!x,
    ) as ApolloLink[]);

    let activeResolvers = resolvers;
    let activeTypeDefs = typeDefs;
    let activeFragmentMatcher = fragmentMatcher;
    if (clientState) {
      if (clientState.defaults) {
        cache.writeData({
          data: clientState.defaults,
        });
      }
      activeResolvers = clientState.resolvers;
      activeTypeDefs = clientState.typeDefs;
      activeFragmentMatcher = clientState.fragmentMatcher;
    }
github webiny / webiny-js / packages / demo-admin / src / config / apollo.js View on Github external
import ApolloClient from "apollo-client";
import { ApolloLink } from "apollo-link";
import { BatchHttpLink } from "apollo-link-batch-http";
import { InMemoryCache } from "apollo-cache-inmemory";
import { createAuthLink } from "webiny-app-security/components";
import { createOmitTypenameLink } from "webiny-app/graphql";

export default new ApolloClient({
    link: ApolloLink.from([
        createOmitTypenameLink(),
        createAuthLink(),
        new BatchHttpLink({ uri: process.env.REACT_APP_FUNCTIONS_HOST + "/function/api" })
    ]),
    cache: new InMemoryCache({
        addTypename: true,
        dataIdFromObject: obj => obj.id || null
    })
});
github seashell / drago / ui / src / graphql / client.js View on Github external
operation.setContext(({ headers }) => ({
    headers: {
      'X-Drago-Token': `${localStorage.getItem('drago.settings.acl.token')}`,
      ...headers,
    },
  }))
  return forward(operation)
})

const errorLink = onError(error => {
  if (DEBUG) {
    log.errors(error)
  }
})

const link = ApolloLink.from([authLink, errorLink, restLink])

const inMemoryCache = new InMemoryCache()

export default new ApolloClient({
  link,
  cache: inMemoryCache,
  connectToDevTools: true,
  typeDefs: {},
})