You can use the variables
key in your client.query
function params as the following(您可以在client.query
函数参数中使用variables
键,如下所示)
const getPostsByCategory = async category => {
const res = await client.query({
query: gql`
query articlesByCategory($id: String!) {
postsByCategory(id: $id) {
id
}
}
`,
variables: {
id: category,
},
});
console.log('res', res);
};
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…