Skip to content
This repository has been archived by the owner on Jul 31, 2022. It is now read-only.

Commit

Permalink
feat: provide 'Execute Query' for /* GraphQL */ templates
Browse files Browse the repository at this point in the history
  • Loading branch information
AumyF authored and acao committed Dec 10, 2021
1 parent f390366 commit 6017872
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/silver-radios-invent.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"vscode-graphql": patch
---

provide 'Execute Query' for `/* GraphQL */` templates
15 changes: 11 additions & 4 deletions src/client/graphql-codelens-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
CodeLens,
Range,
Position,
ProviderResult,
} from "vscode"

import { SourceHelper, ExtractedTemplateLiteral } from "./source-helper"
Expand All @@ -23,10 +24,14 @@ export class GraphQLCodeLensProvider implements CodeLensProvider {
public provideCodeLenses(
document: TextDocument,
_token: CancellationToken,
): CodeLens[] {
const literals: ExtractedTemplateLiteral[] =
this.sourceHelper.extractAllTemplateLiterals(document, ["gql", "graphql"])
return literals.map(literal => {
// for some reason, ProviderResult<CodeLens[]> doesn't work here
// anymore after upgrading types
): ProviderResult<[]> {
const literals: ExtractedTemplateLiteral[] = this.sourceHelper.extractAllTemplateLiterals(
document,
["gql", "graphql", "/\\* GraphQL \\*/"],
)
const results = literals.map(literal => {
return new CodeLens(
new Range(
new Position(literal.position.line, 0),
Expand All @@ -39,5 +44,7 @@ export class GraphQLCodeLensProvider implements CodeLensProvider {
},
)
})

return results as ProviderResult<[]>
}
}

0 comments on commit 6017872

Please sign in to comment.