可跨多个文件重用的GraphQL片段

可跨多个文件重用的GraphQL片段,graphql,Graphql,在多个.GraphQL文件中重用相同的GraphQL片段是否有一个好的解决方案 我试图将所有片段放在一个文件中,并在多个查询中使用它们。您的意思是,如何导出/导入片段accross文件?我会这样做 fragment MyReusableFragment_MyConnection on MyConnection { edges { node { _id name } } } 并将其导入: #import "./MyReusableFragment.

在多个.GraphQL文件中重用相同的GraphQL片段是否有一个好的解决方案


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

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

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
}

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

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
}