From ccf3d4d7427fcc6aecad69dcc35e81a47ab93e2f Mon Sep 17 00:00:00 2001 From: Guillaume Chau Date: Sun, 28 Nov 2021 19:10:52 +0100 Subject: [PATCH] docs: add error handling link example --- .../src/guide-composable/error-handling.md | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/packages/docs/src/guide-composable/error-handling.md b/packages/docs/src/guide-composable/error-handling.md index 5d86151..94617d6 100644 --- a/packages/docs/src/guide-composable/error-handling.md +++ b/packages/docs/src/guide-composable/error-handling.md @@ -102,6 +102,33 @@ const link = onError(error => { That way it will be dropped when compiling the project for production. +Full example: + +```js +import { ApolloClient, InMemoryCache, createHttpLink } from '@apollo/client/core' +import { onError } from '@apollo/client/link/error' +import { logErrorMessages } from '@vue/apollo-util' + +const cache = new InMemoryCache() + +// HTTP connection to the API +let httpLink = createHttpLink({ + uri: 'http://localhost:4242/graphql', +}) + +// Handle errors +const errorLink = onError(error => { + if (process.env.NODE_ENV !== 'production') { + logErrorMessages(error) + } +}) + +export const apolloClient = new ApolloClient({ + cache, + link: errorLink.concat(httpLink), +}) +``` + #### Options Error Link takes a function that is called in the event of an error. This function is called with an object containing the following keys: