Skip to content

Commit

Permalink
re-introduce query exec as separate extension (#2665)
Browse files Browse the repository at this point in the history
  • Loading branch information
acao authored Oct 2, 2022
1 parent 993d7e4 commit 324fbed
Show file tree
Hide file tree
Showing 21 changed files with 1,663 additions and 140 deletions.
6 changes: 6 additions & 0 deletions .changeset/dull-knives-wonder.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'vscode-graphql-execution': patch
'vscode-graphql': patch
---

Port the inline query execution capability from the original `vscode-graphql` repository as promised. More improvements to come!
16 changes: 15 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"version": "0.2.0",
"configurations": [
{
"name": "VS Code Extension: Run",
"name": "VS Code LSP Extension: Run",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
Expand Down Expand Up @@ -35,6 +35,20 @@
"cwd": "${workspaceFolder}",
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen"
},
{
"name": "VS Code Exec Extension: Run",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}/packages/vscode-graphql-execution"
],
"outFiles": [
"${workspaceFolder}/packages/vscode-graphql-execution/dist/extension.js"
],
"sourceMaps": true,
"preLaunchTask": "watch-vscode-exec"
}
]
}
3 changes: 3 additions & 0 deletions custom-words.txt
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,10 @@ typedoc
undici
vite
vitejs
wonka
wsrun


