【发布时间】:2017-01-05 20:35:34
【问题描述】:
我正在使用React Starter Kit,我正在尝试将一个字符串与查询一起作为参数传递,但没有任何效果。我尝试了以下方法:
export default {
path: '/',
async action() {
const resp = await fetch('/graphql', {
method: 'post',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
query: `{
posts {
id,
title,
content,
date
},
page(slug: 'homepage'){
id,
date,
modified,
slug,
type,
title,
content,
excerpt,
author
}
}`,
}),
credentials: 'include',
});
const { data } = await resp.json();
console.log('in home/index');
if (!data || !data.posts) throw new Error('Failed to load the homepage.');
return {
title: 'React Starter Kit',
component: <Layout><Home posts={data.posts} page={data.page} /></Layout>,
};
},
};
但每次我包含括号时它都会失败...传递参数的正确方式是什么?
【问题讨论】:
-
“失败”是什么意思,“包含括号”是什么意思?无论如何,您可能应该使用变量:graphql.org/learn/queries/#variables
-
嘿@stubailo 一直是您作品的忠实粉丝,感谢您的回复。事实证明,我的架构设置不正确,无法接受参数。当我所说的“parens”是指一旦我将它们包含在上面的代码中,我就会得到 thought 是语法错误,但这只是架构没有正确设置。