首页 > 解决方案 > Graphql 响应不是来自 Apollo 客户端查询

问题描述

在我的本地http://localhost:3000/graphql查询中,如下所示... 在此处输入图像描述

但是当我通过 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);
  });

不知道我错过了什么。感谢任何帮助谢谢!

下面是截图,当我试图从前端查询时

在此处输入图像描述 在此处输入图像描述 在此处输入图像描述 在此处输入图像描述

标签: graphqlapolloreact-apolloapollo-clientexpress-graphql

解决方案


通过添加 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


推荐阅读