-
Notifications
You must be signed in to change notification settings - Fork 177
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
Fragments #25
Comments
Not right now, I had some ideas here: apollographql/apollo-client#994 (comment) |
I've been hacking around on this and have a half-baked solution using the loader and @stubailo's idea of using a directive. What works well is first declaring the directive in your schema. I've been using this declaration so far, # Import a fragment from an external file
directive @import(
# Path to import fragment from
from: String!
) on FRAGMENT_SPREAD As far as I can tell, graphql-js only provides a way to define custom directives, but not their runtime. This is fine though as Right now I have the loader set to parse the query using visit(ast, {
Directive: {
enter(node) {
if (node.name.value === 'import') {
const fromArg = node.arguments.filter(arg => arg.name.value === 'from')
addImport(fromArg.value.value)
}
return node;
}
}
}); One thing to note is that the loader currently doesn't strip Lastly, a `var fragments = ${imports.map(path => `require(${path})`)}
var query ${JSON.stringify(gql`${source}`)};
query.documents = query.documents.concat(fragments)
module.exports = query` Overall not too complicated of a loader. Biggest concern of mine is if custom directives are considered taboo still, or if they are safe to implement. |
Good. |
Can I use fragments with loader?
The text was updated successfully, but these errors were encountered: