const httpLink = createHttpLink({
uri: 'http://localhost:3090/'
})
const client = new ApolloClient({
link: httpLink,
cache: new InMemoryCache()
})
client.query({
query: gql`
query users {
email
}
`,
})
.then(data => console.log(data))
.catch(error => console.error(error));
从客户端代码获取时,此查询会出错,但是当我在浏览器中的 http://localhost:3090/graphql 上执行此查询时,它会正确获取数据
原文由 Mukesh Kumar 发布,翻译遵循 CC BY-SA 4.0 许可协议
您要将查询发布到的 graphql 端点缺少
/graphql
。因此,您的服务器可能会返回一个 html 文档,其中包含以<
来自<html...
开头的 404 错误消息。 Apollo 试图将其解析为查询结果,但失败了。检查
httpLink
实际上是localhost:3090/graphql
。查询的语法也是:
或者如果你想命名查询: