Skip to content

Commit

Permalink
test: fix flowtype checks
Browse files Browse the repository at this point in the history
Related #61
  • Loading branch information
nodkz committed Sep 6, 2018
1 parent 4cb5776 commit 37593de
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .eslintignore
@@ -0,0 +1,3 @@
lib/
es/
coverage/
6 changes: 6 additions & 0 deletions src/definition.js
Expand Up @@ -2,6 +2,7 @@

import type { BatchRequestMap } from './middleware/batch';

export type FetchWithMiddleware = (req: RRNLRequestObject) => Promise<RRNLResponsePayload>;
export type MiddlewareNextFn = (req: RRNLRequestObject) => Promise<RRNLResponseObject>;
export type Middleware = (next: MiddlewareNextFn) => MiddlewareNextFn;
// {
Expand Down Expand Up @@ -53,6 +54,11 @@ export type GraphQLResponse = {
errors?: GraphQLResponseErrors,
};

export type RRNLResponsePayload = {|
+data: ?mixed,
+errors?: ?mixed,
|};

export type RRNLResponseObject = {
ok: any,
status: number,
Expand Down
3 changes: 2 additions & 1 deletion src/fetchWithMiddleware.js
Expand Up @@ -8,6 +8,7 @@ import type {
RRNLResponseObject,
MiddlewareNextFn,
RRNLOptions,
RRNLResponsePayload,
} from './definition';

function runFetch(req: RRNLRequestObject): Promise<RRNLResponseObject> {
Expand Down Expand Up @@ -43,7 +44,7 @@ export default function fetchWithMiddleware(
req: RRNLRequestObject,
middlewares: Middleware[],
options: RRNLOptions
): Promise<any> {
): Promise<RRNLResponsePayload> {
const wrappedFetch: MiddlewareNextFn = compose(...middlewares)(runFetch);

return wrappedFetch(req).then(res => {
Expand Down
4 changes: 2 additions & 2 deletions src/relayMutation.js
Expand Up @@ -4,12 +4,12 @@
import type {
RRNLRequestObjectMutation,
RelayClassicRequest,
MiddlewareNextFn,
FetchWithMiddleware,
} from './definition';

export default function mutation(
relayRequest: RelayClassicRequest,
fetchWithMiddleware: MiddlewareNextFn
fetchWithMiddleware: FetchWithMiddleware
): Promise<any> {
const commonReq: $Shape<RRNLRequestObjectMutation> = {
method: 'POST',
Expand Down
8 changes: 6 additions & 2 deletions src/relayQueries.js
@@ -1,11 +1,15 @@
/* @flow */
/* eslint-disable no-param-reassign, prefer-template */

import type { RelayClassicRequest, MiddlewareNextFn, RRNLRequestObjectQuery } from './definition';
import type {
RelayClassicRequest,
FetchWithMiddleware,
RRNLRequestObjectQuery,
} from './definition';

export default function queries(
relayRequestList: RelayClassicRequest[],
fetchWithMiddleware: MiddlewareNextFn
fetchWithMiddleware: FetchWithMiddleware
): Promise<any> {
return Promise.all(
relayRequestList.map(relayRequest => {
Expand Down

0 comments on commit 37593de

Please sign in to comment.