Skip to content

Commit

Permalink
Fix up link for alternate engine
Browse files Browse the repository at this point in the history
  • Loading branch information
jgzuke committed Sep 9, 2021
1 parent 4c6cecc commit 29d4422
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 10 deletions.
11 changes: 10 additions & 1 deletion src/language-server/engine/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { GraphQLDataSource } from "./GraphQLDataSource";
import { DefaultEngineConfig } from "../config";
import { SCHEMA_TAGS_AND_FIELD_STATS } from "./operations/schemaTagsAndFieldStats";
import { SchemaTagsAndFieldStats } from "../graphqlTypes";
import { FrontendUrlRoot, SchemaTagsAndFieldStats } from "../graphqlTypes";
import { FRONTEND_URL_ROOT } from "./operations/frontendUrlRoot";

export interface ClientIdentity {
name?: string;
Expand Down Expand Up @@ -92,4 +93,12 @@ export class ApolloEngineClient extends GraphQLDataSource {

return { schemaTags, fieldStats };
}

async loadFrontendUrlRoot() {
const { data } = await this.execute<FrontendUrlRoot>({
query: FRONTEND_URL_ROOT,
});

return data?.frontendUrlRoot;
}
}
7 changes: 7 additions & 0 deletions src/language-server/engine/operations/frontendUrlRoot.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import gql from "graphql-tag";

export const FRONTEND_URL_ROOT = gql`
query FrontendUrlRoot {
frontendUrlRoot
}
`;
16 changes: 16 additions & 0 deletions src/language-server/graphqlTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,22 @@ export interface GetSchemaByTagVariables {
// @generated
// This file was automatically generated and should not be edited.

// ====================================================
// GraphQL query operation: FrontendUrlRoot
// ====================================================

export interface FrontendUrlRoot {
/**
* Service by ID
*/
frontendUrlRoot: string;
}

/* tslint:disable */
/* eslint-disable */
// @generated
// This file was automatically generated and should not be edited.

// ====================================================
// GraphQL fragment: IntrospectionFullType
// ====================================================
Expand Down
27 changes: 18 additions & 9 deletions src/language-server/project/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import {
} from "../diagnostics";
import URI from "vscode-uri";
import type { EngineDecoration } from "src/messages";
import { join } from "path";

type Maybe<T> = null | undefined | T;

Expand Down Expand Up @@ -93,6 +94,7 @@ export class GraphQLClientProject extends GraphQLProject {
private _onSchemaTags?: NotificationHandler<[ServiceID, SchemaTag[]]>;

private fieldStats?: FieldStats;
private frontendUrlRoot?: string;

private _validationRules?: ValidationRule[];

Expand Down Expand Up @@ -327,16 +329,19 @@ export class GraphQLClientProject extends GraphQLProject {
if (!engineClient) return;

const serviceID = this.serviceID;
if (!serviceID) return;

await this.loadingHandler.handle(
`Loading Apollo data for ${this.displayName}`,
(async () => {
try {
const { schemaTags, fieldStats } =
await engineClient.loadSchemaTagsAndFieldStats(serviceID);
this._onSchemaTags && this._onSchemaTags([serviceID, schemaTags]);
this.fieldStats = fieldStats;
if (serviceID) {
const { schemaTags, fieldStats } =
await engineClient.loadSchemaTagsAndFieldStats(serviceID);
this._onSchemaTags && this._onSchemaTags([serviceID, schemaTags]);
this.fieldStats = fieldStats;
}
const frontendUrlRoot = await engineClient.loadFrontendUrlRoot();
this.frontendUrlRoot = frontendUrlRoot;
this.lastLoadDate = +new Date();

this.generateDecorations();
Expand Down Expand Up @@ -391,18 +396,22 @@ export class GraphQLClientProject extends GraphQLProject {
);

const frontendUrlRoot =
"https://studio-staging.apollographql.com"; // TODO
this.frontendUrlRoot ?? "https://studio.apollographql.com";

const endpoint = this.config.service?.endpoint;
const variant = this.config.variant;
const graphId = this.config.graph;
this.config.client.service;

const runInExplorerLink = graphId
? `${frontendUrlRoot}/${graphId}/engine/explorer?variant=${variant}&explorerURLState=${explorerURLState}`
: `${frontendUrlRoot}/sandbox/explorer?explorerURLState=${explorerURLState}${
const runInExplorerPath = graphId
? `${graphId}/engine/explorer?variant=${variant}&explorerURLState=${explorerURLState}`
: `/sandbox/explorer?explorerURLState=${explorerURLState}${
endpoint ? `&endpoint=${endpoint}` : ""
}`;
const runInExplorerLink = join(
frontendUrlRoot,
runInExplorerPath
);

decorations.push({
document: uri,
Expand Down

0 comments on commit 29d4422

Please sign in to comment.