How to use apollo-link-error - 10 common examples

To help you get started, we’ve selected a few apollo-link-error 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 SolidZORO / leaa / packages / leaa-www / src / libs / apollo-client.lib.ts View on Github external
});

  const authLink = new ApolloLink((operation, forward) => {
    const token = isServer ? authToken : authUtil.getAuthToken();

    operation.setContext({
      headers: {
        Authorization: token ? `Bearer ${token}` : '',
      },
    });

    // @ts-ignore
    return forward(operation);
  });

  const errorLink = onError(({ graphQLErrors }) => {
    if (graphQLErrors) {
      graphQLErrors.forEach(error => {
        console.error(`❌ [GraphQL error]: ${JSON.stringify(error)}`);

        // messageUtil.gqlError(error.message);
      });
    }
  });

  const terminatingLink = split(
    ({ query: { definitions } }) =>
      definitions.some(node => {
        const { kind } = node as OperationDefinitionNode;

        return kind === 'OperationDefinition';
      }),
github notadd / ng-notadd / src / app / graphql / graphql.module.ts View on Github external
});

        return forward(operation);
    });

    // Afterware
    const afterwareLink = new ApolloLink((operation, forward) => {
        return forward(operation).map(response => {
            const { response: { headers } } = operation.getContext();

            return response;
        });
    });

    // Error link
    const errorLink = onError(({ graphQLErrors, networkError }) => {
        if (graphQLErrors) {
            graphQLErrors.map(({ message, locations, path }) =>
                console.log(
                    `[GraphQL error]: Message: ${message}, Location: ${locations}, Path: ${path}`
                )
            );
        }
        if (networkError) {
            console.log(`[Network error]:`, networkError);
        }
    });

    return {
        link: ApolloLink.from([authFlowLink, authMiddleware, afterwareLink, errorLink, http]),
        cache: new InMemoryCache(),
    };
github janhartmann / flight-spotter / client / src / data / apollo.ts View on Github external
import { ApolloClient } from "apollo-client";
import { createHttpLink } from "apollo-link-http";
import {
  InMemoryCache,
  IntrospectionFragmentMatcher
} from "apollo-cache-inmemory";
import { onError } from "apollo-link-error";

import introspectionResultData from "./generated-types";

const httpLink = createHttpLink({
  uri: process.env.FLIGHT_SPOTTER_SERVER || "http://localhost:5000"
});

const errorLink = onError(({ graphQLErrors, networkError }) => {
  if (graphQLErrors) {
    // tslint:disable-next-line:no-console
    console.error("Error Fetching Data", graphQLErrors);
  }

  if (networkError) {
    // tslint:disable-next-line:no-console
    console.error(networkError);
  }
});

