【问题标题】:Concatenate variable and sting in graphql query在graphql查询中连接变量和字符串
【发布时间】:2018-10-16 10:58:29
【问题描述】:

我正在尝试将 my/custom/path/ 添加到 $path 变量中,但不知道如何执行此操作。已经查看了文档,但找不到任何提及这一点的内容。

export const postQuery = graphql`
    query BlogPostByPath($path: String!) {
        markdownRemark(frontmatter: { path: { eq: $path } }) {
            html
            frontmatter {
                path
                title
                description
                keywords
            }
        }
    }
`;

【问题讨论】:

  • 可以显示markdownRemark的解析功能吗?第一次看到这样的嵌套参数传递。你在使用 Apollo 作为 GraphQl 客户端吗?
  • @ArupRakshit 我正在使用 gatsby 和名为 gatsby-transformer-remark 的插件,所以它可能看起来不同。我不确定我还能提供什么来帮助您:/

标签: reactjs graphql-js


【解决方案1】:

如果你正在使用 Gatsby,请尝试:

graphql(`<your_query_with_variable>`, { variable: <value_of_variable> })

来源:Passing a string to GraphQL queries argument.

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-12-17
    • 2016-11-15
    • 2018-06-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多