Skip to content

Commit

Permalink
Temporarily remove run query / webview in VSCode extension (#605)
Browse files Browse the repository at this point in the history
Remove run query feature for now, to be re-introduced in the future.
Revert this commit as a jumping off point for pulling it back in.
  • Loading branch information
trevor-scheer authored Oct 9, 2018
1 parent 36a3f2e commit 11fc68a
Show file tree
Hide file tree
Showing 13 changed files with 143 additions and 3,854 deletions.
3,223 changes: 136 additions & 3,087 deletions package-lock.json

Large diffs are not rendered by default.

16 changes: 2 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@
"apollo-codegen-typescript": "file:packages/apollo-codegen-typescript",
"apollo-codegen-typescript-legacy": "file:packages/apollo-codegen-typescript-legacy",
"apollo-language-server": "file:packages/apollo-language-server",
"apollo-vscode": "file:packages/apollo-vscode",
"apollo-vscode-webview": "file:packages/apollo-vscode-webview",
"webpack-command": "^0.4.1"
"apollo-vscode": "file:packages/apollo-vscode"
},
"devDependencies": {
"@fancy-test/nock": "^0.1.1",
Expand All @@ -64,11 +62,7 @@
"@types/react-dom": "^16.0.7",
"@types/recursive-readdir": "^2.2.0",
"@types/ws": "^6.0.0",
"babel-loader": "^7.1.2",
"babel-preset-react-app": "^3.1.2",
"case-sensitive-paths-webpack-plugin": "2.1.2",
"chai": "^4.1.2",
"css-loader": "1.0.0",
"fs-monkey": "^0.3.3",
"graphql": "^0.13.2",
"husky": "^0.14.3",
Expand All @@ -80,17 +74,11 @@
"memfs": "^2.9.4",
"nock": "^9.6.1",
"prettier": "1.14.2",
"style-loader": "0.23.0",
"ts-jest": "^23.1.4",
"ts-loader": "^4.5.0",
"ts-node": "^7.0.1",
"tsconfig-paths-webpack-plugin": "^3.2.0",
"tslib": "^1.9.3",
"typescript": "^3.0.3",
"uglifyjs-webpack-plugin": "^1.3.0",
"url-loader": "1.1.1",
"vsce": "^1.46.0",
"webpack": "4.17.1"
"vsce": "^1.46.0"
},
"jest": {
"projects": [
Expand Down
45 changes: 2 additions & 43 deletions packages/apollo-language-server/src/languageProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ import {
import {
GraphQLNamedType,
Kind,
visit,
FragmentSpreadNode,
GraphQLField,
GraphQLNonNull,
isAbstractType,
Expand Down Expand Up @@ -392,50 +390,11 @@ ${argumentNode.description}

let codeLenses: CodeLens[] = [];

for (const { doc, set } of docsAndSets) {
for (const { doc } of docsAndSets) {
if (!doc.ast) continue;

for (const definition of doc.ast.definitions) {
if (definition.kind === Kind.OPERATION_DEFINITION) {
if (set.endpoint) {
const fragmentSpreads: Set<
graphql.FragmentDefinitionNode
> = new Set();
const searchForReferencedFragments = (node: graphql.ASTNode) => {
visit(node, {
FragmentSpread(node: FragmentSpreadNode) {
const fragDefn = project.fragments[node.name.value];
if (!fragDefn) return;

if (!fragmentSpreads.has(fragDefn)) {
fragmentSpreads.add(fragDefn);
searchForReferencedFragments(fragDefn);
}
}
});
};

searchForReferencedFragments(definition);

codeLenses.push({
range: rangeForASTNode(definition),
command: Command.create(
`Run ${definition.operation}`,
"apollographql.runQuery",
graphql.parse(
[definition, ...fragmentSpreads]
.map(n => graphql.print(n))
.join("\n")
),
definition.operation === "subscription"
? set.endpoint.subscriptions
: set.endpoint.url,
set.endpoint.headers,
graphql.printSchema(set.schema!)
)
});
}
} else if (definition.kind === Kind.FRAGMENT_DEFINITION) {
if (definition.kind === Kind.FRAGMENT_DEFINITION) {
const references = project.fragmentSpreadsForFragment(
definition.name.value
);
Expand Down
146 changes: 3 additions & 143 deletions packages/apollo-language-server/src/server.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,15 @@
import { dirname } from "path";
import {
createConnection,
ProposedFeatures,
TextDocuments,
FileChangeType,
NotificationType
} from "vscode-languageserver";

import { GraphQLWorkspace } from "./workspace";
import { GraphQLLanguageProvider } from "./languageProvider";

import { execute, DocumentNode } from "apollo-link";
import { createHttpLink } from "apollo-link-http";
import fetch from "node-fetch";
import { OperationDefinitionNode } from "graphql";

import { WebSocketLink } from "apollo-link-ws";
import { SubscriptionClient } from "subscriptions-transport-ws";

import Uri from "vscode-uri";

import * as ws from "ws";

import { dirname } from "path";
import { findAndLoadConfig } from "apollo/lib/config";
import { GraphQLWorkspace } from "./workspace";
import { GraphQLLanguageProvider } from "./languageProvider";

const connection = createConnection(ProposedFeatures.all);

Expand Down Expand Up @@ -131,12 +118,6 @@ connection.onInitialize(async params => {
codeLensProvider: {
resolveProvider: false
},
executeCommandProvider: {
commands: [
"apollographql.runQuery",
"apollographql.runQueryWithVariables"
]
},
textDocumentSync: documents.syncKind
}
};
Expand Down Expand Up @@ -244,125 +225,4 @@ connection.onCodeLens((params, token) => {
return languageProvider.provideCodeLenses(params.textDocument.uri, token);
});

const createSubscriptionLink = (endpoint: string) => {
const client = new SubscriptionClient(
endpoint,
{
reconnect: true
},
ws
);

return new WebSocketLink(client);
};

const cancellationFunctions: { [id: number]: () => void } = {};
let nextCancellationID = 1;

export const executeAndNotify = (
query: DocumentNode,
endpoint: string,
headers: any,
variables: any
) => {
const operation = query.definitions[0] as OperationDefinitionNode;
const link =
operation.operation === "subscription"
? createSubscriptionLink(endpoint)
: createHttpLink({ uri: endpoint, fetch } as any);

const cancellationID = nextCancellationID;
nextCancellationID++;

const sub = execute(link, {
query,
variables,
context: { headers }
}).subscribe(
value => {
connection.sendNotification(
new NotificationType<any, void>("apollographql/queryResult"),
{ result: value, cancellationID }
);
},
error => {
if (error.result) {
connection.sendNotification(
new NotificationType<any, void>("apollographql/queryResult"),
{ result: error.result, cancellationID }
);
} else {
connection.sendNotification(
new NotificationType<any, void>("apollographql/queryResult"),
{ result: { errors: [error] }, cancellationID }
);
}
}
);

connection.sendNotification(
new NotificationType<any, void>("apollographql/queryResult"),
{ result: "Loading...", cancellationID }
);

cancellationFunctions[cancellationID] = () => {
sub.unsubscribe();
};
};

const operationHasVariables = (operation: OperationDefinitionNode) => {
return (
operation.variableDefinitions && operation.variableDefinitions.length > 0
);
};

connection.onExecuteCommand(params => {
switch (params.command) {
case "apollographql.runQuery":
const operation = (params.arguments![0] as DocumentNode)
.definitions[0] as OperationDefinitionNode;
if (operationHasVariables(operation)) {
connection.sendNotification(
new NotificationType<any, void>("apollographql/requestVariables"),
{
query: params.arguments![0],
endpoint: params.arguments![1],
headers: params.arguments![2],
schema: params.arguments![3],
requestedVariables: operation.variableDefinitions!.map(v => {
return {
name: v.variable.name.value,
typeNode: v.type
};
})
}
);
} else {
executeAndNotify(
params.arguments![0],
params.arguments![1],
params.arguments![2],
{}
);
}

break;

default:
}
});

connection.onNotification(
"apollographql/runQueryWithVariables",
({ query, endpoint, headers, variables }) => {
executeAndNotify(query, endpoint, headers, variables);
}
);

connection.onNotification("apollographql/cancelQuery", ({ cancellationID }) => {
cancellationFunctions[cancellationID]();
delete cancellationFunctions[cancellationID];
});

// Listen on the connection
connection.listen();
2 changes: 0 additions & 2 deletions packages/apollo-vscode-webview/graphiql.d.ts

This file was deleted.

30 changes: 0 additions & 30 deletions packages/apollo-vscode-webview/package.json

This file was deleted.

74 changes: 0 additions & 74 deletions packages/apollo-vscode-webview/src/App.tsx

This file was deleted.

Loading

0 comments on commit 11fc68a

Please sign in to comment.