From 8988aee224efd4df06a9a70b543e6938a68f4302 Mon Sep 17 00:00:00 2001 From: Firede Date: Wed, 28 Mar 2018 14:39:26 +0800 Subject: [PATCH 1/3] Reformat all files using prettier. prettier --parser typescript --tab-width 4 --semi --trailing-comma es5 \ --write --print-width 120 \ types/express-graphql/*.ts related: #24552 --- .../express-graphql/express-graphql-tests.ts | 22 +++++++++---------- types/express-graphql/index.d.ts | 8 +++---- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/types/express-graphql/express-graphql-tests.ts b/types/express-graphql/express-graphql-tests.ts index 1557c4c0ac..958be4f5ff 100644 --- a/types/express-graphql/express-graphql-tests.ts +++ b/types/express-graphql/express-graphql-tests.ts @@ -1,7 +1,7 @@ -import express = require('express'); -import 'express-session'; -import graphqlHTTP = require('express-graphql'); -import { GraphQLSchema } from 'graphql/type/schema'; +import express = require("express"); +import "express-session"; +import graphqlHTTP = require("express-graphql"); +import { GraphQLSchema } from "graphql/type/schema"; const app = express(); const schema: GraphQLSchema = { @@ -20,10 +20,10 @@ const graphqlOption: graphqlHTTP.OptionsData = { graphiql: true, schema, formatError: (error: Error) => ({ - message: error.message + message: error.message, }), validationRules: [() => false, () => true], - extensions: ({ document, variables, operationName, result }) => ({ key: "value", key2: "value"}), + extensions: ({ document, variables, operationName, result }) => ({ key: "value", key2: "value" }), }; const graphqlOptionRequest = (request: express.Request): graphqlHTTP.OptionsData => ({ @@ -38,15 +38,15 @@ const graphqlOptionRequestAsync = async (request: express.Request): Promise { }, + extensions: async args => {}, validationRules: [() => false, () => true], }; }; -app.use('/graphql1', graphqlHTTP(graphqlOption)); +app.use("/graphql1", graphqlHTTP(graphqlOption)); -app.use('/graphql2', graphqlHTTP(graphqlOptionRequest)); +app.use("/graphql2", graphqlHTTP(graphqlOptionRequest)); -app.use('/graphqlasync', graphqlHTTP(graphqlOptionRequestAsync)); +app.use("/graphqlasync", graphqlHTTP(graphqlOptionRequestAsync)); -app.listen(8080, () => console.log('GraphQL Server running on localhost:8080')); +app.listen(8080, () => console.log("GraphQL Server running on localhost:8080")); diff --git a/types/express-graphql/index.d.ts b/types/express-graphql/index.d.ts index 4b2d10c99b..b00259e158 100644 --- a/types/express-graphql/index.d.ts +++ b/types/express-graphql/index.d.ts @@ -9,7 +9,7 @@ // TypeScript Version: 2.3 import { Request, Response } from "express"; -import { DocumentNode, GraphQLSchema, GraphQLError } from 'graphql'; +import { DocumentNode, GraphQLSchema, GraphQLError } from "graphql"; export = graphqlHTTP; declare namespace graphqlHTTP { @@ -17,9 +17,9 @@ declare namespace graphqlHTTP { * Used to configure the graphQLHTTP middleware by providing a schema * and other configuration options. */ - export type Options = ((request: Request, - response: Response, - params?: GraphQLParams) => OptionsResult) | OptionsResult; + export type Options = + | ((request: Request, response: Response, params?: GraphQLParams) => OptionsResult) + | OptionsResult; export type OptionsResult = OptionsData | Promise; export interface OptionsData { /** From 73c777a74a44cb85e5be44e19d0afde8a94c44d8 Mon Sep 17 00:00:00 2001 From: Firede Date: Wed, 28 Mar 2018 14:49:05 +0800 Subject: [PATCH 2/3] Fixed the definition of some optional fields. `express-graphql` version: 0.6.12 --- types/express-graphql/index.d.ts | 34 ++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/types/express-graphql/index.d.ts b/types/express-graphql/index.d.ts index b00259e158..78c988204f 100644 --- a/types/express-graphql/index.d.ts +++ b/types/express-graphql/index.d.ts @@ -5,6 +5,7 @@ // Daniel Fader // Ehsan Ziya // Margus Lamp +// Firede // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.3 @@ -14,8 +15,11 @@ export = graphqlHTTP; declare namespace graphqlHTTP { /** - * Used to configure the graphQLHTTP middleware by providing a schema + * Used to configure the graphqlHTTP middleware by providing a schema * and other configuration options. + * + * Options can be provided as an Object, a Promise for an Object, or a Function + * that returns an Object or a Promise for an Object. */ export type Options = | ((request: Request, response: Response, params?: GraphQLParams) => OptionsResult) @@ -40,20 +44,20 @@ declare namespace graphqlHTTP { /** * A boolean to configure whether the output should be pretty-printed. */ - pretty?: boolean; + pretty?: boolean | null; /** * An optional function which will be used to format any errors produced by * fulfilling a GraphQL operation. If no function is provided, GraphQL's * default spec-compliant `formatError` function will be used. */ - formatError?: (error: GraphQLError) => any; + formatError?: ((error: GraphQLError) => any) | null; /** * An optional array of validation rules that will be applied on the document * in additional to those defined by the GraphQL spec. */ - validationRules?: any[]; + validationRules?: any[] | null; /** * An optional function for adding additional metadata to the GraphQL response @@ -65,12 +69,12 @@ declare namespace graphqlHTTP { * * This function may be async. */ - extensions?: (info: RequestInfo) => { [key: string]: any }; + extensions?: ((info: RequestInfo) => { [key: string]: any }) | null; /** * A boolean to optionally enable GraphiQL mode. */ - graphiql?: boolean; + graphiql?: boolean | null; } /** @@ -80,32 +84,32 @@ declare namespace graphqlHTTP { /** * The parsed GraphQL document. */ - document?: DocumentNode; + document: DocumentNode | null | undefined; /** * The variable values used at runtime. */ - variables?: { [name: string]: any }; + variables: { [name: string]: any } | null | undefined; /** * The (optional) operation name requested. */ - operationName?: string; + operationName: string | null | undefined; /** * The result of executing the operation. */ - result?: any; + result: any; } export interface GraphQLParams { - query?: string; - variables?: { [name: string]: any }; - operationName?: string; - raw?: boolean; + query: string | null | undefined; + variables: { [name: string]: any } | null | undefined; + operationName: string | null | undefined; + raw: boolean | null | undefined; } - type Middleware = (request: Request, response: Response) => void; + type Middleware = (request: Request, response: Response) => Promise; } /** From ac6eb13e40e93553c1d9743924a5aa408d548cf0 Mon Sep 17 00:00:00 2001 From: Firede Date: Wed, 28 Mar 2018 15:25:04 +0800 Subject: [PATCH 3/3] Defining `schema` the right way. Otherwise, it will cause the new version `@types/graphql` test to fail. Related: #24566 --- types/express-graphql/express-graphql-tests.ts | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/types/express-graphql/express-graphql-tests.ts b/types/express-graphql/express-graphql-tests.ts index 958be4f5ff..52071cea07 100644 --- a/types/express-graphql/express-graphql-tests.ts +++ b/types/express-graphql/express-graphql-tests.ts @@ -1,20 +1,10 @@ import express = require("express"); import "express-session"; import graphqlHTTP = require("express-graphql"); -import { GraphQLSchema } from "graphql/type/schema"; +import { buildSchema } from "graphql"; const app = express(); -const schema: GraphQLSchema = { - getQueryType: null, - getMutationType: null, - getSubscriptionType: null, - getTypeMap: null, - getType: null, - getPossibleTypes: null, - isPossibleType: null, - getDirective: null, - getDirectives: null, -}; +const schema = buildSchema(`type Query { hello: String }`); const graphqlOption: graphqlHTTP.OptionsData = { graphiql: true,