【发布时间】: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