-
Notifications
You must be signed in to change notification settings - Fork 173
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
[graphql-tag/loader] Allow importing query strings directly #250
Comments
I think this is available as e.g.
|
This almost works, but it won't work if you specify more than one query/fragment in a file and try to access only one. That is, this won't work: import queries from './queries.graphql';
fetch(API_ENDPOINT, {
method: 'POST',
body: JSON.stringify({
query: queries.foo.loc.source.body
})
}); It will simply query with the full body of the |
Well ... sure. But you were saying earlier that "my files were originally query strings, and this should be possible at compile time" which I interpreted to mean you wanted the original string. I guess what you're saying is that you want it to actually generate a new query document for each query and embed it into the generated js code. Some people might object as for anyone who has no use for the source, each document would have to include a copy of all the fragments it uses plus the query itself. Which could mean duplication between these different copies of the source. One thing that might be easier than you think is to just make a fork of graphql-tag/loader that exports exactly the strings you want, and use that in webpack instead of using the one from this package. The loader is actually not super complicated. |
https://github.com/nhi/graphql-operations-string-loader I created a loader that handles multiple operations per file, and outputs them as named exports in a string format |
Hi, I'm using
graphql-tag/loader
to import.graphql
files for compile time checks and general compilation benefits.I do this mostly because it makes development a bit easier; I like to keep my runtime dependencies rather minimal, so I'm handling the actual requests myself (though the same problem applies to
graphql.js
orgraphql-request
).To use the queries, I then need to use
graphql.print
at run time to convert my AST into query string - but my files were originally query strings, and this should be possible at compile time!I'm now unnecessarily importing
graphql
into my "binary" and spend runtime turning an AST back into its source code. This strikes me as extremely inefficient.Similar to #206, it would be nice if the webpack loader could export queries directly, so that we can use the
graphql-tag
loader for compilation without affecting runtime performance.The text was updated successfully, but these errors were encountered: