graphql-tag
graphql-tag copied to clipboard
Added support for nested fragments when importing from graphql/loader
Used test from https://github.com/apollographql/graphql-tag/pull/105
Simplified import of nested fragments - uses the built-in graphql printer to get the full source including any nested fragments
Fixes the following situation:
AuthorDetailsFragment.gql
fragment AuthorDetails on Author {
firstName
lastName
}
BookDetailsFragment.gql
#import "./AuthorDetailsFragment.gql"
fragment BooksAuthor on Book {
author {
...AuthorDetails
}
}
main.js
import gql from 'graphql-tag';
import BookDetails from './BookDetailsFragment.gql';
const result = gql`query { ...BooksAuthor } ${BookDetails}`;
Previously, result would only include 2 definitions: the Query and the BooksAuthor fragment - and ignore the AuthorDetails fragment.
Now result should include all 3
we want this :)
Oh yes ! we really need this too ! 😍 It's so bad not being able to nest fragments... 😢
@mzalewski, any updates?
I really need that feature too, hope reviewer merge this pull request
It's been a while...
Our app just suffered a nasty bug traced to a point where developer tried a nested fragment and commented it out because it doesn't work and the hard coded attributes pasted in its place got out of sync with the original fragment. Please get this merged!
any updates on this?
As a workaround while this isn't merged, for me the following worked.
In the situation described by the OP, put the query in a separate .gql
file:
# MyBookQuery.gql
#import "./BookDetailsFragment.gql"
# Above import includes nested AuthorDetailsFragment.
query MyBookQuery {
book {
...BooksAuthor
}
}
// main.js
const result = require("./MyBookQuery")
I'm using webpack as described here.
As a (positive) side effect, the gql
import in main.js
can be dropped.