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

patch: Increase support of harder to detect gql.tada API usage patterns #309

Merged
merged 19 commits into from Apr 26, 2024

Conversation

kitten
Copy link
Member

@kitten kitten commented Apr 26, 2024

Note

Marking this as a minor since we already have minor changes queued up and some of the API signatures have changed slightly.

Summary

This aims to reduce the amount of separate templates.has based checks and introduce a new check that can also detect gql.tada via the TypeChecker as a fallback if the name (or expression) of graphql() calls is non-standard.

Set of changes

  • Add checks.ts for all predicates
  • Detect graphql() calls by checking !!graphql.scalar and !!graphql.persisted via the typ e checker
    • This works even if graphql itself is not an identifier (any expression)
    • This works even if graphql is renamed (more relevant now due to multi-schema support)
  • Detect graphql.persisted() calls with the above logic
  • Extract logic to detect GraphQL calls and GraphQL tagged template literals
    • Also unifies checks for templates.has into few reusable function
  • Fix several branches where GraphQL tags were checked for even if isCallExpression was truthy
  • Widen NoSubstitutionTemplateLiteral to StringLiteralLike
    • graphql('...') and graphql("...") will work now
    • NOTE: I chose not to implement a TypeChecker based approach here for arguments[0] or arguments[1] yet, but this could lead to some refactors which might slim down the codebase
  • Prevent getAllFragments from expanding to check for fragments via declarations (graphql-code-generator code branch) even if gql.tada is active with new isTadaGraphQLCall check
  • Extract logic to resolve graphql() fragments array literal argument
    • Expand to support as const
    • Consistently resolve PropertyAccessExpressions

Copy link

changeset-bot bot commented Apr 26, 2024

🦋 Changeset detected

Latest commit: f796266

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@0no-co/graphqlsp Minor

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

@JoviDeCroock JoviDeCroock merged commit eb7ce75 into main Apr 26, 2024
1 check passed
@JoviDeCroock JoviDeCroock deleted the feat/call-discovery branch April 26, 2024 06:58
@github-actions github-actions bot mentioned this pull request Apr 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants