-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Add tagged template strings to enable query string linting #155
Comments
Big questions to answer: Should we keep parsing in ApolloClient as a courtesyIf we move all parsing into the In short, should we require this: import { gql } from 'apollo-client/gql';
import ApolloClient from 'apollo-client';
...
client.query({
query: gql`...`
}); Or allow people to do: import ApolloClient from 'apollo-client';
...
client.query({
query: `...`
}); But just print a warning reminding them to use How to enable people to set up pre-compilation and avoid loading the parser in productionOne of the biggest benefits of this approach is that we can start allowing people to precompile queries, which allows at least three great optimizations:
This means that even though using Given the limitations of current bundling systems, this probably means it needs to be in a separate module - one of the following: // Subdirectory of client
import gql from 'apollo-client/gql';
// Separate NPM module entirely
import gql from 'gql-template-literal'; Then one could simply remove all of those imports in the production build. Interested in feedback @martijnwalraven @jbaxleyiii @abhiaiyer91 since this would be a pretty big change in how the library is used. |
One thing people that people do not like is when you take away their magic. I for one, don't like magic and err on the side of good tooling. I do not think requiring I actually think its more approachable. One of the first things I looked into when diving into Apollo was, "How does this just work? This is magical". Especially comparing this to the counterparts in other Gql implementations. Having the I'd like to see the workflow of using the module in Production vs. Development and how that would be on users in terms of friction. Will people know the best practices between environments? Even with that, education can solve that. Pretty big change, good thing its still early. Hahah if only we can |
hah, would be cool! at least we can print good errors - "hey, you forgot to put |
Solution at #168 |
Done! |
The way I understand, Relay require all the parsing in the pre-compilation - so you have an optimized situation but can't do string interpolation in general 'cause it needs to be able to resolve it in the pre-compilation (so you still can do it in situations like I understood that apollo will have room for both approaches, optimized and parsing on the client, and maybe use both in production. Is this the way forward? Or won't be a effort to have parsing on the client good for a production environment, and will just be a good devtool? |
Yeah right now you can use both in production! This is just one step toward making pre compilation an option if you have really specific performance needs. |
I believe these were wrong, but please double-check before merging @jbaxleyiii
The GraphQL ESlint plugin identifies queries via a template literal tag,
gql
by default.https://github.com/apollostack/eslint-plugin-graphql
We should think about the best way to encourage people to use such a tag, and what other benefits we can get from it.
For example, we could have the template tag do the parsing, and memoize the results. We could also add a warning to the client if you don't use it, so that we can ensure all queries are linted.
Down the road, other benefits include targeting this template string with a query precompiler for performance.
The text was updated successfully, but these errors were encountered: