Skip to content

Commit

Permalink
feat: expose error creation functions (#89)
Browse files Browse the repository at this point in the history
* feat: expose error formatting and creation functions.

* fix: use proper type for `RelayResponse#errors` in Flow definition.
  • Loading branch information
nirvdrum committed Feb 4, 2020
1 parent 68cf9be commit ab32fe6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/RelayResponse.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/* @flow */

import type { PayloadData, FetchResponse } from './definition';
import type { FetchResponse, GraphQLResponseErrors, PayloadData } from './definition';

export default class RelayResponse {
_res: any; // response from low-level method, eg. fetch

data: ?PayloadData;
errors: ?Array<any>;
errors: ?GraphQLResponseErrors;

ok: any;
status: number;
Expand Down
13 changes: 11 additions & 2 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ declare class RelayResponse {
_res: any;

data?: PayloadData;
errors?: any[];
errors?: GraphQLResponseErrors;

ok: any;
status: number;
Expand Down Expand Up @@ -146,7 +146,7 @@ export type BatchMiddlewareOpts = {
allowMutations?: boolean;
method?: 'POST' | 'GET';
headers?: Headers | Promise<Headers> | ((req: RelayRequestBatch) => Headers | Promise<Headers>);
// Avaliable request modes in fetch options. For details see https://fetch.spec.whatwg.org/#requests
// Available request modes in fetch options. For details see https://fetch.spec.whatwg.org/#requests
credentials?: FetchOpts['credentials'];
mode?: FetchOpts['mode'];
cache?: FetchOpts['cache'];
Expand Down Expand Up @@ -296,3 +296,12 @@ export class RelayNetworkLayer {

execute: ExecuteFunction;
}

export type GraphQLResponseErrors = Array<{
message: string;
locations?: [{ column: number; line: number }];
stack?: string[];
}>;

export function createRequestError(request: RelayRequestAny, response?: RelayResponse);
export function formatGraphQLErrors(request: RelayRequest, errors: GraphQLResponseErrors);
4 changes: 3 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import graphqlBatchHTTPWrapper from './express-middleware/graphqlBatchHTTPWrappe
import RelayNetworkLayerRequest from './RelayRequest';
import RelayNetworkLayerRequestBatch from './RelayRequestBatch';
import RelayNetworkLayerResponse from './RelayResponse';
import { RRNLRequestError } from './createRequestError';
import { createRequestError, formatGraphQLErrors, RRNLRequestError } from './createRequestError';
import RRNLError from './RRNLError';

export {
Expand All @@ -36,6 +36,8 @@ export {
progressMiddleware,
uploadMiddleware,
graphqlBatchHTTPWrapper,
createRequestError,
formatGraphQLErrors,
RRNLError,
RRNLRequestError,
RRNLRetryMiddlewareError,
Expand Down

0 comments on commit ab32fe6

Please sign in to comment.