尝试在 GraphCMS api 上连接时出现 Gatsby Graphql 问题

Posted

技术标签:

【中文标题】尝试在 GraphCMS api 上连接时出现 Gatsby Graphql 问题【英文标题】:Gatsby Graphql issue when trying to connect at GraphCMS api 【发布时间】:2018-11-16 17:10:09 【问题描述】:

我有一个来自 GraphCMS 的启动并正在运行的 api。

我正在建立一个小型静态网站,想要使用 Gatsby,我想使用 Graphql 客户端从 GraphCMS 获取一些数据 (https://github.com/prismagraphql/graphql-request)

问题是我在执行以下操作时收到了types.js:24 Uncaught (in promise) Error: GraphQL Error (Code: 200)

我的index.js

import React from 'react'
import PropTypes from 'prop-types'
import Helmet from 'react-helmet'
import  GraphQLClient  from 'graphql-request'
import Header from '../components/header'
import './index.css'

export default () =>
<div style= color: `tomato` >
<h1>Hello Gatsby!</h1>
<p>What a world.</p>
</div>




 const client = new GraphQLClient('my-endpoint', 
 headers: 
 Authorization: 'mytokenfromGraphCms',
 ,
 )

 const query = `
 allCurrentEvents 
 tip
 awayteam
 hometeam
 date
 
 allPasteventses
 tip
 
 `

 client.request(query).then(data => console.log(data))

有什么想法吗?

非常感谢

【问题讨论】:

【参考方案1】:

您是否允许对正在查询的字段具有读取权限?或者你正在使用令牌?你真的可以发布你从请求中得到的错误响应吗?

【讨论】:

以上是关于尝试在 GraphCMS api 上连接时出现 Gatsby Graphql 问题的主要内容,如果未能解决你的问题,请参考以下文章