Skip to content

Commit

Permalink
Turn on noUnusedLocals and noUnusedParameters (#1126)
Browse files Browse the repository at this point in the history
  • Loading branch information
glasser authored and evans committed Jun 1, 2018
1 parent 561033a commit 836616b
Show file tree
Hide file tree
Showing 24 changed files with 69 additions and 90 deletions.
2 changes: 1 addition & 1 deletion packages/apollo-server-adonis/src/adonisApollo.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// tslint:disable: variable-name no-var-requires
import { ioc, registrar, resolver } from '@adonisjs/fold';
import { ioc, registrar } from '@adonisjs/fold';
import { setupResolver, Config } from '@adonisjs/sink';
import { graphqlAdonis, graphiqlAdonis } from './adonisApollo';
import { GraphQLOptions } from 'apollo-server-core';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import 'mocha';
import * as url from 'url';

function createFunction(options: CreateAppOptions = {}) {
let route, callback, context;
let route, context;
let handler: AzureFunctionsHandler;

options.graphqlOptions = options.graphqlOptions || { schema: Schema };
Expand Down
1 change: 0 additions & 1 deletion packages/apollo-server-cloudflare/src/cloudflareApollo.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as url from 'url';
import {
GraphQLOptions,
HttpQueryError,
Expand Down
17 changes: 7 additions & 10 deletions packages/apollo-server-core/src/ApolloServer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
GraphQLSchema,
GraphQLObjectType,
GraphQLString,
GraphQLInt,
GraphQLError,
ValidationContext,
FieldDefinitionNode,
Expand Down Expand Up @@ -65,7 +64,6 @@ const schema = new GraphQLSchema({

function createHttpServer(server) {
return http.createServer(async (req, res) => {
const result = {};
let body: any = [];
req
.on('data', chunk => {
Expand Down Expand Up @@ -339,7 +337,7 @@ describe('ApolloServerBase', () => {
`;
const resolvers = {
Query: {
hello: (parent, args, context) => {
hello: (_parent, _args, context) => {
expect(context).to.equal(Promise.resolve(uniqueContext));
return 'hi';
},
Expand Down Expand Up @@ -379,15 +377,15 @@ describe('ApolloServerBase', () => {
`;
const resolvers = {
Query: {
hello: (parent, args, context) => {
hello: () => {
throw Error('never get here');
},
},
};
const server = new ApolloServerBase({
typeDefs,
resolvers,
context: ({ req }) => {
context: () => {
throw new AuthenticationError('valid result');
},
});
Expand Down Expand Up @@ -628,7 +626,7 @@ describe('ApolloServerBase', () => {
getHttp: () => httpServer,
path: '/graphql',
});
server.listen({}).then(({ url: uri, port }) => {
server.listen({}).then(({ port }) => {
const client = new SubscriptionClient(
`ws://localhost:${port}${server.subscriptionsPath}`,
{},
Expand Down Expand Up @@ -703,7 +701,7 @@ describe('ApolloServerBase', () => {
.listen({
subscriptions: false,
})
.then(({ url: uri, port }) => {
.then(({ port }) => {
const client = new SubscriptionClient(
`ws://localhost:${port}${server.subscriptionsPath}`,
{},
Expand All @@ -712,7 +710,6 @@ describe('ApolloServerBase', () => {

const observable = client.request({ query });

let i = 1;
subscription = observable.subscribe({
next: () => {
done(new Error('should not call next'));
Expand All @@ -731,7 +728,7 @@ describe('ApolloServerBase', () => {
//the behavior with an option in the client constructor. If you're
//available to make a PR to the following please do!
//https://github.com/apollographql/subscriptions-transport-ws/blob/master/src/client.ts
client.onError((err: Error) => {
client.onError((_: Error) => {
done();
});
});
Expand Down Expand Up @@ -787,7 +784,7 @@ describe('ApolloServerBase', () => {
.listen({
subscriptions: { onConnect, path },
})
.then(({ url: uri, port }) => {
.then(({ port }) => {
expect(onConnect.notCalled).true;

expect(server.subscriptionsPath).to.equal(path);
Expand Down
16 changes: 11 additions & 5 deletions packages/apollo-server-core/src/ApolloServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
subscribe,
ExecutionResult,
GraphQLError,
GraphQLResolveInfo,
GraphQLFieldResolver,
ValidationContext,
FieldDefinitionNode,
} from 'graphql';
Expand All @@ -28,12 +28,11 @@ import {

import { formatApolloErrors } from './errors';
import { GraphQLServerOptions as GraphQLOptions } from './graphqlOptions';
import { LogFunction, LogAction, LogStep } from './logging';
import { LogFunction } from './logging';

import {
Config,
ListenOptions,
MiddlewareOptions,
RegistrationOptions,
ServerInfo,
Context,
Expand Down Expand Up @@ -71,7 +70,7 @@ export class ApolloServerBase<Request = RequestInit> {
private subscriptionServer?: SubscriptionServer;
protected getHttp: () => HttpServer;

constructor(config: Config<Request>) {
constructor(config: Config) {
const {
context,
resolvers,
Expand Down Expand Up @@ -374,7 +373,14 @@ export class ApolloServerBase<Request = RequestInit> {
schema: this.schema,
extensions: this.extensions,
context,
// allow overrides from options
// Allow overrides from options. Be explicit about a couple of them to
// avoid a bad side effect of the otherwise useful noUnusedLocals option
// (https://github.com/Microsoft/TypeScript/issues/21673).
logFunction: this.requestOptions.logFunction as LogFunction,
fieldResolver: this.requestOptions.fieldResolver as GraphQLFieldResolver<
any,
any
>,
...this.requestOptions,
};
}
Expand Down
6 changes: 3 additions & 3 deletions packages/apollo-server-core/src/errors.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* tslint:disable:no-unused-expression */
import { expect } from 'chai';
import { stub, spy } from 'sinon';
import { stub } from 'sinon';
import 'mocha';

import { GraphQLError } from 'graphql';
Expand Down Expand Up @@ -108,7 +108,7 @@ describe('Errors', () => {
it('calls logFunction with each error', () => {
const error = new ApolloError(message, code, { key });
const logFunction = stub();
const formattedError = formatApolloErrors([error], {
formatApolloErrors([error], {
logFunction,
debug: true,
});
Expand All @@ -121,7 +121,7 @@ describe('Errors', () => {
it('calls formatter after exposing the code and stacktrace', () => {
const error = new ApolloError(message, code, { key });
const formatter = stub();
const formattedError = formatApolloErrors([error], {
formatApolloErrors([error], {
formatter,
debug: true,
});
Expand Down
2 changes: 1 addition & 1 deletion packages/apollo-server-core/src/errors.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { GraphQLError } from 'graphql';
import { LogStep, LogAction, LogMessage, LogFunction } from './logging';
import { LogStep, LogAction, LogFunction } from './logging';

export class ApolloError extends Error implements GraphQLError {
public extensions: Record<string, any>;
Expand Down
10 changes: 2 additions & 8 deletions packages/apollo-server-core/src/runHttpQuery.test.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
/* tslint:disable:no-unused-expression */
import { expect } from 'chai';
import { stub } from 'sinon';
import 'mocha';
import * as MockReq from 'mock-req';

import {
GraphQLSchema,
GraphQLObjectType,
GraphQLString,
GraphQLInt,
} from 'graphql';
import { GraphQLSchema, GraphQLObjectType, GraphQLString } from 'graphql';

import { runHttpQuery, HttpQueryError } from './runHttpQuery';
import { runHttpQuery } from './runHttpQuery';

const queryType = new GraphQLObjectType({
name: 'QueryType',
Expand Down
2 changes: 1 addition & 1 deletion packages/apollo-server-core/src/runHttpQuery.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { parse, DocumentNode, ExecutionResult } from 'graphql';
import { ExecutionResult } from 'graphql';
import { runQuery, QueryOptions } from './runQuery';
import {
default as GraphQLOptions,
Expand Down
16 changes: 8 additions & 8 deletions packages/apollo-server-core/src/runQuery.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ const queryType = new GraphQLObjectType({
},
testContextValue: {
type: GraphQLString,
resolve(root, args, context) {
resolve(_root, _args, context) {
return context + ' works';
},
},
testArgumentValue: {
type: GraphQLInt,
resolve(root, args, context) {
resolve(_root, args) {
return args['base'] + 5;
},
args: {
Expand All @@ -70,7 +70,7 @@ const queryType = new GraphQLObjectType({
},
testAwaitedValue: {
type: GraphQLString,
resolve(root) {
resolve() {
// Calling Promise.await is legal here even though this is
// not an async function, because we are guaranteed to be
// running in a Fiber.
Expand Down Expand Up @@ -138,7 +138,7 @@ describe('runQuery', () => {
queryString: query,
debug: true,
request: new MockReq(),
}).then(res => {
}).then(() => {
logStub.restore();
expect(logStub.callCount).to.equal(0);
});
Expand All @@ -152,7 +152,7 @@ describe('runQuery', () => {
queryString: query,
debug: false,
request: new MockReq(),
}).then(res => {
}).then(() => {
logStub.restore();
expect(logStub.callCount).to.equal(0);
});
Expand Down Expand Up @@ -376,7 +376,6 @@ describe('runQuery', () => {

it('creates the extension stack', async () => {
const queryString = `{ testString }`;
const expected = { testString: 'it works' };
const extensions = [() => new CustomExtension()];
return runQuery({
schema: new GraphQLSchema({
Expand All @@ -385,7 +384,7 @@ describe('runQuery', () => {
fields: {
testString: {
type: GraphQLString,
resolve(root, args, context) {
resolve(_root, _args, context) {
expect(context._extensionStack).to.be.instanceof(
GraphQLExtensionStack,
);
Expand Down Expand Up @@ -413,7 +412,8 @@ describe('runQuery', () => {
extensions,
request: new MockReq(),
}).then(res => {
return expect(res.extensions).to.deep.equal({
expect(res.data).to.deep.equal(expected);
expect(res.extensions).to.deep.equal({
customExtension: { foo: 'bar' },
});
});
Expand Down
4 changes: 1 addition & 3 deletions packages/apollo-server-core/src/runQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {
enableGraphQLExtensions,
GraphQLExtension,
GraphQLExtensionStack,
EndHandler,
} from 'graphql-extensions';
import { TracingExtension } from 'apollo-tracing';
import { CacheControlExtension } from 'apollo-cache-control';
Expand All @@ -30,8 +29,7 @@ import {
SyntaxError,
} from './errors';

import { LogStep, LogAction, LogMessage, LogFunction } from './logging';
import { GraphQLRequest } from 'apollo-fetch';
import { LogStep, LogAction, LogFunction } from './logging';

export interface GraphQLResponse {
data?: object;
Expand Down
2 changes: 1 addition & 1 deletion packages/apollo-server-core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export interface SubscriptionServerOptions {
onDisconnect?: (websocket: WebSocket, context: ConnectionContext) => any;
}

export interface Config<Server>
export interface Config
extends Pick<
GraphQLOptions<Context<any>>,
| 'formatError'
Expand Down
11 changes: 5 additions & 6 deletions packages/apollo-server-express/src/ApolloServer.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { expect } from 'chai';
import { stub } from 'sinon';
import 'mocha';
import * as express from 'express';

Expand Down Expand Up @@ -244,7 +243,7 @@ describe('apollo-server-express', () => {
url: `http://localhost:${port}/.well-known/apollo/server-health`,
method: 'GET',
},
(error, response, body) => {
(error, response) => {
if (error) {
reject(error);
} else {
Expand Down Expand Up @@ -276,10 +275,10 @@ describe('apollo-server-express', () => {
`,
resolvers: {
Query: {
uploads: (parent, args) => {},
uploads: () => {},
},
Mutation: {
singleUpload: async (parent, args) => {
singleUpload: async (_, args) => {
expect((await args.file).stream).to.exist;
return args.file;
},
Expand Down Expand Up @@ -348,15 +347,15 @@ describe('apollo-server-express', () => {
`;
const resolvers = {
Query: {
hello: (parent, args, context) => {
hello: () => {
throw Error('never get here');
},
},
};
server = new ApolloServer({
typeDefs,
resolvers,
context: ({ req }) => {
context: () => {
throw new AuthenticationError('valid result');
},
});
Expand Down
6 changes: 3 additions & 3 deletions packages/apollo-server-express/src/ApolloServer.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as express from 'express';
import * as corsMiddleware from 'cors';
import { json, OptionsJson } from 'body-parser';
import { createServer, Server as HttpServer } from 'http';
import { createServer } from 'http';
import gui from 'graphql-playground-middleware-express';
import { ApolloServerBase, formatApolloErrors } from 'apollo-server-core';
import * as accepts from 'accepts';
Expand Down Expand Up @@ -71,7 +71,7 @@ export const registerServer = async ({

if (!disableHealthCheck) {
//uses same path as engine
app.use('/.well-known/apollo/server-health', (req, res, next) => {
app.use('/.well-known/apollo/server-health', (req, res) => {
//Response follows https://tools.ietf.org/html/draft-inadarei-api-health-check-01
res.type('application/health+json');

Expand Down Expand Up @@ -114,7 +114,7 @@ export const registerServer = async ({
path,
corsMiddleware(cors),
json(bodyParserConfig),
uploadsMiddleware ? uploadsMiddleware : (req, res, next) => next(),
uploadsMiddleware ? uploadsMiddleware : (_req, _res, next) => next(),
(req, res, next) => {
// make sure we check to see if graphql gui should be on
if (!server.disableTools && req.method === 'GET') {
Expand Down
Loading

0 comments on commit 836616b

Please sign in to comment.