Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

External fragments are not pulled into the query document using the loader #23

Open
emahuni opened this issue Aug 9, 2019 · 6 comments

Comments

@emahuni
Copy link

emahuni commented Aug 9, 2019

import doesn't seem to contain the fragment specified in # import statement and doesn't handle single quoted paths as well:

contact.fragment.graphql:

fragment fullContactFields on Contact {
  addresses {
    line1
    line2
  }
  mobiles {
    number
  }
}

profile.graphql:

# import "../fragments/contact.fragment.graphql"

query fetchProfile{
  profiles{
    firstname
    lastname
    contact {
      ...fullContactFields
    }
  }
}

Further console log scrutiny of the imported graphql query shows that the fragment definition is missing in the AST or imported string.

NOTICE If I combine the two files into one (profile.graphql) then the fragment is defined in the resulting AST document and works flawlessly.

Am I missing something I should do to include the fragment or it's a bug?

@gpoitch
Copy link
Contributor

gpoitch commented Aug 9, 2019

#import (without the space after the pound sign) should make it work

@emahuni
Copy link
Author

emahuni commented Aug 9, 2019

ok let me try it out just now, will give feedback just now. Thanks

@emahuni
Copy link
Author

emahuni commented Aug 9, 2019

Thank you soo much, it works, but why is this so?
I think it should handle these imports without too much strictness don't you think?
I thought this was handling the import statement using a regEx or something.

I had created a make shift loader that was now at the point of parsing it with gql. I guess I just going to ditch it now coz this has all the features I want and you are very active on issues. I'd rather contribute to this than reinvent the wheel.

@emahuni
Copy link
Author

emahuni commented Aug 9, 2019

It could help if you throw an error when the import statement is somehow mull-formed and not parsable coz, I am sure the code can detect that an import was being attempted. Double pound should be a real comment even if it contains a valid or invalid import directive.

@gpoitch
Copy link
Contributor

gpoitch commented Aug 9, 2019

I don't know, I didn't write the code. Just saw the question and thought I'd help.
Here are the lines that parse it: https://github.com/samsarahq/graphql-loader/blob/master/src/loader.ts#L84-L92

@amonks
Copy link

amonks commented Aug 9, 2019

@emahuni

I see that prisma supports a space between the poundsign and the word import:
https://github.com/prisma/graphql-import#usage

I think, given that prior art, we would accept a PR that added either:

  • a useful warning in this branch, or, better yet,
  • handing of whitespace between # and import.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants