2017-12-11 5 views
0

私はApolloを使用して自分のローカルGraphQLサーバに接続しようとしています。以下はreact-apollo2.0を使った私の試みです。でも、react-apollo1.4createNetworkInterfaceで試してみましたが、同じエラーが発生しています。私は取得していますreact-apolloが私のgraphqlローカルサーバに接続していません

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; 

エラー:

enter image description here

私の依存関係。

"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でアクセスできます。

私はここで何が欠けていますか?

+0

モバイルプロジェクトと同じプロジェクトにサーバーがありますか? –

+0

いいえ、これはDjangoサーバーです。 –

+0

'localhost'の代わりに192.168.1.4のようなローカルIPアドレスを使用してみてください – Dyo

答えて

1

許可されていないので、あなたは一つのファイルに二回のエクスポートのデフォルトを使用しているようだと思う:

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エミュレータでのみ使用されますが、他のエミュレータとは異なる場合があります

0

私はアポロに関連しないエラーは、それはAndroid docsから

関連する問題