Skip to content
This repository has been archived by the owner on Mar 20, 2023. It is now read-only.

Enable more Flow lint checks #568

Merged
merged 1 commit into from Nov 14, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions .flowconfig
Expand Up @@ -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
Expand Down
36 changes: 22 additions & 14 deletions src/__tests__/http-test.js
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
},
},
}),
Expand Down Expand Up @@ -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;
Expand All @@ -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',
},
};
},
})),
);
Expand Down Expand Up @@ -2156,7 +2161,7 @@ function urlString(urlParams?: ?{ [param: string]: mixed, ... }) {
schema: TestSchema,
customFormatErrorFn: () => null,
extensions({ result }) {
return { preservedErrors: (result: any).errors };
return { preservedResult: { ...result } };
},
}),
);
Expand All @@ -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'],
},
],
},
},
});
});
Expand Down
6 changes: 3 additions & 3 deletions src/index.js
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/parseBody.js
Expand Up @@ -37,7 +37,7 @@ export async function parseBody(
}

// Already parsed body we didn't recognise? Parse nothing.
if (body) {
if (body != null) {
return {};
}

Expand Down
14 changes: 7 additions & 7 deletions src/renderGraphiQL.js
Expand Up @@ -19,7 +19,9 @@ export type GraphiQLOptions = {|

// Ensures string values are safe to be used within a <script> tag.
function safeSerialize(data) {
return data ? JSON.stringify(data).replace(/\//g, '\\/') : 'undefined';
return data != null
? JSON.stringify(data).replace(/\//g, '\\/')
: 'undefined';
}

// Implemented as Babel transformation, see ../resources/load-staticly-from-npm.js
Expand All @@ -34,12 +36,10 @@ declare function loadFileStaticlyFromNPM(npmPath: string): string;
*/
export function renderGraphiQL(data: GraphiQLData): string {
const queryString = data.query;
const variablesString = data.variables
? JSON.stringify(data.variables, null, 2)
: null;
const resultString = data.result
? JSON.stringify(data.result, null, 2)
: null;
const variablesString =
data.variables != null ? JSON.stringify(data.variables, null, 2) : null;
const resultString =
data.result != null ? JSON.stringify(data.result, null, 2) : null;
const operationName = data.operationName;
const defaultQuery = data.options.defaultQuery;

Expand Down