-
-
Notifications
You must be signed in to change notification settings - Fork 27k
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
Proposal: importing .graphql files should be enabled #1792
Comments
Ejected for this same reason. |
I’m open to supporting this, but is it Apollo-specific? Would it work for people using Relay Modern too? |
I dont think it's apollo specific -- but I have not verified yet. From this:
You end up with this: {
"kind": "Document",
"definitions": [
{
"kind": "OperationDefinition",
"operation": "query",
"name": {
"kind": "Name",
"value": "ChannelsList"
},
"variableDefinitions": [],
"directives": [],
"selectionSet": {
"kind": "SelectionSet",
"selections": [
{
"kind": "Field",
"alias": null,
"name": {
"kind": "Name",
"value": "channels"
},
"arguments": [],
"directives": [],
"selectionSet": {
"kind": "SelectionSet",
"selections": [
{
"kind": "Field",
"alias": null,
"name": {
"kind": "Name",
"value": "id"
},
"arguments": [],
"directives": [],
"selectionSet": null
},
{
"kind": "Field",
"alias": null,
"name": {
"kind": "Name",
"value": "name"
},
"arguments": [],
"directives": [],
"selectionSet": null
}
]
}
}
]
}
}
],
"loc": {
"start": 0,
"end": 55,
"source": {
"body": "query ChannelsList {\n channels {\n id\n name\n }\n}",
"name": "GraphQL"
}
}
} |
Looks like Relay.QL is vastly different. It uses a precompiled schema and validates your graphql against it. Whereas graphql-tag/loader just spits out the document and handles imports (that also might be a graphql-tag/loader specific concept). |
Yep, I'm having to eject too on a brand new project just to support this. Really good if there were a way to bake this in, or even better add custom loaders somehow 🙌 |
As of Relay Modern, there must be "babel-plugin-relay" baked into the Babel config. |
Has anyone had any further thoughts on how we best implement this? Graphcool today announced graphql-cli and it would be awesome to submit a PR over there that CRA works out of the box with graphql-cli. |
Note this issue won't progress by itself. If you're interested in this please create a proof of concept, send a PR, help us understand whether it's Apollo-specific or not, etc. Thanks! |
@gaearon - From what I have tested so far, it is Apollo-specific. Would a good alternative be to add both |
If the above isn't a good alternative, I only see two other options:
(Or just support one. I don't see that as an ideal solution, though.) |
For Relay, I’d like to see if recently merged For Apollo, it seems to me odd to hardcode a filetype loader to a specific library 😞 But maybe if |
I haven't seen Ideally, we should have a global GraphQL plugin/loader that handles Apollo, Relay, and any other GraphQL lib/framework. I'm not sure about a good solution to the last statement you made. For users who are not using GraphQL, it adds a bit more bloat to the |
I'll note that if we come up with a good solution, I'm more than happy to submit a PR to close this issue. |
Someone could probably build a macro to support reading in // some-file.js
import graphqlLoader from './graphql-loader.macro'
const query = graphqlLoader('./query.graphql')
// graphql-loader.macro.js
const {createMacro} = require('babel-plugin-macros')
module.exports = createMacro(graphqlLoaderMacro)
function graphqlLoaderMacro({references, state, babel}) {
const {file: {opts: {filename}}} = state
references.default.forEach(graphqlLoader => {
const relativeQueryPath = graphqlLoader.parentPath.get('arguments')[0].node.value
const queryPath = path.relative(filename, relativeQueryPath)
// do the queryPath loading thing
// replace graphqlLoader.parentPath with whatever you loaded...
})
} The cool thing is you could do this locally in your own project before it's even published to npm. All without having to configure anything at all. Then when someone's got a good working version they can publish it to npm and anyone can use it. It's 100% explicit what's going on and it works without any configuration necessary! 🎉 |
Smart. Since we landed |
@kentcdodds I'd like to see the setup for this and how to use in practice as an example if possible. |
I don't know if I have time. I also don't know much about graphql, so I may not be the right one to make this. But it does seem interesting to me, so if I have time I'll work on it. Honestly I don't think it's much more than my example above. You'll probably need For folks wanting to learn more about this, see the |
@kentcdodds Thank for your suggestion. I try to implement it with babel-plugin-macros. It ls really $ yarn add graphql.macro import { loader } from 'graphql.macro';
const query = loader('./fixtures/query.graphql');
↓ ↓ ↓ ↓ ↓ ↓
const query = {
"kind": "Document",
"definitions": [{
... ReferencesGitHub: https://github.com/evenchange4/graphql.macro |
This is super @evenchange4! Would you like to add your macro to the list? And make sure to add the keyword Well done @evenchange4! 👏 |
Importing |
Right now I need to eject in order to import .graphql files (using graphql-tag/loader) . I would think graphQl is some kind of core technology that should be supported out of the box ?
The text was updated successfully, but these errors were encountered: