【问题标题】:GraphQL Fragments reusable across multiple filesGraphQL 片段可跨多个文件重用
【发布时间】:2018-05-22 01:40:39
【问题描述】:

有没有好的解决方案可以在多个 .graphql 文件中重用相同的 GraphQL 片段?

我试图将所有片段放在一个文件中,并在多个查询中使用它们。

【问题讨论】:

    标签: graphql


    【解决方案1】:

    您的意思是,如何跨文件导出/导入片段?我会这样做

    fragment MyReusableFragment_MyConnection on MyConnection {
      edges {
        node {
          _id
          name
        }
      }
    }
    

    并导入它:

    #import "./MyReusableFragment.graphql"
    
    query myQuery on MyConnection {
      ...MyReusableFragment_MyConnection
    }
    

    并在其他文件中重复使用它

    #import "./MyReusableFragment.graphql"
    
    query myOtherQuery on MyConnection {
      ...MyReusableFragment_MyConnection
    }
    

    【讨论】:

      猜你喜欢
      • 2021-06-09
      • 2014-07-11
      • 2019-10-09
      • 1970-01-01
      • 2020-04-22
      • 1970-01-01
      • 2023-03-06
      • 2016-06-25
      • 2018-09-29
      相关资源
      最近更新 更多