gpt4 book ai didi

graphql - 是否可以将变量放入 GraphQL 标签中?

转载 作者:行者123 更新时间:2023-12-02 18:53:55 25 4
gpt4 key购买 nike

现在我下面有这个标签。它是静态的,并且总是会获得 id 为 3 的注释。是否有可能将变量放入此 graphQL 标签中。那么我可以重复使用 graphQL 标签,而只需更改变量 ID 吗?

export const GET_COMMENTS: any = gql`
{
comments(id: 3) {
userId,
text,
creationDate,
}
}
`;

提前致谢!

最佳答案

是的,您可以在 GQL 查询中传递变量。 $xyz 是一种在 GQL 中传递变量的符号或变量名称。

export const GET_COMMENTS: any = gql`
query GET_COMMENTS($id: Int){ // $id is the variable name
comments(id: $id) {
userId,
text,
creationDate,
}
}
`;

关于graphql - 是否可以将变量放入 GraphQL 标签中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52588436/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com