【问题标题】:Gatsby Graphql issue when trying to connect at GraphCMS api尝试在 GraphCMS api 上连接时出现 Gatsby Graphql 问题
【发布时间】: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))

有什么想法吗?

非常感谢

【问题讨论】:

    标签: graphql graphql-js gatsby


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2021-09-01
      • 2019-04-05
      • 2021-09-07
      • 1970-01-01
      • 2023-02-08
      • 2011-02-14
      • 2020-10-02
      • 2020-08-29
      • 1970-01-01
      相关资源
      最近更新 更多