I'm not getting full error throw from Apollo server, just get stacktrace of error. I need to get full error. how to config?

I need to get full error as: enter image description here enter image description here But on component just get: enter image description here

enter image description here I have resolver:

Mutation: {
    signUp: (parent, args) => {
      console.log('args', args);

      const validationErrors = {};
      if (!args.name) {
        validationErrors.name = ('Name is required')
      }

      if ( !args.email ) {
        validationErrors.email = ('Email is required')
      }

      if ( !args.password ) {
        validationErrors.password = ('Password is required')
      }

      if (_.find(authors, {email: args.email})) {
        validationErrors.email = ('This email already exists')
      }

      if (Object.keys(validationErrors).length > 0) {
        throw new UserInputError(
          'Failed to get events due to validation errors',
          { validationErrors }
        );
      }

config client:

import React, { Suspense, useState, useEffect } from 'react';
import { Spinner } from 'react-bootstrap'

//style
import './App.css';
// import './themes/bootstrap/bootstrap.css'

import { ApolloProvider } from 'react-apollo'
import { ApolloClient } from 'apollo-client';
import { InMemoryCache } from 'apollo-cache-inmemory';
import { createHttpLink } from 'apollo-link-http';
import { persistCache } from 'apollo-cache-persist';

import { withClientState } from 'apollo-link-state';
import { ApolloLink } from 'apollo-link';
import { onError } from "apollo-link-error";

import resolvers from './apollo/resolvers'
import defaults from './apollo/defaults'
import AppRoute from './AppRoute'

function App() {

  const [client, setClient] = useState(null)

  async function createClient() {
    const cache = new InMemoryCache({
      dataIdFromObject: object => {
        switch (object.__typename) {
          //loggedUser is whatever type "me" query resolves to
          case 'loggedUser': return object.__typename;
          case 'PostResponse': return object.__typename;
          default: return object.id || object._id;
        }
      }
    });

    // Create an http link
    const httpLink = createHttpLink({
      uri: 'http://localhost:4000',
    });
    const error = onError(({ graphQLErrors, networkError }) => {
      if (graphQLErrors) {
        console.log(graphQLErrors)
      }

      if (networkError) {
        console.log(networkError)
      }

    })
    const stateLink = withClientState({
      cache,
      resolvers,
      defaults
    });

    try {
      // See above for additional options, including other storage providers.
      await persistCache({
        cache,
        storage: window.localStorage,
      });
    } catch (error) {
      console.error('Error restoring Apollo cache', error);
    }

    // const defaultOptions = {
    //   watchQuery: {
    //     fetchPolicy: 'cache-and-network',
    //     errorPolicy: 'all',
    //   },
    //   query: {
    //     fetchPolicy: 'cache-and-network',
    //     errorPolicy: 'all',
    //   },
    //   mutate: {
    //     errorPolicy: 'all',
    //   },
    // };

    const client = new ApolloClient({
      link: ApolloLink.from([
        error,
        httpLink,
        stateLink,
        cache
      ]),
      cache,
      // defaultOptions,
      connectToDevTools: true
    });

    //update state
    setClient(client)
  }

  useEffect(() => {
    createClient()
  },[])

  return !client ? (
    <div className='wrap-loading'>
      <Spinner animation="border" variant="primary" />
    </div>
  ) : (
    <div className="App">
      <ApolloProvider client={client}>
        <Suspense fallback={()=> <Spinner animation="border" variant="primary" />}>
          <AppRoute />
        </Suspense>
      </ApolloProvider>
    </div>
  )
}

export default App

I need get the full error on component, current just gets stacktrace on component:

return (
    <Mutation
      mutation={CREATE_USER}
      onCompleted={ () => props.history.push('/login') }
      errorPolicy="all"
    >
      {(signUp, { data, loading, error }) => {
        console.log('error', error)

0 Answers