是否可以在单独的.graphql文件中分离页面graphql查询,然后将其导入页面文件?我假设我需要添加一些og .graphQL加载器?
检查'apollo-universal-starter-kit' - 应该适应gatsby
如果您想用query
或mutation
文件扩展名来编写.graphql
,.gql
。
你需要graphql-tag/loader
,这是我的webpack.config.js
:
{
test: /\.(graphql|gql)$/,
exclude: /node_modules/,
use: 'graphql-tag/loader'
}
据我所知,开箱即用是不可能的。分割查询的唯一方法是使用Fragments:https://www.gatsbyjs.org/docs/querying-with-graphql/#fragments
但是,如果您想开始讨论,我建议您在GitHub上打开一个问题。
你可以使用graphql-import来做到这一点。
示例:假设以下目录结构:
.
├── schema.graphql
├── posts.graphql
└── comments.graphql
schema.graphql
# import Query.*, Mutation.* from "posts.graphql"
# import Query.*, Mutation.* from "comments.graphql"
posts.graphql
# import Comment from 'comments.graphql'
type Post {
comments: [Comment]
id: ID!
text: String!
tags: [String]
}
comments.graphql
type Comment {
id: ID!
text: String!
}
您可以在here中看到完整的文档