Skip to content
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

fix(lsp): nested call expressions #319

Merged
merged 3 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 27 additions & 27 deletions packages/example-tada/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,41 @@ import { useQuery } from 'urql';
import { graphql } from './graphql';
import { Fields, Pokemon, PokemonFields } from './Pokemon';

const PokemonQuery = graphql(`
query Po($id: ID!) {
pokemon(id: $id) {
id
fleeRate
...Pok
...pokemonFields
attacks {
special {
name
damage
}
const query = graphql(`
query Po($id: ID!) {
pokemon(id: $id) {
id
fleeRate
...Pok
...pokemonFields
attacks {
special {
name
damage
}
weight {
minimum
maximum
}
name
__typename
}
pokemons {
name
maxCP
maxHP
types
fleeRate
weight {
minimum
maximum
}
name
__typename
}
pokemons {
name
maxCP
maxHP
types
fleeRate
}
`, [PokemonFields, Fields.Pokemon]);
}
`, [PokemonFields, Fields.Pokemon])

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

const Pokemons = () => {
const [result] = useQuery({
query: PokemonQuery,
query,
variables: { id: '' }
});

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;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like it was refactored the wrong way, if we keep accessing the expression we'll reach the top-element i.e. fields.fragment we'll get fields rather than fragment

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