Skip to content

Instantly share code, notes, and snippets.

@stubailo
Created November 26, 2018 17:14
Show Gist options
  • Select an option

  • Save stubailo/610f6319ef551499ffa0883d47df5d9f to your computer and use it in GitHub Desktop.

Select an option

Save stubailo/610f6319ef551499ffa0883d47df5d9f to your computer and use it in GitHub Desktop.

Revisions

  1. stubailo created this gist Nov 26, 2018.
    25 changes: 25 additions & 0 deletions ErrorProvider.jsx
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    export const ErrorProvider = (props) => {
    // This is just a link that swallows all operations and returns the same thing
    // for every request: The specified error.
    const link = new ApolloLink((operation) => {
    return new Observable((observer) => {
    observer.next({
    errors: props.graphQLErrors || [
    {message: 'Unspecified error from ErrorProvider.'},
    ],
    });
    observer.complete();
    });
    });

    const client = new ApolloClient({
    link,
    cache: new InMemoryCache(),
    });

    return (
    <ApolloProvider client={client}>
    {props.children}
    </ApolloProvider>
    );
    };