graphql-raw-loader
graphql-raw-loader copied to clipboard
Import a file just once
Importing, using comment or directive, a file more than once results into repeated concatenated bundle. This breaks GraphQL.
So,
query GetA ($page: Int = 1, $limit: Int = 10, $term: String, $isSearch: Boolean = false) {
getA (page: $page, limit: $limit) @skip(if: $isSearch) {
...FragmentA @import(from: "./FragmentA.graphql")
}
searchA (page: $page, limit: $limit, term: $term) @include(if: $isSearch) {
...FragmentA @import(from: "./FragmentA.graphql")
}
}
results into
module.exports = [
require('./FragmentA.graphql'),
require('./FragmentA.graphql'), `
query GetA ($page: Int = 1, $limit: Int = 10, $term: String, $isSearch: Boolean = false) {
getA (page: $page, limit: $limit) @skip(if: $isSearch) {
...FragmentA
}
searchA (page: $page, limit: $limit, term: $term) @include(if: $isSearch) {
...FragmentA
}
}
`].join('\n\n')
We need some kind of cache to import a file just once.