// identifiers used in code and configs
acmerc
binti
Expand Down Expand Up @@ -152,6 +154,7 @@ testid
testonly
typeof
unfocus
urql
unnormalized
unsubscribable
websockets
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"build:watch": "yarn tsc --watch",
"watch": "yarn build:watch",
"watch-vscode": "concurrently --raw \"yarn tsc && yarn tsc --watch\" \"yarn workspace vscode-graphql run compile --watch\"",
"watch-vscode-exec": "concurrently --raw \"yarn tsc && yarn tsc --watch\" \"yarn workspace vscode-graphql-exec run compile --watch\"",
"check": "yarn tsc --dry",
"cypress-open": "yarn workspace graphiql cypress-open",
"dev-graphiql": "yarn workspace graphiql dev",
Expand Down
3 changes: 2 additions & 1 deletion packages/graphql-language-service-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"devDependencies": {
"@types/mkdirp": "^1.0.1",
"cross-env": "^7.0.2",
"graphql": "^16.4.0"
"graphql": "^16.4.0",
"cross-fetch": "^3.1.5"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,23 @@
*
*/
import { AbortController as MockAbortController } from 'node-abort-controller';
import fetchMock from 'fetch-mock';

jest.mock('@whatwg-node/fetch', () => ({
fetch: require('fetch-mock').fetchHandler,
AbortController: MockAbortController,
TextDecoder: global.TextDecoder,
}));

jest.mock('cross-fetch', () => ({
fetch: require('fetch-mock').fetchHandler,
AbortController: MockAbortController,
TextDecoder: global.TextDecoder,
}));

import { GraphQLSchema } from 'graphql/type';
import { parse } from 'graphql/language';
import { loadConfig, GraphQLExtensionDeclaration } from 'graphql-config';
import fetchMock from 'fetch-mock';
import {
introspectionFromSchema,
FragmentDefinitionNode,
Expand Down Expand Up @@ -82,7 +88,7 @@ describe('GraphQLCache', () => {
expect(schema instanceof GraphQLSchema).toEqual(true);
});

it('generates the schema correctly from endpoint', async () => {
it.skip('generates the schema correctly from endpoint', async () => {
const introspectionResult = {
data: introspectionFromSchema(
await graphQLRC.getProject('testWithSchema').getSchema(),
Expand Down
21 changes: 21 additions & 0 deletions packages/vscode-graphql-execution/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 GraphQL Contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
63 changes: 63 additions & 0 deletions packages/vscode-graphql-execution/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
## `graphql.vscode-graphql-execution`

This extension provides standalone support for executing graphql operations inline in your code for:

- .ts/.tsx
- .js/.jsx
- .graphql, .gql or .graphqls files

## How it works

1. A codelens will appear above all operations - clicking will begin executing the operation.
2. (If variables are specified in the operation), a dialog will prompt for these variables
3. Then, the results or network error should appear, voila!
4. If no endpoints are configured, it will exit early and tell you to define them.

## Configuring the extension

### `graphql-config`

Your graphql config file will need to contain either a schema-as-url OR an endpoints configuration. Either of the following are valid:

```yaml
schema: https://localhost:3000/graphql
```
```yaml
schema: schema.graphql
extensions:
endpoints:
default:
url: 'https://localhost:3000/graphql'
```
```yaml
projects:
app:
schema: schema.graphql
extensions:
endpoints:
default:
url: 'https://localhost:3000/graphql'
```
### Disable codelens
To disable the codelens, please specify this setting in `settings.json` or `user.json`:

```json
{
...
"vscode-graphql-execution.showExecCodelens": false
}
```

### Self Signed Certificates

Enable this (`false` by default) to allow node to use non-authorized SSL certificates.

```json
{
"vscode-graphql-execution.rejectUnauthorized": true
}
```
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 38 additions & 0 deletions packages/vscode-graphql-execution/esbuild.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
const { build } = require('esbuild');
const [, , arg] = process.argv;

const logger = console;

const isWatchMode = arg === '--watch';

build({
entryPoints: ['src/extension.ts'],
bundle: true,
minify: arg === '--minify',
platform: 'node',
outdir: 'out/',
external: ['vscode', 'ts-node', 'tslib'],
format: 'cjs',
sourcemap: true,
watch: isWatchMode,
})
.then(({ errors, warnings }) => {
if (warnings.length) {
logger.warn(...warnings);
}
if (errors.length) {
logger.error(...errors);
}

logger.log('successfully bundled vscode-graphql-execution 🚀');

if (isWatchMode) {
logger.log('watching... 🕰');
} else {
process.exit();
}
})
.catch(err => {
logger.error(err);
process.exit(1);
});
124 changes: 124 additions & 0 deletions packages/vscode-graphql-execution/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
{
"name": "vscode-graphql-execution",
"version": "0.1.0",
"displayName": "GraphQL: Inline Operation Execution",
"description": "Execute graphql operations from your code (revived!)",
"publisher": "GraphQL",
"license": "MIT",
"private": true,
"engines": {
"vscode": "^1.63.0"
},
"main": "./dist/extension",
"icon": "assets/images/logo.png",
"contributors": [
{
"name": "Divyendu Singh",
"url": "https://www.divyendusingh.com/"
}
],
"galleryBanner": {
"color": "#032539",
"theme": "dark"
},
"categories": [
"Programming Languages"
],
"activationEvents": [
"workspaceContains:**/.graphqlrc",
"workspaceContains:**/.graphqlconfig",
"workspaceContains:**/.graphqlrc.{json,yaml,yml,js,ts,toml}",
"workspaceContains:**/graphql.config.{json,yaml,yml,js,ts,toml}",
"workspaceContains:**/package.json",
"onCommand:vscode-graphql-execution.isDebugging",
"onCommand:vscode-graphql-execution.contentProvider",
"onLanguage:graphql"
],
"contributes": {
"commands": [
{
"command": "vscode-graphql-execution.isDebugging",
"title": "GraphQL Exec: Is Debugging?"
},
{
"command": "vscode-graphql-execution.showOutputChannel",
"title": "GraphQL Exec: Show output channel"
},
{
"command": "vscode-graphql-execution.contentProvider",
"title": "GraphQL Exec: Execute GraphQL Operations"
}
],
"configuration": {
"title": "VSCode GraphQL: Inline Operation Execution",
"properties": {
"vscode-graphql-execution.debug": {
"type": [
"boolean",
"null"
],
"default": false,
"description": "Enable debug logs"
},
"vscode-graphql-execution.showExecCodelens": {
"type": [
"boolean"
],
"description": "Show codelens to execute operations inline",
"default": true
},
"vscode-graphql-execution.rejectUnauthorized": {
"type": [
"boolean"
],
"description": "Fail the request on invalid certificate",
"default": true
}
}
}
},
"repository": {
"type": "git",
"url": "https://github.com/graphql/graphiql",
"directory": "packages/vscode-graphql-execution"
},
"homepage": "https://github.com/graphql/graphiql/blob/main/packages/vscode-graphql-inline-exec/README.md",
"scripts": {
"compile": "yarn tsc",
"vsce:package": "vsce package --yarn",
"vsce:prepublish": "npm run vsce:package",
"vsce:publish": "vsce publish --yarn",
"open-vsx:publish": "ovsx publish",
"release": "npm run vsce:publish && npm run open-vsx:publish"
},
"devDependencies": {
"@types/capitalize": "2.0.0",
"@types/dotenv": "8.2.0",
"@types/mocha": "5.2.7",
"@types/node": "16.11.26",
"@types/node-fetch": "3.0.3",
"@types/vscode": "1.62.0",
"@types/escape-html": "^1.0.2",
"@types/ws": "8.2.2",
"esbuild": "0.15.1",
"ovsx": "0.3.0",
"vsce": "2.6.7"
},
"dependencies": {
"@urql/core": "2.6.1",
"babel-polyfill": "6.26.0",
"capitalize": "2.0.4",
"dotenv": "10.0.0",
"escape-html": "1.0.3",
"graphql-config": "4.3.0",
"graphql-tag": "2.12.6",
"graphql-ws": "5.10.0",
"@whatwg-node/fetch": "0.2.8",
"ws": "8.8.1",
"graphql": "^16.4.0",
"nullthrows": "^1.1.1"
},
"resolutions": {
"cosmiconfig": "^5.0.1"
}
}
Loading

0 comments on commit 324fbed

Please sign in to comment.