有没有办法将数据从页面 graphql 调用传递到组件 graphql 调用?

Posted

技术标签:

【中文标题】有没有办法将数据从页面 graphql 调用传递到组件 graphql 调用?【英文标题】:Is there a way to pass data from a page graphql call to a component graphql call? 【发布时间】:2020-04-04 23:03:59 【问题描述】:

我正在尝试将数据 (contentful_id) 传递给组件 graphql 调用。这可能吗?我正在使用 gatsby。

export const pageQuery = graphql`
    query pageQuery($slug: String!)
        contentfulPage(slug: eq: $slug)
            content 
                ... on ContentfulPersonBar 
                  contentful_id: contentful_id
                
            
        
    

我想将该 contentful_id 传递到下面的查询中。

export const personBarQuery = graphql`
    query personBarQuery($contentful_id: String!)
        contentfulPersonBar(contentful_id: eq: $contentful_id)
            heading
            people
                etc
            
        
    
    `

【问题讨论】:

【参考方案1】:

您将无法在运行时(构建后)执行此操作。在 createPages 钩子中,您已经解决了 $slug 问题。可以在那里执行其他查询以获取 $contentful_id 变量并将其传递到页面上下文,就像对 $slug 所做的那样。

【讨论】:

有没有办法可以将 props 传递到 graphql 查询中?

以上是关于有没有办法将数据从页面 graphql 调用传递到组件 graphql 调用?的主要内容,如果未能解决你的问题,请参考以下文章