useQuery returns undefined, But returns data on gql playground

前端 未结 3 595
北荒
北荒 2021-01-13 05:11
\"@apollo/react-hooks\": \"^3.1.3\",
\"apollo-client\": \"^2.6.8\",

Apollo client return undefined on react app but return the data on gql playgrou

3条回答
  •  没有蜡笔的小新
    2021-01-13 05:57

    something that might help, you know where you call {data} you can also look for error and console.log('Error:',error)

    check the apollo client query docs

    something like this , and look at the error message, it should help !

    import { useQuery } from '@apollo/react-hooks';
    import gql from 'graphql-tag';
    
    const GET_GREETING = gql`
      query getGreeting($language: String!) {
        greeting(language: $language) {
          message
        }
      }
    `;
    
    function Hello() {
        const { loading, error, data } = useQuery(GET_GREETING, {
        variables: { language: 'english' },
      });
      if (loading) return 'Loading...';
      if (error) return `Error! ${error.message}`;
      return 

    Hello {data.greeting.message}!

    ; }

提交回复
热议问题