Skip to content

Commit

Permalink
fix(lsp): nested call expressions (#319)
Browse files Browse the repository at this point in the history
  • Loading branch information
JoviDeCroock committed May 13, 2024
1 parent b8997a5 commit b153ce1
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/tough-crabs-heal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@0no-co/graphqlsp': patch
---

Support finding `graphql()` invocations within call-expressions
4 changes: 2 additions & 2 deletions packages/example-tada/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ const PokemonQuery = graphql(`
fleeRate
}
}
`, [PokemonFields, Fields.Pokemon]);
`, [PokemonFields, Fields.Pokemon])

const persisted = graphql.persisted<typeof PokemonQuery>("sha256:7a9bbe8533362e631f92af8d7f314b1589c8272f8e092da564d9ad6cd600a4eb")
const persisted = graphql.persisted<typeof PokemonQuery>("sha256:78c769ed6cfef67e17e579a2abfe4da27bd51e09ed832a88393148bcce4c5a7d")

const Pokemons = () => {
const [result] = useQuery({
Expand Down
2 changes: 1 addition & 1 deletion packages/graphqlsp/src/ast/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export function findAllCallExpressions(
// Check whether we've got a `graphql()` or `gql()` call, by the
// call expression's identifier
if (!checks.isGraphQLCall(node, typeChecker)) {
return;
return ts.forEachChild(node, find);
}

const name = checks.getSchemaName(node, typeChecker);
Expand Down
2 changes: 1 addition & 1 deletion packages/graphqlsp/src/ast/resolve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ export const resolveTadaFragmentArray = (
if (node.elements.every(ts.isIdentifier)) return node.elements;
const identifiers: ts.Identifier[] = [];
for (let element of node.elements) {
while (ts.isPropertyAccessExpression(element)) element = element.expression;
while (ts.isPropertyAccessExpression(element)) element = element.name;
if (ts.isIdentifier(element)) identifiers.push(element);
}
return identifiers;
Expand Down
2 changes: 1 addition & 1 deletion packages/graphqlsp/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ function create(info: ts.server.PluginCreateInfo) {
: positionOrRange.pos,
info
);
console.log('[GraphQLSP]', JSON.stringify(codefix));

if (codefix) {
return [
{
Expand Down

0 comments on commit b153ce1

Please sign in to comment.