Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[apollo-language-server] Allow config.client.service.localSchemaFile #676

Merged
merged 2 commits into from
Nov 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
19 changes: 14 additions & 5 deletions packages/apollo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -422,40 +422,49 @@ module.exports = {

### Service Configuration

When linking a client to a service, you can either use the name of a service that has been published to the Apollo service registry, or you can use a remote url that supports introspection
When linking a client to a service, you can either use the name of a service that has been published to the Apollo service registry, or you can use a remote url that supports introspection or you can provide a filepath of a generated SDL (Schema Definition Language) file, for example: `schema.json` or `schema.graphql`.

```js
module.exports = {
client: {
service: "my-service-name",

// or
service: {
name: "my-service-name",
url: "http://example.com/graphql",
headers: {
cookie: "myCookieValue"
}
},

// or a local generated schema file
service: {
name: "my-service-name",
localSchemaFile: "./path/to/schema.graphl"
}
}
};
```

## Service settings

The service config needs to know how to fetch the schema for that service. This can be done with either an endpoint config or a filepath of a generated SDL file
The service config needs to know how to fetch the schema for that service. This can be done with either an endpoint config or a filepath of a generated SDL (Schema Definition Language) file, for example: `schema.json` or `schema.graphql`.

```js
module.exports = {
service: {
name: "my-service",

// this is the default endpoint info
endpoint: {
url: "https://localhost:4000/graphql"
},
// or a local generated schema
localSchemaFile: "./path/to/sdl.graphql"

// or a local generated schema file
localSchemaFile: "./path/to/schema.graphl"
}
}
};
```

# Code Generation
Expand Down