Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/391.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 为什么Fetch在工作,而Apollo Fetch没有?(调用GraphQL API)_Javascript_Amazon Web Services_Graphql - Fatal编程技术网

Javascript 为什么Fetch在工作,而Apollo Fetch没有?(调用GraphQL API)

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 =&

我正在尝试调用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 => 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)
})