export const client = new ApolloClient({
  link: errorLink.concat(httpLink),
  defaultOptions: {
    watchQuery: {
      errorPolicy: "all"
github leighhalliday / github-stars-graphql / src / apolloClient.js View on Github external
import { onError } from "apollo-link-error";

// const client = new ApolloClient({
//   uri: "https://api.github.com/graphql",
//   request: operation => {
//     operation.setContext({
//       headers: {
//         Authorization: `bearer ${sessionStorage.getItem("token")}`
//       }
//     });
//   }
// });

const cache = new InMemoryCache();

const errorLink = onError(({ graphQLErrors, networkError, operation }) => {
  if (graphQLErrors) {
    graphQLErrors.forEach(({ message, path }) =>
      console.log(`[GraphQL error]: Message: ${message}, Path: ${path}`)
    );
  }

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

const authLink = setContext((_, { headers }) => {
  const context = {
    headers: {
github cdmbase / fullstack-pro / servers / frontend-server / src / config / apollo-client.ts View on Github external
import apolloLogger from 'apollo-link-logger';

import { PUBLIC_SETTINGS } from '../config/public-config';
import modules from '../modules';
import { logger } from '@cdm-logger/client';
import { merge } from 'lodash-es';
import { invariant } from 'ts-invariant';

// TODO: add cache redirects to module
const cache = new InMemoryCache({ dataIdFromObject: (result) => modules.getDataIdFromObject(result) });
const schema = `
type Query {}
type Mutation {}
`;

const errorLink = onError(({ graphQLErrors, networkError }) => {
    if (graphQLErrors) {
        graphQLErrors.map(({ message, locations, path }) =>
            // tslint:disable-next-line
            invariant.warn(
                `[GraphQL error]: Message: ${message}, Location: ` +
                `${locations}, Path: ${path}`,
            ),
        );
    }
    if (networkError) {
        // tslint:disable-next-line
        invariant.warn(`[Network error]: ${networkError}`);
    }
});
let link;
if (__CLIENT__) {
github apollographql / apollo-client / packages / apollo-boost / src / index.ts View on Github external
let { cache } = config;

    invariant(
      !cache || !cacheRedirects,
      'Incompatible cache configuration. When not providing `cache`, ' +
        'configure the provided instance with `cacheRedirects` instead.',
    );

    if (!cache) {
      cache = cacheRedirects
        ? new InMemoryCache({ cacheRedirects })
        : new InMemoryCache();
    }

    const errorLink = errorCallback
      ? onError(errorCallback)
      : onError(({ graphQLErrors, networkError }) => {
          if (graphQLErrors) {
            graphQLErrors.forEach(({ message, locations, path }) =>
              // tslint:disable-next-line
              invariant.warn(
                `[GraphQL error]: Message: ${message}, Location: ` +
                  `${locations}, Path: ${path}`,
              ),
            );
          }
          if (networkError) {
            // tslint:disable-next-line
            invariant.warn(`[Network error]: ${networkError}`);
          }
        });
github oughtinc / mosaic / client / src / graphqlClient.ts View on Github external
import { InMemoryCache } from "apollo-cache-inmemory";
import ApolloClient from "apollo-client";
import { HttpLink } from "apollo-link-http";
import { ApolloLink } from "apollo-link";
import { onError } from "apollo-link-error";
import { getUserAccessToken } from "./auth/getUserAccessToken";
import { getUserId } from "./auth/getUserId";

const SERVER_URL =
  window.location.hostname === "localhost"
    ? "http://localhost:8080/graphql"
    : `${window.location.protocol}//${window.location.hostname}/graphql`;

const errorLink = onError(({ graphQLErrors, networkError }) => {
  if (graphQLErrors) {
    graphQLErrors.map(({ message, locations, path }) =>
      console.log(
        `[GraphQL error]: Message: ${message}. Path: ${path}. Location: `,
        locations,
      ),
    );
  }
  if (networkError) {
    console.log(`[Network error]: ${networkError}`);
  }
});

const authLink = new ApolloLink((operation, forward) => {
  operation.setContext(context => ({
    ...context,
github tcerdaITBA / Serverless-Graphql-Next.js-boilerplate / web / lib / withApollo.js View on Github external
export default withApollo(({ ctx, initialState }) => {
  const httpLink = new HttpLink({
    uri: process.env.API_URL,
    fetch
  });

  const errorLink = onError(({ graphQLErrors, networkError }) => {
    if (graphQLErrors) {
      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)}` : ''
    }
  }));
github ff14wed / aetherometer / ui / src / api / gqlClient.ts View on Github external
import * as gql from './gql';

import { ApolloLink, execute, makePromise, GraphQLRequest, FetchResult } from 'apollo-link';
import { HttpLink } from 'apollo-link-http';
import { fetch } from 'apollo-env';

import { WebSocketLink } from './wsLink';
import { onError } from 'apollo-link-error';

const errHandlerLink = onError(({ graphQLErrors, networkError }) => {
  if (graphQLErrors) {
    graphQLErrors.map((e) => {
      throw e;
    });
  }
  if (networkError) { throw networkError; }
});

const executeOperation = (
  httpLink: ApolloLink, operation: GraphQLRequest, credentials: string,
) => {
  operation.context = {
    headers: {
      authorization: `Bearer ${credentials}`,
    },
  };

apollo-link-error

Error Apollo Link for GraphQL Network Stack

MIT
Latest version published 5 years ago

Package Health Score

64 / 100
Full package analysis

Popular apollo-link-error functions

Similar packages