Javascript 为什么Fetch在工作,而Apollo Fetch没有?(调用GraphQL API)
我正在尝试调用AWSAPI网关中的GraphQLAPI。该调用需要标头中的x-api-key才能工作 我已经成功地在邮递员和使用fetch中打了这个电话Javascript 为什么Fetch在工作,而Apollo Fetch没有?(调用GraphQL API),javascript,amazon-web-services,graphql,Javascript,Amazon Web Services,Graphql,我正在尝试调用AWSAPI网关中的GraphQLAPI。该调用需要标头中的x-api-key才能工作 我已经成功地在邮递员和使用fetch中打了这个电话 fetch('ApiEndPoint', { method: 'GET', headers: { 'x-api-key': 'myApiKey' }, body: JSON.stringify({query:'{getBook(book_id:"221"){author}}'}), }) .then(res =&
fetch('ApiEndPoint', {
method: 'GET',
headers: {
'x-api-key': 'myApiKey'
},
body: JSON.stringify({query:'{getBook(book_id:"221"){author}}'}),
})
.then(res => res.json())
.then(res => console.log(res.data));
当我尝试使用下面的Apollo Fetch查询时,我得到403状态和“缺少身份验证令牌”
我假设我没有正确地传递x-api-key-如果这可以更好地用于不同的GraphQL客户端,我希望得到其他建议
const { createApolloFetch } = require('apollo-fetch')
const uri = 'ApiEndPoint'
const query = `{getBook(book_id:"221"){author}}`
const apolloFetch = createApolloFetch({ uri })
apolloFetch.use(({ request, options }, next) => {
options.headers = {
'Content-Type': 'application/json',
'x-api-key': 'myApiKey'
}
next()
})
apolloFetch({ query, options }).then(result => {
console.log(result)
})