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

Support Importing Fragments #158

Open
brettjurgens opened this issue Mar 14, 2018 · 3 comments
Open

Support Importing Fragments #158

brettjurgens opened this issue Mar 14, 2018 · 3 comments

Comments

@brettjurgens
Copy link
Contributor

brought up by @zamiang here: #127 (comment)

essentially, in a query that looks like:

#import "./path/to/fragment"

query DoSomething {
  ...FragmentFromImport
}

should import the fragment & generate the appropriate typings

@zamiang
Copy link

zamiang commented Mar 14, 2018

While I'm thinking about it. It seems like there are (at least) 3 approaches that we could take here.

  1. when generating a type for a query, gql2ts would load any imported fragment and inline the fragment in the generated type for the query
  2. a new function that generates a single namespace file for a single fragment (would create a global type for each fragment) ie: FragmentFromImport.d.ts
  3. generate a larger file (much like schema.d.ts) of types for all fragments and then have the generated types for queries import and use those fragments. (struggling a bit with imagining this approach)

Do you feel strongly about any particular way of doing this?

@brettjurgens
Copy link
Contributor Author

So I was leaning towards option 1, option 2 seems more difficult with minimal gain.

I've only given it a little thought, but the caveats I've come up with, so far, are:

  • @gql2ts/from-schema doesn't know where the file is located, which will complicate relative imports

    • allow passing either the file's directory to resolve the imports (this seems like it might be the best option)
      • cli/possible webpack loader would be able to do this automatically
      • API users can pass the additional option
    • allow passing an array of fragment definitions
  • nested imports (i.e. a fragment imports another fragment and so on...)

regardless of these, I think option 1 should be relatively trivial

@brettjurgens
Copy link
Contributor Author

adding this to #163

@brettjurgens brettjurgens mentioned this issue Mar 23, 2018
17 tasks
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

2 participants