【发布时间】:2018-06-23 01:20:15
【问题描述】:
我正在尝试使用此代码设置 react-apollo:
import React from 'react';
import {render} from 'react-dom';
import gql from 'graphql-tag';
import { ApolloProvider, graphql } from 'react-apollo';
import { ApolloClient } from 'apollo-client';
import { HttpLink } from 'apollo-link-http';
import { InMemoryCache } from 'apollo-cache-inmemory';
const client = new ApolloClient({
link: new HttpLink({ uri: 'http://localhost:5000/graphql' }),
cache: new InMemoryCache()
});
class App extends React.Component {
render () {
return <p> Hello React project</p>; }
}
const MY_QUERY = gql`query Hello { hello }`;
const AppWithData = graphql(MY_QUERY)(App)
render(
<ApolloProvider client={client}>
<AppWithData />
</ApolloProvider>,
document.getElementById('app')
);
查看 chrome 开发工具中的“网络”选项卡,我可以看到请求正在通过:
我想知道是否可能缺少一些配置设置来获得正确格式的响应?或者我可能需要以不同的格式从我的 graphql 端点返回数据?任何建议都值得赞赏,我只是在学习 graphql 和 apollo,所以它可能是非常明显的。谢谢!
【问题讨论】:
标签: javascript reactjs graphql apollo react-apollo