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

Remove unused locals in Apollo CLI #489

Merged
merged 3 commits into from
Jul 9, 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
8 changes: 3 additions & 5 deletions packages/apollo-cli/src/commands/codegen/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ import * as path from "path";

import { TargetType, default as generate } from "../../generate";

import { buildClientSchema, buildSchema, parse, visit, GraphQLCompositeType, extendSchema, buildASTSchema } from "graphql";
import { buildClientSchema, visit, extendSchema, buildASTSchema } from "graphql";

import * as fg from "glob";
import { fs, withGlobalFS } from "apollo-codegen-core/lib/localfs";
import { promisify } from "util";
import { withGlobalFS } from "apollo-codegen-core/lib/localfs";

import { loadSchemaStep } from "../../load-schema";

Expand Down Expand Up @@ -235,9 +234,8 @@ export default class Generate extends Command {
}

const ast = foundDocuments[0];
const clientNodes: {parentType: string}[] = [];
visit(ast, {
enter(node, key, parent, path, ancestors) {
enter(node) {
if (node.kind == "FieldDefinition") {
(node as any).__client = true;
}
Expand Down
14 changes: 4 additions & 10 deletions packages/apollo-cli/src/commands/queries/check.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,23 @@
import "apollo-codegen-core/lib/polyfills";
import { Command, flags } from "@oclif/command";
import { color, table, styledJSON } from "heroku-cli-util";
import { table, styledJSON } from "heroku-cli-util";
import * as Listr from "listr";
import * as path from "path";
import { toPromise, execute } from "apollo-link";
import {
print,
buildClientSchema,
validate,
findDeprecatedUsages,
GraphQLError
} from "graphql";

import * as fg from "glob";
import { fs, withGlobalFS } from "apollo-codegen-core/lib/localfs";
import { promisify } from "util";
import { withGlobalFS } from "apollo-codegen-core/lib/localfs";

import { loadQueryDocuments } from "apollo-codegen-core/lib/loading";

import { engineFlags } from "../../engine-cli";
import { engineLink, getIdFromKey } from "../../engine";
import { gitInfo } from "../../git";
import { loadSchemaStep } from "../../load-schema";
import { VALIDATE_OPERATIONS } from "../../operations/validateOperations";
import { ChangeType, Change } from "../../printer/ast";
import { ChangeType } from "../../printer/ast";
import { format } from "../schema/check";

export default class CheckQueries extends Command {
Expand Down Expand Up @@ -82,7 +76,7 @@ export default class CheckQueries extends Command {
},
{
title: "Checking query compatibility with schema",
task: async (ctx, task) => {
task: async (ctx) => {
const gitContext = await gitInfo();

const variables = {
Expand Down
3 changes: 1 addition & 2 deletions packages/apollo-cli/src/commands/schema/check.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Command, flags } from "@oclif/command";
import chalk from "chalk";
import { color, table, styledJSON } from "heroku-cli-util";
import cli from "cli-ux";
import { table, styledJSON } from "heroku-cli-util";
import * as Listr from "listr";
import { GraphQLError } from "graphql";

Expand Down
2 changes: 0 additions & 2 deletions packages/apollo-cli/src/commands/schema/publish.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { Command, flags } from "@oclif/command";
import cli from "cli-ux";
import { table, styledJSON } from "heroku-cli-util";
import * as Listr from "listr";
import { toPromise, execute } from "apollo-link";
import * as util from "util";
import { GraphQLError } from "graphql";

import { UPLOAD_SCHEMA } from "../../operations/uploadSchema";
Expand Down
2 changes: 1 addition & 1 deletion packages/apollo-cli/src/engine-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { flags } from "@oclif/command";
export const engineFlags = {
key: flags.string({
description: "The API key for the Apollo Engine service",
default: (ctx) => process.env.ENGINE_API_KEY,
default: () => process.env.ENGINE_API_KEY,
}),
engine: flags.string({
description: "Reporting URL for a custom Apollo Engine deployment",
Expand Down
1 change: 0 additions & 1 deletion packages/apollo-cli/src/fetch-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import * as path from "path";
import fetch from "node-fetch";
import gql from "graphql-tag";
import {
ExecutionResult,
buildSchema,
execute as graphql,
introspectionQuery,
Expand Down
5 changes: 2 additions & 3 deletions packages/apollo-cli/src/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@ import { compileToIR, CompilerContext, CompilerOptions } from "apollo-codegen-co
import { compileToLegacyIR, CompilerOptions as LegacyCompilerOptions } from "apollo-codegen-core/lib/compiler/legacyIR";
import serializeToJSON from "apollo-codegen-core/lib/serializeToJSON";
import { BasicGeneratedFile } from "apollo-codegen-core/lib/utilities/CodeGenerator";
import { getFieldDef } from "apollo-codegen-core/lib/utilities/graphql";

import { generateSource as generateSwiftSource } from "apollo-codegen-swift";
import { generateSource as generateTypescriptLegacySource } from "apollo-codegen-typescript-legacy";
import { generateSource as generateFlowLegacySource } from "apollo-codegen-flow-legacy";
import { generateSource as generateFlowSource } from "apollo-codegen-flow";
import { generateSource as generateTypescriptSource } from "apollo-codegen-typescript";
import { generateSource as generateScalaSource } from "apollo-codegen-scala";
import { GraphQLSchema, TypeInfo, GraphQLCompositeType } from "graphql";
import { GraphQLSchema } from "graphql";
import { FlowCompilerOptions } from '../../apollo-codegen-flow/lib/language';

export type TargetType =
Expand Down Expand Up @@ -98,7 +97,7 @@ export default function generate(
}

else if (fs.existsSync(outputPath) && fs.statSync(outputPath).isDirectory()) {
generatedFiles.forEach(({ sourcePath, fileName, content }) => {
generatedFiles.forEach(({ fileName, content }) => {
outFiles[fileName] = {
output: content.fileContents + common
};
Expand Down
2 changes: 1 addition & 1 deletion packages/apollo-cli/src/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export interface Commit {
authorEmail: string | null;
}

export const gitInfo = async (path?: string) => {
export const gitInfo = async () => {
const { isCi, commit, slug, root } = ci();
const gitLoc = root ? root : findGitRoot();

Expand Down
3 changes: 0 additions & 3 deletions packages/apollo-cli/src/printer/ast.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import {
TypeNode,
GraphQLNamedType,
GraphQLField,
ASTKindToNode,
TypeDefinitionNode,
FieldDefinitionNode,
EnumValueDefinitionNode,
Expand Down
33 changes: 2 additions & 31 deletions packages/apollo-cli/src/printer/diff.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import {
GraphQLSchema,
GraphQLNamedType,
GraphQLObjectType,
GraphQLType,
astFromValue,
isScalarType,
isObjectType,
isInterfaceType,
Expand All @@ -16,16 +14,12 @@ import {
InputObjectTypeDefinitionNode,
ObjectTypeDefinitionNode,
EnumTypeDefinitionNode,
UnionTypeDefinitionNode,
} from "graphql";

import {
TypeMap,
ChangeType,
TypeKind,
Change,
DiffTypeMap,
DiffType,
DiffField,
DiffInputValue,
DiffEnum,
Expand Down Expand Up @@ -126,33 +120,11 @@ function typeKindName(type: GraphQLNamedType): string {
throw new TypeError("Unknown type " + type!.constructor.name);
}

const getKind = (type: GraphQLNamedType) => {
if (isScalarType(type)) {
return TypeKind.SCALAR;
} else if (isObjectType(type)) {
return TypeKind.OBJECT;
} else if (isInterfaceType(type)) {
return TypeKind.INTERFACE;
} else if (isUnionType(type)) {
return TypeKind.UNION;
} else if (isEnumType(type)) {
return TypeKind.ENUM;
} else if (isInputObjectType(type)) {
return TypeKind.INPUT_OBJECT;
} else if (isListType(type)) {
return TypeKind.LIST;
} else if (isNonNullType(type)) {
return TypeKind.NON_NULL;
}
throw new Error("Unknown kind of type: " + type);
};

const m = (text: any): string => "`" + text + "`";

// we use error throwing for control flow here
const diffTypesLeft = (
type: GraphQLNamedType,
current: TypeMap,
next: TypeMap,
changes: Change[]
) => {
Expand Down Expand Up @@ -485,7 +457,6 @@ const diffFieldsLeft = (
const diffTypesRight = (
type: GraphQLNamedType,
current: TypeMap,
next: TypeMap,
changes: Change[]
) => {
// if we have a new type we can early exit since thats the
Expand Down Expand Up @@ -794,7 +765,7 @@ const diffLeft = (current: TypeMap, next: TypeMap, changes: Change[]) => {
const oldType = current[typeName];
const newType = next[typeName];
try {
diffTypesLeft(oldType, current, next, changes);
diffTypesLeft(oldType, next, changes);
diffFieldsLeft(current[typeName], newType, changes);
} catch (r) {
if (r instanceof Error) throw r;
Expand All @@ -809,7 +780,7 @@ const diffRight = (next: TypeMap, current: TypeMap, changes: Change[]) => {
if (!newType.astNode) return;

try {
diffTypesRight(newType, current, next, changes);
diffTypesRight(newType, current, changes);
diffFieldsRight(current[typeName], newType, changes);
} catch (r) {
if (r instanceof Error) throw r;
Expand Down
12 changes: 2 additions & 10 deletions packages/apollo-cli/src/printer/print.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,6 @@ import { renderToStaticMarkup } from "react-dom/server";
import {
print,
GraphQLSchema,
GraphQLEnumValue,
GraphQLFieldMap,
GraphQLField,
GraphQLInputObjectType,
GraphQLInterfaceType,
GraphQLObjectType,
GraphQLScalarType,
GraphQLUnionType,
ASTKindToNode,
FieldDefinitionNode,
EnumValueDefinitionNode,
ObjectTypeDefinitionNode,
Expand All @@ -26,7 +17,6 @@ import {
ChangeType,
Change,
TypeKind,
DiffType,
DiffField,
DiffEnum
} from "./ast";
Expand Down Expand Up @@ -57,6 +47,8 @@ const nameFromKind = (kind: string) => {
return "interface";
case TypeKind.UNION:
return "union";
default:
return null;
}
};
const Fields: React.SFC<{
Expand Down
5 changes: 1 addition & 4 deletions packages/apollo-cli/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@
"baseUrl": ".",
"paths": {
"*": ["./@types/*"]
},
"noImplicitReturns": false,
"noUnusedParameters": false,
"noUnusedLocals": false
}
},
"include": ["./src/**/*"],
"exclude": [ "**/__tests__/*", "**/__mocks__/*" ]
Expand Down