-
Notifications
You must be signed in to change notification settings - Fork 178
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
Added ability to "#import" graphql files #33
Conversation
let outputCode = ""; | ||
|
||
lines.some((line) => { | ||
if (line[0] === '#') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you probably want to check if this comment is an import - so maybe check for #import
. People should still be able to do regular comments in their queries.
Would it make sense to put the |
I guess I was thinking of this in terms of "preprocessor directives" which are traditionally at the top. I don't think the choice matters since the definitions can be permuted arbitrarily. |
I think both ways make sense, but I thought I'd mention it :) |
I think we should support both - here's a good design for directives inline: #25 If someone is interested in tackling it I think it could be a good addition even though I personally prefer the comment approach since it doesn't introduce new GraphQL syntax. |
Quick question about this PR. Is this documented in any way?? Just found this issue when trying to use fragments. The documentation on fragments seems out of date. It seems that options no longer support fragments and the way forward is importing fragments directly in .graphql files. Anyway...recommended way to handle fragments would be nice. Thanks! |
You can handle fragments however you like, this just offers a particular way of doing it. There are some people that want to colocate queries/fragments with the components in their JS/JSX code whereas others want to place them in different files. This PR supports the latter while not preventing the former. I'm not sure how passing around fragments has changed within Apollo Client. |
@jole78 would you mind sending a PR to this page to add information about fragments? http://dev.apollodata.com/react/webpack.html This |
sure @stubailo I'm glad to help with an example of the #import syntax. Just a question though, are these the 2 recommended ways of including fragments? Meaning:
There's no way of doing mix and match? Meaning, defining query in .graphql file (webpack loader) and fragment in plain JS. And thus including the fragment via graphql HOC (react at least). For me I find it more clear (and easier) to add the fragment inline with my component that uses the data returned from the query. More that often I find myself doing a list and and listitem approach where the list issues the query and the listitem has the fragment. Anyhow, I'll do the PR and again all of you thanks for an awesome library!! |
@Poincare no the 2 ways work just fine. Just wondering if you can mix and match them. e.g. query in .graphql file and fragment in plain JS/X using gql tag. |
No you have to pick one or the other right now. Why not simply use the JS format if that's the one you prefer? There is basically no benefit to the webpack approach. |
The goal is to be able to do this with the webpack loader:
with the following in
fragment.graphql
:This should be equivalent to:
in a single file.