我正在尝试使用graphql运行查询,但始终出现网络错误。这是代码:
import React from 'react';
import { ThemeProvider } from 'styled-components';
import { ApolloProvider, gql } from 'react-apollo';
import { ApolloClient } from 'apollo-client';
import { HttpLink } from 'apollo-link-http';
import { InMemoryCache } from 'apollo-cache-inmemory'
import { NETWORK_INTERFACE } from './src/utils/constants'
import { colors } from './src/utils/constants';
import Main from './src/Main';
const client = new ApolloClient({
link: new HttpLink({
uri: NETWORK_INTERFACE
// http://localhost:3000/graphql
}),
cache: new InMemoryCache()
})
console.log('Tesset')
client.query({
query: gql`
query GetPosts {
getPosts {
text
_id
createdAt
}
}`
}).then(result => console.log(result));
export default class App extends React.Component {
render() {
return (
<ApolloProvider client={client}>
<ThemeProvider theme={colors}>
<Main />
</ThemeProvider>
</ApolloProvider>
);
}
}
client.query()导致以下错误。
[Unhandled promise rejection: Error: Network error: Network request failed]
* http://127.0.0.1:19001/node_modules%5Cexpo%5CAppEntry.bundle?platform=android&dev=true&minify=false&hot=false:144904:32 in ApolloError
我在后端使用graphql没问题。能够进行发布和获取等。任何帮助都将得到