Example with fragments
bdombro opened this issue · comments
I tried for a while to get fragment to work and failed. Are they supported? If so, can you extend your reference application to demonstrate?
Hello @bdombro, thank you for using graphql-let.
Sadly, It seems that independent .graphql
document files don't have measures to import another GraphQL document right now, as you investigated.
A thread says the spec still needs time to be standardized for a concrete syntax. I think we should wait for something #import
or #include
they're discussing.
Bummer! But looking at the Apollo docs, isn't import already settled and adopted? Ref: https://www.apollographql.com/docs/react/integrations/webpack/#fragments
@bdombro Yeah it is in webpack for now. But... as I looked at graphql-import, we might be able to load *.graphql just by it. Let me try it.
Progress
- graphql-import is for schema, not for documents so it's not our option
- graphql-tag/loader beautifully loads subsequent dependencies by
#import "a.graphql"
- by webpack loader. Since we provide
graphql-let
CLI, we can't use it directly
- by webpack loader. Since we provide
- graphql-tag function (
gql()
) generates documents AST, but it doesn't include information of#import
- I found webpack/loader-runner. Perhaps we can share how to load files by both CLI and Loader, while it differs in file processing steps depending on the context? That allows graphql-tag to load .graphql including
#import
Exciting you've made progress! I wish I had more to contribute -- I know little about the inner workings of Apollo at this point. Someday that will hopefully change. I can tell ya though that fragments are very important to my colleagues.
@piglovesyou GraphQL Tools supports #import
for both schema and documents. It's not documented specifically yet but it does all those stuff with @graphql-tools/import
under the hood.
https://www.graphql-tools.com/docs/documents-loading
Thanks for the information! I didn't check it last time, so that might be what we've looked for.
I made sure it solves the problem with your amazing work, thank you @ardatan ! The rest I need is time to code👍
@piglovesyou thanks for you're hard work! Curious, this ticket is for an example -- can you point me to an example of it working? Would love to see it in the awesome nextjs example. I'll try to add when I can find time.
Thank you @bdombro! @graphql-tools/import
is the trick. For a quick answer,
This imports this fragment. Here describe a little more. Yes, it's been a while to put features into with-typescript-graphql, it's great if you find the time :)
I forked nextjs, created a branch, and updated the example but it's not working with Fragments. Could you take a look? I added you as a collaborator so feel free to fix and push directly to the branch @piglovesyou
Because I didn't publish 0.15.0 yet. I'd like to add one more feature so please wait for a moment. Thank you!
Any update on when this may be supported? I see the issue is closed, but the README still links here.