Rename ApolloOptions to GraphQLOptions

This commit is contained in:
Sashko Stubailo 2016-10-22 23:56:14 -07:00
parent cd298c5b48
commit 42613a448a
8 changed files with 28 additions and 28 deletions

View file

@ -1,2 +1,2 @@
export { runQuery, LogFunction, LogMessage, LogStep, LogAction } from './runQuery' export { runQuery, LogFunction, LogMessage, LogStep, LogAction } from './runQuery'
export { default as ApolloOptions} from './graphqlOptions' export { default as GraphQLOptions} from './graphqlOptions'

View file

@ -3,7 +3,7 @@ import * as bodyParser from 'body-parser';
import { graphqlExpress, graphiqlExpress } from './expressApollo'; import { graphqlExpress, graphiqlExpress } from './expressApollo';
import testSuite, { Schema, CreateAppOptions } from 'graphql-server-integration-testsuite'; import testSuite, { Schema, CreateAppOptions } from 'graphql-server-integration-testsuite';
import { expect } from 'chai'; import { expect } from 'chai';
import { ApolloOptions } from 'graphql-server-core'; import { GraphQLOptions } from 'graphql-server-core';
import 'mocha'; import 'mocha';
function createApp(options: CreateAppOptions = {}) { function createApp(options: CreateAppOptions = {}) {
@ -22,7 +22,7 @@ function createApp(options: CreateAppOptions = {}) {
describe('expressApollo', () => { describe('expressApollo', () => {
it('throws error if called without schema', function(){ it('throws error if called without schema', function(){
expect(() => graphqlExpress(undefined as ApolloOptions)).to.throw('Apollo Server requires options.'); expect(() => graphqlExpress(undefined as GraphQLOptions)).to.throw('Apollo Server requires options.');
}); });
it('throws an error if called with more than one argument', function(){ it('throws an error if called with more than one argument', function(){

View file

@ -1,11 +1,11 @@
import * as express from 'express'; import * as express from 'express';
import * as graphql from 'graphql'; import * as graphql from 'graphql';
import * as url from 'url'; import * as url from 'url';
import { ApolloOptions, runQuery } from 'graphql-server-core'; import { GraphQLOptions, runQuery } from 'graphql-server-core';
import * as GraphiQL from 'graphql-server-module-graphiql'; import * as GraphiQL from 'graphql-server-module-graphiql';
export interface ExpressApolloOptionsFunction { export interface ExpressGraphQLOptionsFunction {
(req?: express.Request, res?: express.Response): ApolloOptions | Promise<ApolloOptions>; (req?: express.Request, res?: express.Response): GraphQLOptions | Promise<GraphQLOptions>;
} }
// Design principles: // Design principles:
@ -17,7 +17,7 @@ export interface ExpressHandler {
(req: express.Request, res: express.Response, next): void; (req: express.Request, res: express.Response, next): void;
} }
export function graphqlExpress(options: ApolloOptions | ExpressApolloOptionsFunction): ExpressHandler { export function graphqlExpress(options: GraphQLOptions | ExpressGraphQLOptionsFunction): ExpressHandler {
if (!options) { if (!options) {
throw new Error('Apollo Server requires options.'); throw new Error('Apollo Server requires options.');
} }
@ -28,7 +28,7 @@ export function graphqlExpress(options: ApolloOptions | ExpressApolloOptionsFunc
} }
return async (req: express.Request, res: express.Response, next) => { return async (req: express.Request, res: express.Response, next) => {
let optionsObject: ApolloOptions; let optionsObject: GraphQLOptions;
if (isOptionsFunction(options)) { if (isOptionsFunction(options)) {
try { try {
optionsObject = await options(req, res); optionsObject = await options(req, res);
@ -133,7 +133,7 @@ export function graphqlExpress(options: ApolloOptions | ExpressApolloOptionsFunc
}; };
} }
function isOptionsFunction(arg: ApolloOptions | ExpressApolloOptionsFunction): arg is ExpressApolloOptionsFunction { function isOptionsFunction(arg: GraphQLOptions | ExpressGraphQLOptionsFunction): arg is ExpressGraphQLOptionsFunction {
return typeof arg === 'function'; return typeof arg === 'function';
} }

View file

@ -1,5 +1,5 @@
export { export {
ExpressApolloOptionsFunction, ExpressGraphQLOptionsFunction,
ExpressHandler, ExpressHandler,
graphqlExpress, graphqlExpress,
graphiqlExpress, graphiqlExpress,

View file

@ -2,7 +2,7 @@ import * as Boom from 'boom';
import { Server, Request, IReply } from 'hapi'; import { Server, Request, IReply } from 'hapi';
import { GraphQLResult, formatError } from 'graphql'; import { GraphQLResult, formatError } from 'graphql';
import * as GraphiQL from 'graphql-server-module-graphiql'; import * as GraphiQL from 'graphql-server-module-graphiql';
import { ApolloOptions, runQuery } from 'graphql-server-core'; import { GraphQLOptions, runQuery } from 'graphql-server-core';
export interface IRegister { export interface IRegister {
(server: Server, options: any, next: any): void; (server: Server, options: any, next: any): void;
@ -10,13 +10,13 @@ export interface IRegister {
} }
export interface HapiOptionsFunction { export interface HapiOptionsFunction {
(req?: Request): ApolloOptions | Promise<ApolloOptions>; (req?: Request): GraphQLOptions | Promise<GraphQLOptions>;
} }
export interface HapiPluginOptions { export interface HapiPluginOptions {
path: string; path: string;
route?: any; route?: any;
graphqlOptions: ApolloOptions | HapiOptionsFunction; graphqlOptions: GraphQLOptions | HapiOptionsFunction;
} }
const graphqlHapi: IRegister = function(server: Server, options: HapiPluginOptions, next) { const graphqlHapi: IRegister = function(server: Server, options: HapiPluginOptions, next) {
@ -108,7 +108,7 @@ function getGraphQLParams(payload, isBatch, reply) {
async function getGraphQLOptions(request: Request, reply: IReply): Promise<{}> { async function getGraphQLOptions(request: Request, reply: IReply): Promise<{}> {
const options = request.route.settings.plugins['graphql']; const options = request.route.settings.plugins['graphql'];
let optionsObject: ApolloOptions; let optionsObject: GraphQLOptions;
if (isOptionsFunction(options)) { if (isOptionsFunction(options)) {
try { try {
const opsFunc: HapiOptionsFunction = <HapiOptionsFunction>options; const opsFunc: HapiOptionsFunction = <HapiOptionsFunction>options;
@ -117,12 +117,12 @@ async function getGraphQLOptions(request: Request, reply: IReply): Promise<{}> {
return reply(createErr(500, `Invalid options provided to ApolloServer: ${e.message}`)); return reply(createErr(500, `Invalid options provided to ApolloServer: ${e.message}`));
} }
} else { } else {
optionsObject = <ApolloOptions>options; optionsObject = <GraphQLOptions>options;
} }
reply(optionsObject); reply(optionsObject);
} }
async function processQuery(graphqlParams, optionsObject: ApolloOptions, isBatch: boolean, reply) { async function processQuery(graphqlParams, optionsObject: GraphQLOptions, isBatch: boolean, reply) {
const formatErrorFn = optionsObject.formatError || formatError; const formatErrorFn = optionsObject.formatError || formatError;
let responses: GraphQLResult[] = []; let responses: GraphQLResult[] = [];
@ -162,7 +162,7 @@ async function processQuery(graphqlParams, optionsObject: ApolloOptions, isBatch
return reply(responses); return reply(responses);
} }
function isOptionsFunction(arg: ApolloOptions | HapiOptionsFunction): arg is HapiOptionsFunction { function isOptionsFunction(arg: GraphQLOptions | HapiOptionsFunction): arg is HapiOptionsFunction {
return typeof arg === 'function'; return typeof arg === 'function';
} }

View file

@ -14,7 +14,7 @@ import {
// tslint:disable-next-line // tslint:disable-next-line
const request = require('supertest-as-promised'); const request = require('supertest-as-promised');
import { ApolloOptions } from 'graphql-server-core'; import { GraphQLOptions } from 'graphql-server-core';
import * as GraphiQL from 'graphql-server-module-graphiql'; import * as GraphiQL from 'graphql-server-module-graphiql';
import { OperationStore } from 'graphql-server-module-operation-store'; import { OperationStore } from 'graphql-server-module-operation-store';
@ -79,7 +79,7 @@ export const Schema = new GraphQLSchema({
export interface CreateAppOptions { export interface CreateAppOptions {
excludeParser?: boolean; excludeParser?: boolean;
graphqlOptions?: ApolloOptions | {(): ApolloOptions | Promise<{}>}; graphqlOptions?: GraphQLOptions | {(): GraphQLOptions | Promise<{}>};
graphiqlOptions?: GraphiQL.GraphiQLData; graphiqlOptions?: GraphiQL.GraphiQLData;
} }
@ -107,7 +107,7 @@ export default (createApp: CreateAppFunc, destroyApp?: DestroyAppFunc) => {
describe('graphqlHTTP', () => { describe('graphqlHTTP', () => {
it('can be called with an options function', () => { it('can be called with an options function', () => {
app = createApp({graphqlOptions: (): ApolloOptions => ({schema: Schema})}); app = createApp({graphqlOptions: (): GraphQLOptions => ({schema: Schema})});
const expected = { const expected = {
testString: 'it works', testString: 'it works',
}; };
@ -144,7 +144,7 @@ export default (createApp: CreateAppFunc, destroyApp?: DestroyAppFunc) => {
it('throws an error if options promise is rejected', () => { it('throws an error if options promise is rejected', () => {
app = createApp({ graphqlOptions: () => { app = createApp({ graphqlOptions: () => {
return Promise.reject({}) as any as ApolloOptions; return Promise.reject({}) as any as GraphQLOptions;
}}); }});
const expected = 'Invalid options'; const expected = 'Invalid options';
const req = request(app) const req = request(app)

View file

@ -2,7 +2,7 @@ import * as koa from 'koa';
import * as koaRouter from 'koa-router'; import * as koaRouter from 'koa-router';
import * as koaBody from 'koa-bodyparser'; import * as koaBody from 'koa-bodyparser';
import { graphqlKoa, graphiqlKoa } from './koaApollo'; import { graphqlKoa, graphiqlKoa } from './koaApollo';
import { ApolloOptions } from 'graphql-server-core'; import { GraphQLOptions } from 'graphql-server-core';
import { expect } from 'chai'; import { expect } from 'chai';
import * as http from 'http'; import * as http from 'http';
@ -32,7 +32,7 @@ function destroyApp(app) {
describe('koaApollo', () => { describe('koaApollo', () => {
it('throws error if called without schema', function(){ it('throws error if called without schema', function(){
expect(() => graphqlKoa(undefined as ApolloOptions)).to.throw('Apollo Server requires options.'); expect(() => graphqlKoa(undefined as GraphQLOptions)).to.throw('Apollo Server requires options.');
}); });
it('throws an error if called with more than one argument', function(){ it('throws an error if called with more than one argument', function(){

View file

@ -1,17 +1,17 @@
import * as koa from 'koa'; import * as koa from 'koa';
import * as graphql from 'graphql'; import * as graphql from 'graphql';
import { ApolloOptions, runQuery } from 'graphql-server-core'; import { GraphQLOptions, runQuery } from 'graphql-server-core';
import * as GraphiQL from 'graphql-server-module-graphiql'; import * as GraphiQL from 'graphql-server-module-graphiql';
export interface KoaGraphQLOptionsFunction { export interface KoaGraphQLOptionsFunction {
(ctx: koa.Context): ApolloOptions | Promise<ApolloOptions>; (ctx: koa.Context): GraphQLOptions | Promise<GraphQLOptions>;
} }
export interface KoaHandler { export interface KoaHandler {
(req: any, next): void; (req: any, next): void;
} }
export function graphqlKoa(options: ApolloOptions | KoaGraphQLOptionsFunction): KoaHandler { export function graphqlKoa(options: GraphQLOptions | KoaGraphQLOptionsFunction): KoaHandler {
if (!options) { if (!options) {
throw new Error('Apollo Server requires options.'); throw new Error('Apollo Server requires options.');
} }
@ -21,7 +21,7 @@ export function graphqlKoa(options: ApolloOptions | KoaGraphQLOptionsFunction):
} }
return async (ctx, next) => { return async (ctx, next) => {
let optionsObject: ApolloOptions; let optionsObject: GraphQLOptions;
if (isOptionsFunction(options)) { if (isOptionsFunction(options)) {
try { try {
optionsObject = await options(ctx); optionsObject = await options(ctx);
@ -109,7 +109,7 @@ export function graphqlKoa(options: ApolloOptions | KoaGraphQLOptionsFunction):
}; };
} }
function isOptionsFunction(arg: ApolloOptions | KoaGraphQLOptionsFunction): arg is KoaGraphQLOptionsFunction { function isOptionsFunction(arg: GraphQLOptions | KoaGraphQLOptionsFunction): arg is KoaGraphQLOptionsFunction {
return typeof arg === 'function'; return typeof arg === 'function';
} }