graphql-tag icon indicating copy to clipboard operation
graphql-tag copied to clipboard

Feature request: Allow to import specific fragment from .graphql file with many fragments

Open chris-verclytte opened this issue 8 years ago • 7 comments

In some cases, it would be great to be able to import a specific fragment when defined in a .graphql file alongside with other fragments. At the moment, only two solutions are available:

  • Write only one fragment per .graphql file which produces a lot of files
  • Declare fragments both in the .graphql file (for the query) and in the components (for props validation and data filtering) which is the solution exposed in GitHunt but imply writing the data requirements in two places and thus is not very maintainable. #

chris-verclytte avatar Jun 20 '17 07:06 chris-verclytte

Not stated above - I beileve it's not possible to do this today because spec-compliant graphql servers will complain about unused fragments.

Alternatively, what if the loader checked for the validity of the graphql queries/fragments and removed unused fragments?

stephen avatar Jul 19 '17 04:07 stephen

+1. Maybe we can just use ES6 style import in the future

fragment userInfo on UserInfo {
  # some fileds
}

fragment communityUserInfo on UserInfo {
  # some fileds
}

then

#import { userInfo } from './userInfo.gql'

TinkGu avatar Sep 06 '17 07:09 TinkGu

sounds like a fairly reasonable extension of the feature introduced in 2.6.0 to export multiple operations from a graphql document

happily accepting PRs, that PR should help make this easy!

jnwng avatar Dec 07 '17 17:12 jnwng

What is the status of this issue? Is the idea abandoned? Currently we can only produce a huge amount of graphql files which mostly makes no sense unfortunately.

klemenoslaj avatar Feb 04 '19 19:02 klemenoslaj

i generally think that this should be subsumed by integrating with efforts like graphql-import which have better support for some of the things mentioned above, rather than building our own version of this stuff in this library.

jnwng avatar Feb 04 '19 20:02 jnwng

@jnwng, thanks for a fast reply 👍 I absolutely agree with integrating rather than reimplementing, but does that mean integrating it to this library or within end projects?

klemenoslaj avatar Feb 04 '19 20:02 klemenoslaj

I've submitted PR #257 to address this, please take a look.

dobesv avatar May 03 '19 18:05 dobesv