-
Notifications
You must be signed in to change notification settings - Fork 1.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
feat: add gql call expressions support #2509
Conversation
🦋 Changeset detectedLatest commit: c22885b The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
@Chnapy this adds highlighting support only fyi! It would seem language support already exists in the LSP server. Can you add a changeset? |
Codecov Report
@@ Coverage Diff @@
## main #2509 +/- ##
==========================================
+ Coverage 65.70% 68.83% +3.12%
==========================================
Files 85 71 -14
Lines 5106 4155 -951
Branches 1631 1375 -256
==========================================
- Hits 3355 2860 -495
+ Misses 1747 1290 -457
- Partials 4 5 +1
Continue to review full report at Codecov.
|
@Chnapy I haven't seen this pattern used. Usually with const myQuery = gql`
query {
field
}
`
as you can see, even github's ace editor supports this pattern! whereas, this pattern is not supported in most of the third party ecosystem as you can see: const myQuery = gql(`
query {
field
}
`)
``` (a
do you have examples of libraries that use this pattern? I'm worried about creating confusion, because if someone used `graphql-tag` or similar libraries this way, it would look like it's working when it would break at runtime (at least for js users) |
@Chnapy my apologies, we can add support for this syntax no problem, I don't need examples, there is no sense holding back innovation. To clarify, the Edit - tests! There are some tests in Let me know how I can help if it needs completion! |
@acao thanks for your feedbacks ! I worked on this add because of a small typescript plugin I'm working on (ts-gql-plugin). There is no difference between these 2 ways of doing with require("graphql/package.json"); // graphql is a peer dependency.
const { gql } = require("graphql-tag")
const a = gql`
query Foo {
bar {
id
}
}
`;
const b = gql`
query Foo {
bar {
${'id'}
}
}
`;
const c = gql(`
query Foo {
bar {
id
}
}
`);
const d = gql(`
query Foo {
bar {
${'id'}
}
}
`);
const strA = JSON.stringify(a);
const strB = JSON.stringify(b);
const strC = JSON.stringify(c);
const strD = JSON.stringify(d);
console.log(
a, b, c, d,
strA.length, strB.length, strC.length, strD.length, // same length
strA === strB, strC === strD, strA === strC // true
); -- I admit this is a very specific use-case, based on one random librairy. I thought this add would cost quite nothing in maintainability (?). Also since it is simply possible to call
Hmm I see, I think I found the part to work on. I'll pass some time and update this PR if I succeed something 👍 |
@Chnapy yes my bad, Are we sure the language support works for this syntax? the visitor you linked to in the last sentence is used for comment tags, which is a different visitor than what we need. what we need to do is repeat this, I think:
also see an update to my above comment about where to add (partial) integration test coverage! |
I made few changes on I put the logic into Some tests added in |
@Chnapy brilliant work, thanks for this! Looks great so far and I will give it a spin later today |
@@ -100,10 +100,48 @@ export function findGraphQLTags( | |||
} | |||
const ast = parsedAST!; | |||
|
|||
const parseTemplateLiteral = (node: TemplateLiteral) => { |
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.
this is exactly the abstraction I was hoping for!
|
||
if ( | ||
callee.type === 'Identifier' && | ||
getGraphQLTagName(callee) && |
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.
💯
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.
@Chnapy reviewed it locally and everything works great. thanks for all your work on this!
a3ce572
to
aeb84dc
Compare
@Chnapy I think I've found a substantial section of code that is never used within |
@stonexer if you'd like to take a look, and make sure you can't find a test case that I'm overlooking by deleting this seemingly unused functionality?? |
merged! thanks @Chnapy ! 🥳 |
This PR enables highlight & intellisense on common
gql()
calls without need to add a#graphql
tag or equivalent.Before:
After: