Skip to content

Commit

Permalink
Add support for localSchemaFile option in client config
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan Nowak committed Nov 10, 2018
1 parent 6f6ca7d commit fd30430
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
15 changes: 14 additions & 1 deletion packages/apollo-language-server/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ export interface RemoteServiceConfig {
skipSSLValidation?: boolean;
}

export interface LocalServiceConfig {
name: ServiceID;
localSchemaFile: string;
}

export interface EngineConfig {
endpoint?: EndpointURI;
frontend?: EndpointURI;
Expand All @@ -54,9 +59,11 @@ export interface ConfigBase {
excludes: string[];
}

export type ClientServiceConfig = RemoteServiceConfig | LocalServiceConfig;

export interface ClientConfigFormat extends ConfigBase {
// service linking
service?: ServiceSpecifier | RemoteServiceConfig;
service?: ServiceSpecifier | ClientServiceConfig;
// client identity
name?: ClientID;
referenceID?: string;
Expand Down Expand Up @@ -230,6 +237,12 @@ export function isClientConfig(config: ApolloConfig): config is ClientConfig {
return config.isClient;
}

export function isLocalServiceConfig(
config: ClientServiceConfig
): config is LocalServiceConfig {
return !!(config as LocalServiceConfig).localSchemaFile;
}

export function isServiceConfig(config: ApolloConfig): config is ServiceConfig {
return config.isService;
}
Expand Down
18 changes: 16 additions & 2 deletions packages/apollo-language-server/src/schema/providers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ import {
SchemaChangeUnsubscribeHandler,
SchemaResolveConfig
} from "./base";
import { ApolloConfig, isClientConfig, isServiceConfig } from "../../config";
import {
ApolloConfig,
isClientConfig,
isServiceConfig,
isLocalServiceConfig
} from "../../config";

import { IntrospectionSchemaProvider } from "./introspection";
import { EngineSchemaProvider } from "./engine";
Expand All @@ -22,6 +27,7 @@ export function schemaProviderFromConfig(
if (config.service.localSchemaFile) {
return new FileSchemaProvider({ path: config.service.localSchemaFile });
}

if (config.service.endpoint) {
return new IntrospectionSchemaProvider(config.service.endpoint);
}
Expand All @@ -30,7 +36,15 @@ export function schemaProviderFromConfig(
if (isClientConfig(config)) {
if (typeof config.client.service === "string") {
return new EngineSchemaProvider(config);
} else if (config.client.service) {
}

if (config.client.service) {
if (isLocalServiceConfig(config.client.service)) {
return new FileSchemaProvider({
path: config.client.service.localSchemaFile
});
}

return new IntrospectionSchemaProvider(config.client.service);
}
}
Expand Down

0 comments on commit fd30430

Please sign in to comment.