-
Notifications
You must be signed in to change notification settings - Fork 175
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
Webpack loader fragment auto-resolution #37
Comments
I'm still a bit confused because my understanding is that to resolve stuff, Webpack needs a file path to that module. Can you point me to some docs about how a loader can scan all files in a project that match a certain pattern? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Regarding
#import "my-fragment.gql"
(#33) vs auto-resolving/loading fragments from the project where necessary. Bringing this in from a discussion from Twitter/Gist.Suggestion: Instead of manually
#import
ing files to load fragments for a query/mutation, rather have the webpack loader automatically include them by auto-discovering them in the project.@armstrjare says:
If the fragments are stored in different parts of file tree, it's a pain to have to manually import them and maintain imports if refactoring etc.
#import '../../contacts/contact.fragment.gql'
Considering:
apollo-codegen
assumes all fragments and queries are uniquely namedWhy doesn't the loader operate in the following way:
Loader semantics:
require
s)To me this:
#import
preprocessor (IMO this adds redundant complexity to the syntax, and extra managing of import paths etc., and it's non-standard)Thoughts?
@stubailo responds:
@armstrjare responds:
Not at all - the loader would need to load and parse all resolved graphql files in the project, to determine what "fragments" are available to be used in the application. Only the extension/matcher is relevant - the rest of the info is purely based on the GQL in the file.
Well, afaik this is because of the semantics of JS modules being isolated in scope and adding them on top of the existing JS runtime. Are explicit imports for all tokens needed because of this, rather than "we're going to do it this way in order to have explicit imports"?
If there was some form of "method missing" on the global scope (a la Ruby) then I wonder if autoloading would implemented along the lines of, say, how Rails does it?
With GQL we also have the benefit of it not being a programming language, but a data structure/definition. So we're not really comparing apples with apples. I'm not sure the same expectations apply?
There are some downsides of doing implicit fragment resolution though, but I think they outweigh the benefits:
Are people even naming different fragments with the same name? As above, all the code-generation tools I've seen assume that all fragments are uniquely named. Is a reasonable constraint? Noting there is no concept of a GraphQL module or scope in the spec (?), and in GraphQL itself all Types are expected to be uniquely named.
I'm not sure this is really an issue as a) files are generally pretty small; b) parsing is pretty fast; c) it can be loaded once for the first require() and then cached for future requires
The text was updated successfully, but these errors were encountered: