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

Scan all files for queries and reduce use of default endpoints #526

Merged
merged 1 commit into from
Aug 3, 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
2 changes: 1 addition & 1 deletion packages/apollo-cli/src/commands/codegen/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ export default class Generate extends Command {
}

const tasks: Listr = new Listr([
loadConfigStep(flags),
loadConfigStep(flags, false),
{
title: "Resolving GraphQL document sets and dependencies",
task: async (ctx, task) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/apollo-cli/src/commands/schema/check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export default class SchemaCheck extends Command {
const { flags } = this.parse(SchemaCheck);

const tasks = new Listr([
loadConfigStep(flags),
loadConfigStep(flags, true),
{
title: "Fetching local schema",
task: async ctx => {
Expand Down
4 changes: 2 additions & 2 deletions packages/apollo-cli/src/commands/schema/download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export default class SchemaDownload extends Command {
const { flags, args } = this.parse(SchemaDownload);

const tasks: Listr = new Listr([
loadConfigStep(flags),
loadConfigStep(flags, false),
{
title: "Fetching current schema",
task: async ctx => {
Expand All @@ -67,7 +67,7 @@ export default class SchemaDownload extends Command {
ctx.schema = await loadSchema(
Object.values(ctx.config.schemas)[0],
ctx.config
).catch(this.error);
);
}
},
{
Expand Down
10 changes: 7 additions & 3 deletions packages/apollo-cli/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,13 @@ function loadDocumentSet(obj: any): DocumentSet {
? [obj.includes as string]
: obj.includes
? (obj.includes as string[])
: ["**/*.graphql"],
: ["**"],
excludes:
typeof obj.excludes === "string"
? [obj.excludes as string]
: obj.excludes
? (obj.excludes as string[])
: ["node_modules"]
: ["node_modules/**"]
};
}

Expand Down Expand Up @@ -124,7 +124,11 @@ export function loadConfig(
? Array.isArray(obj.queries)
? (obj.queries as any[])
: [obj.queries]
: []
: (
Object.keys(schemasObj).length == 1 ?
[ { schema: Object.keys(schemasObj)[0] } ] :
[]
)
).map(d => loadDocumentSet(d)),
engineEndpoint: obj.engineEndpoint
};
Expand Down
2 changes: 1 addition & 1 deletion packages/apollo-cli/src/load-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { ListrTask } from "listr";

export function loadConfigStep(
flags: any,
defaultEndpoint: boolean = true
defaultEndpoint: boolean
): ListrTask {
const header: any[] = Array.isArray(flags.header)
? flags.header
Expand Down
21 changes: 18 additions & 3 deletions packages/apollo-codegen-core/src/loading.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ export function loadQueryDocuments(
): DocumentNode[] {
const sources = inputPaths
.map(inputPath => {
if (fs.lstatSync(inputPath).isDirectory()) {
return null;
}

const body = fs.readFileSync(inputPath, "utf8");
if (!body) {
return null;
Expand All @@ -99,11 +103,22 @@ export function loadQueryDocuments(
return doc ? new Source(doc, inputPath) : null;
}

return new Source(body, inputPath);
if (inputPath.endsWith(".graphql") || inputPath.endsWith(".gql")) {
return new Source(body, inputPath);
}

return null;
})
.filter(source => source);
.filter(source => source)
.map(source => {
try {
return parse(source!);
} catch {
return null;
}
}).filter(source => source);

return (sources as Source[]).map(source => parse(source));
return sources as DocumentNode[];
}

export function loadAndMergeQueryDocuments(
Expand Down