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 16, 2021
1 parent e9af3f6 commit 8f78377
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 18 deletions.
14 changes: 13 additions & 1 deletion src/language-server/engine/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { GraphQLDataSource } from "./GraphQLDataSource";
import { DefaultEngineConfig } from "../config";
import { SCHEMA_TAGS_AND_FIELD_STATS } from "./operations/schemaTagsAndFieldStats";
import { SchemaTagsAndFieldStatsQuery } from "../graphqlTypes";
import {
FrontendUrlRootQuery,
SchemaTagsAndFieldStatsQuery,
} from "../graphqlTypes";
import { FRONTEND_URL_ROOT } from "./operations/frontendUrlRoot";

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

return { schemaTags, fieldLatencies };
}

async loadFrontendUrlRoot() {
const { data } = await this.execute<FrontendUrlRootQuery>({
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
}
`;
30 changes: 22 additions & 8 deletions src/language-server/graphqlTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ export type Scalars = {
/** Long type */
Long: any;
GraphQLDocument: any;
/** A lowercase hexadecimal SHA-256 */
SHA256: any;
/** Arbitrary JSON object */
Object: any;
/** A blob (base64'ed in JSON & GraphQL) */
Blob: any;
StringOrInt: any;
/** Always null */
Void: any;
/** A lowercase hexadecimal SHA-256 */
SHA256: any;
};

export type Query = {
Expand Down Expand Up @@ -349,6 +349,8 @@ export type Service = Identity & {
deletedAt: Maybe<Scalars['Timestamp']>;
description: Maybe<Scalars['String']>;
devGraphOwner: Maybe<User>;
/** Get a graphql by hash */
document: Maybe<Scalars['String']>;
firstReportedAt: Maybe<Scalars['Timestamp']>;
/**
* When this is true, this graph will be hidden from non-admin members of the org who haven't been explicitly assigned a
Expand Down Expand Up @@ -458,6 +460,11 @@ export type ServiceCompositionResultByIdArgs = {
};


export type ServiceDocumentArgs = {
hash: Maybe<Scalars['SHA256']>;
};


export type ServiceImplementingServicesArgs = {
graphVariant: Scalars['String'];
includeDeleted: Maybe<Scalars['Boolean']>;
Expand Down Expand Up @@ -715,6 +722,8 @@ export type GraphVariant = {
__typename?: 'GraphVariant';
/** As new schema tags keep getting published, activeSchemaPublish refers to the latest. */
activeSchemaPublish: Maybe<SchemaTag>;
/** Filter configuration used to create the contract schema */
contractFilterConfig: Maybe<FilterConfig>;
/** Explorer setting for default headers for a graph */
defaultHeaders: Maybe<Scalars['String']>;
derivedVariantCount: Scalars['Int'];
Expand Down Expand Up @@ -1472,6 +1481,12 @@ export type TypeFilterConfig = {
includeIntrospectionTypes: Maybe<Scalars['Boolean']>;
};

export type FilterConfig = {
__typename?: 'FilterConfig';
exclude: Array<Scalars['String']>;
include: Array<Scalars['String']>;
};

export type Launch = {
__typename?: 'Launch';
approvedAt: Maybe<Scalars['Timestamp']>;
Expand Down Expand Up @@ -1523,12 +1538,6 @@ export type FilterBuildInput = {
schemaHash: Scalars['String'];
};

export type FilterConfig = {
__typename?: 'FilterConfig';
exclude: Array<Scalars['String']>;
include: Array<Scalars['String']>;
};

export type BuildResult = BuildFailure | BuildSuccess;

export type BuildFailure = {
Expand Down Expand Up @@ -7494,6 +7503,11 @@ export type Uri = {
gcs: Scalars['String'];
};

export type FrontendUrlRootQueryVariables = Exact<{ [key: string]: never; }>;


export type FrontendUrlRootQuery = { __typename?: 'Query', frontendUrlRoot: string };

export type SchemaTagsAndFieldStatsQueryVariables = Exact<{
id: Scalars['ID'];
}>;
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 @@ -54,6 +54,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 @@ -98,6 +99,7 @@ export class GraphQLClientProject extends GraphQLProject {
private _onSchemaTags?: NotificationHandler<[ServiceID, SchemaTag[]]>;

private fieldLatencies?: FieldLatencies;
private frontendUrlRoot?: string;

private _validationRules?: ValidationRule[];

Expand Down Expand Up @@ -332,16 +334,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, fieldLatencies } =
await engineClient.loadSchemaTagsAndFieldLatencies(serviceID);
this._onSchemaTags && this._onSchemaTags([serviceID, schemaTags]);
this.fieldLatencies = fieldLatencies;
if (serviceID) {
const { schemaTags, fieldLatencies } =
await engineClient.loadSchemaTagsAndFieldLatencies(serviceID);
this._onSchemaTags && this._onSchemaTags([serviceID, schemaTags]);
this.fieldLatencies = fieldLatencies;
}
const frontendUrlRoot = await engineClient.loadFrontendUrlRoot();
this.frontendUrlRoot = frontendUrlRoot;
this.lastLoadDate = +new Date();

this.generateDecorations();
Expand Down Expand Up @@ -396,18 +401,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 8f78377

Please sign in to comment.