gql icon indicating copy to clipboard operation
gql copied to clipboard

Support importing fragments

Open kumarharsh opened this issue 7 years ago • 6 comments

Transferred from https://github.com/kumarharsh/graphql-for-vscode/issues/22

@majodev said:

Enhancement, see documentation in gql-tag.

@kumarharsh said:

@majodev - from what I read, this is a webpack feature rather than an editor feature. Can you clarify exactly what you mean?

@majodev said:

Sure, this allows to import fragments from other files, however the plugin does not understand the import syntax, which leads to NoUnusedFragments and KnownFragmentNames errors.

See the attached screenshot. bildschirmfoto 2017-03-31 um 12 02 20

@kumarharsh said:

OK, I understand, thanks for the screenshot too. I'll look into how to do this.

@kumarharsh said:

I think the gql repo will be the best place to handle this.

kumarharsh avatar Apr 18 '17 13:04 kumarharsh

any news?

jvbianchi avatar Sep 25 '17 22:09 jvbianchi

@jvbianchi you can disable validation rules to suppress errors

// .gqlconfig
{
  match: "path/to/files",
  validate: {
    extends: "gql-rules-query",
    rules: {
      KnownFragmentNames: "off",
      NoUnusedFragments: "off"
    }
  }
}

Mayank1791989 avatar Sep 26 '17 20:09 Mayank1791989

@Mayank1791989 I done it. It solved the errors for me. Thanks

jvbianchi avatar Sep 26 '17 21:09 jvbianchi

I'm not sure that suppressing the errors is necessarily the best solution. One might want to know, for instance, about truly unknown or unused fragments, not just fragments from other files.

graphql-language-service provides a good model for how I think it could work. All of the fragments glob'd from query.files.match have their fragments stored in a map of name to parsed fragment. This information is made available as needed for autocompletion, validation, etc of queries that may reference fragments specified in the same file or other files. Essentially, everything that gets glob'd is globally namespaced. No #imports required.

mgadda avatar Dec 12 '17 17:12 mgadda

I'm not sure that suppressing the errors is necessarily the best solution. One might want to know, for instance, about truly unknown or unused fragments, not just fragments from other files.

@mgadda suppressing errors is only a temp solution for above import based graphql files as I dont want to implement #imports which is not part of graphql spec and very specific to javascript language client.

All of the fragments glob'd from query files.

Yes It's already on the roadmap of next version to support relay-modern client and it will be something similar to that.

Mayank1791989 avatar Dec 12 '17 18:12 Mayank1791989

Any update on this?

ntziolis avatar Apr 18 '18 10:04 ntziolis