graphql-raw-loader icon indicating copy to clipboard operation
graphql-raw-loader copied to clipboard

Import a file just once

Open VitorLuizC opened this issue 7 years ago • 0 comments

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.

VitorLuizC avatar Mar 21 '18 21:03 VitorLuizC