Skip to content
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
19 changes: 13 additions & 6 deletions packages/apollo-language-server/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,18 @@ export type ApolloConfigFormat =

// config settings
const MODULE_NAME = "apollo";
const searchPlaces = [
const defaultSearchPlaces = [
"package.json",
`${MODULE_NAME}.config.js`,
`${MODULE_NAME}.config.ts`
];

// Based on order, a provided config file will take precedence over the defaults
const getSearchPlaces = (configFile?: string) => [
...(configFile ? [configFile] : []),
...defaultSearchPlaces
];

const loaders = {
// XXX improve types for config
".json": (cosmiconfig as any).loadJson as LoaderEntry,
Expand All @@ -130,7 +137,7 @@ export interface LoadConfigSettings {
// the current working directory to start looking for the config
// config loading only works on node so we default to
// process.cwd()
cwd: string;
configPath?: string;
name?: string;
type?: "service" | "client";
}
Expand Down Expand Up @@ -249,23 +256,23 @@ export function isServiceConfig(config: ApolloConfig): config is ServiceConfig {

// XXX load .env files automatically
export const loadConfig = async ({
cwd,
configPath,
name,
type
}: LoadConfigSettings): Promise<ConfigResult<ApolloConfig>> => {
const explorer = cosmiconfig(MODULE_NAME, {
searchPlaces,
searchPlaces: getSearchPlaces(configPath),
loaders
});

let loadedConfig = (await explorer.search(cwd)) as ConfigResult<
let loadedConfig = (await explorer.search(configPath)) as ConfigResult<
ApolloConfigFormat
>;

if (!loadedConfig) {
loadedConfig = {
isEmpty: false,
filepath: cwd || process.cwd(),
filepath: configPath || process.cwd(),
config:
type === "client"
? {
Expand Down
2 changes: 1 addition & 1 deletion packages/apollo-language-server/src/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export class GraphQLWorkspace {
`Loading Apollo Config in folder ${configFolder}`,
(async () => {
try {
const config = await loadConfig({ cwd: configFolder });
const config = await loadConfig({ configPath: configFolder });
return config && config.config;
} catch (e) {
console.error(e);
Expand Down
2 changes: 1 addition & 1 deletion packages/apollo/src/Command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export abstract class ProjectCommand extends Command {
service = getServiceFromKey(process.env.ENGINE_API_KEY);
if (flags.key) service = getServiceFromKey(flags.key);
const loadedConfig = await loadConfig({
cwd: flags.config,
configPath: flags.config,
name: service,
type: this.type
});
Expand Down