1
我正在使用React Starter Kit,我试图将查询作为参数传递给一个字符串,但没有任何效果。我曾尝试以下:向GraphQL请求添加参数
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>,
};
},
};
但它不能每次我包括括号...什么是沿着一个参数传递正确方式?
你说的“失败”和你是什么意思意思“包括括号“?无论如何,这可能是你应该使用变量:http://graphql.org/learn/queries/#variables – stubailo
嘿@stubailo是你的工作的长期粉丝,感谢您的答复。事实证明,我的模式设置不适用于接受参数。当我的意思是“parens”时,当我将它们包含在上面的代码中时,我会得到*认为*是语法错误,但只是模式没有正确设置。 – j0e