react-apollo 没有连接到我的 graphql 本地服务器

react-apollo is not connecting to my graphql local server

我一直在尝试使用 Apollo 连接到我的本地 GraphQL 服务器。下面是我使用 react-apollo2.0 的尝试。但是我也尝试过 react-apollo1.4createNetworkInterface,但我得到了同样的错误。

import { graphql } from 'react-apollo';
import gql from 'graphql-tag';
import { AppRegistry } from 'react-native';
import { HttpLink } from 'apollo-link-http';
import { InMemoryCache } from 'apollo-cache-inmemory';
import { ApolloClient } from 'apollo-client';
import { ApolloProvider } from 'react-apollo';

const client = new ApolloClient({
  link: new HttpLink({ uri: 'http://localhost:8000/graphql' }),
  cache: new InMemoryCache()
});

function FooList({ data: { loading, posts } }) {
  if (loading) {
    return <Text>Loading</Text>;
  } else {
      return (
        <List>
          <ListItem>
            <Left>
                <Text>John Doe5</Text>
                <Text note>(buyer)</Text>
            </Left>
            <Right>
                <Text note>21 min ago</Text>
            </Right>
          </ListItem>
        </List>
      );
  }
}

export default graphql(gql`
  query allLeads {
    id
    name
  }
`)(FooList);

const App = () => (
  <ApolloProvider client={client}>
    <FooList/>
  </ApolloProvider>
);

export default App;

我遇到的错误:

我的依赖。

  "dependencies": {
    "@expo/vector-icons": "^6.2.0",
    "apollo-client-preset": "^1.0.4",
    "expo": "^22.0.2",
    "graphql": "^0.11.7",
    "graphql-tag": "^2.6.0",
    "native-base": "^2.3.3",
    "react": "16.0.0-beta.5",
    "react-apollo": "^2.0.4",
    "react-link": "^1.0.3",
    "react-native": "^0.49.5",
    "react-navigation": "^1.0.0-beta.21"
  }

根据文档,您应该这样设置它。我的服务器没有受到攻击,我可以在 http://localhost:8000/graphql 访问图形浏览器就好了。

我在这里错过了什么?

我认为错误与 apollo 无关,您似乎在一个文件中使用了两次导出默认值,因为它是不允许的

来自 Android docs :

Each instance of the emulator runs behind a virtual router/firewall service that isolates it from your development machine network interfaces and settings and from the internet. An emulated device can't see your development machine or other emulator instances on the network. Instead, it sees only that it is connected through Ethernet to a router/firewall.

The virtual router for each instance manages the 10.0.2/24 network address space — all addresses managed by the router are in the form of 10.0.2.xx, where xx is a number. Addresses within this space are pre-allocated by the emulator/router as follows:

10.0.2.1 Router/gateway address

10.0.2.2 Special alias to your host loopback interface (i.e., 127.0.0.1 on your development machine)

10.0.2.3 First DNS server

10.0.2.4 / 10.0.2.5 / 10.0.2.6 Optional second, third and fourth DNS server (if any)

10.0.2.15 The emulated device network/ethernet interface

127.0.0.1 The emulated device loopback interface

请注意,此虚拟路由器仅供 AVD 模拟器使用,其他模拟器可能会有所不同