From 423772a4a164cb1608a8ce8bf41a11ead46b78c3 Mon Sep 17 00:00:00 2001 From: Ivan Goncharov Date: Wed, 13 Nov 2019 20:01:41 +0200 Subject: [PATCH] Enable more Flow lint checks --- .flowconfig | 4 ++-- src/__tests__/http-test.js | 36 ++++++++++++++++++++++-------------- src/index.js | 6 +++--- src/parseBody.js | 2 +- src/renderGraphiQL.js | 14 +++++++------- 5 files changed, 35 insertions(+), 27 deletions(-) diff --git a/.flowconfig b/.flowconfig index f24e90d1..60f8c1db 100644 --- a/.flowconfig +++ b/.flowconfig @@ -26,12 +26,12 @@ [lints] sketchy-null-bool=off -sketchy-null-string=off +sketchy-null-string=error sketchy-null-number=error sketchy-null-mixed=off sketchy-number=error untyped-type-import=error -nonstrict-import=off +nonstrict-import=error untyped-import=off unclear-type=off deprecated-type=error diff --git a/src/__tests__/http-test.js b/src/__tests__/http-test.js index fba002ef..b45bf14c 100644 --- a/src/__tests__/http-test.js +++ b/src/__tests__/http-test.js @@ -35,7 +35,7 @@ const QueryRootType = new GraphQLObjectType({ args: { who: { type: GraphQLString }, }, - resolve: (root, { who }) => 'Hello ' + ((who: any) || 'World'), + resolve: (root, args) => 'Hello ' + (args.who || 'World'), }, thrower: { type: GraphQLString, @@ -411,7 +411,7 @@ function urlString(urlParams?: ?{ [param: string]: mixed, ... }) { fields: { test: { type: GraphQLString, - resolve: (obj, args, context) => (context: any).foo, + resolve: (obj, args, context) => context.foo, }, }, }), @@ -2023,7 +2023,7 @@ function urlString(urlParams?: ?{ [param: string]: mixed, ... }) { }); describe('Custom execute', () => { - it('allow to replace default execute.', async () => { + it('allow to replace default execute', async () => { const app = server(); let seenExecuteArgs; @@ -2035,9 +2035,14 @@ function urlString(urlParams?: ?{ [param: string]: mixed, ... }) { schema: TestSchema, async customExecuteFn(args) { seenExecuteArgs = args; - const result: any = await Promise.resolve(execute(args)); - result.data.test2 = 'Modification'; - return result; + const result = await Promise.resolve(execute(args)); + return { + ...result, + data: { + ...result.data, + test2: 'Modification', + }, + }; }, })), ); @@ -2156,7 +2161,7 @@ function urlString(urlParams?: ?{ [param: string]: mixed, ... }) { schema: TestSchema, customFormatErrorFn: () => null, extensions({ result }) { - return { preservedErrors: (result: any).errors }; + return { preservedResult: { ...result } }; }, }), ); @@ -2172,13 +2177,16 @@ function urlString(urlParams?: ?{ [param: string]: mixed, ... }) { data: { thrower: null }, errors: [null], extensions: { - preservedErrors: [ - { - message: 'Throws!', - locations: [{ line: 1, column: 2 }], - path: ['thrower'], - }, - ], + preservedResult: { + data: { thrower: null }, + errors: [ + { + message: 'Throws!', + locations: [{ line: 1, column: 2 }], + path: ['thrower'], + }, + ], + }, }, }); }); diff --git a/src/index.js b/src/index.js index ea62c7db..72f98371 100644 --- a/src/index.js +++ b/src/index.js @@ -164,7 +164,7 @@ export type RequestInfo = {| /** * The result of executing the operation. */ - result: ?mixed, + result: ?ExecutionResult, /** * A value to pass as the context to the graphql() function. @@ -254,7 +254,7 @@ function graphqlHTTP(options: Options): Middleware { // If there is no query, but GraphiQL will be displayed, do not produce // a result, otherwise return a 400: Bad Request. - if (!query) { + if (query == null) { if (showGraphiQL) { return null; } @@ -469,7 +469,7 @@ function parseGraphQLParams( // Parse the variables if needed. let variables = urlData.variables || bodyData.variables; - if (variables && typeof variables === 'string') { + if (typeof variables === 'string') { try { variables = JSON.parse(variables); } catch (error) { diff --git a/src/parseBody.js b/src/parseBody.js index 537239ed..e83c1644 100644 --- a/src/parseBody.js +++ b/src/parseBody.js @@ -37,7 +37,7 @@ export async function parseBody( } // Already parsed body we didn't recognise? Parse nothing. - if (body) { + if (body != null) { return {}; } diff --git a/src/renderGraphiQL.js b/src/renderGraphiQL.js index 9d58f51d..9454c97d 100644 --- a/src/renderGraphiQL.js +++ b/src/renderGraphiQL.js @@ -19,7 +19,9 @@ export type GraphiQLOptions = {| // Ensures string values are safe to be used within a