Graphql响应不是来自Apollo客户端查询

时间:2020-03-02 10:16:55

标签: graphql apollo react-apollo apollo-client express-graphql

在我的本地http://localhost:3000/graphql查询中,其工作方式如下所示... enter image description here

但是当我通过apollo客户端查询时,其响应为空

import {InMemoryCache, gql, ApolloClient, HttpLink} from 'apollo-boost';
const cache = new InMemoryCache();
const client = new ApolloClient({
  cache,
  link: new HttpLink({
    uri: 'http://localhost:3000/graphql',
    credentials: 'same-origin',
  }),
  },
});

client
  .query({
    query: gql`
      {
        brands {
          _id
        }
      }
    `,
  })
  .then(data => console.log(data))
  .catch(error => {
    // its coming in this section
    console.log(error);
  });

不知道我在想什么。任何帮助表示赞赏,谢谢!!!

下面是我尝试从前端进行查询时的屏幕截图

enter image description here enter image description here enter image description here enter image description here

1 个答案:

答案 0 :(得分:2)

通过添加app.js解决

global.XMLHttpRequest = global.originalXMLHttpRequest || global.XMLHttpRequest;
global.FormData = global.originalFormData || global.FormData;

if (window.FETCH_SUPPORT) {
  window.FETCH_SUPPORT.blob = false;
} else {
  global.Blob = global.originalBlob || global.Blob;
  global.FileReader = global.originalFileReader || global.FileReader;
}

参考:https://github.com/jhen0409/react-native-debugger/issues/382#issuecomment-544226529