From 5a5c3f54dd8a9a49bc3b2c31669dfc6557ea9689 Mon Sep 17 00:00:00 2001 From: nodkz Date: Sat, 3 Mar 2018 14:06:55 +0600 Subject: [PATCH] refactor: rename `gqlErrorsMiddleware` to `errorMiddleware` BREAKING CHANGE: rename `gqlErrorsMiddleware` to `errorMiddleware` --- README.md | 6 +++--- src/index.js | 4 ++-- .../{gqlErrors-test.js.snap => error-test.js.snap} | 2 +- .../__tests__/{gqlErrors-test.js => error-test.js} | 6 +++--- src/middlewares/{gqlErrors.js => error.js} | 2 +- 5 files changed, 10 insertions(+), 10 deletions(-) rename src/middlewares/__tests__/__snapshots__/{gqlErrors-test.js.snap => error-test.js.snap} (94%) rename src/middlewares/__tests__/{gqlErrors-test.js => error-test.js} (94%) rename src/middlewares/{gqlErrors.js => error.js} (96%) diff --git a/README.md b/README.md index c413359..25d3838 100644 --- a/README.md +++ b/README.md @@ -97,7 +97,7 @@ Middlewares - An example of req/res output in console: screen shot 2017-11-19 at 23 05 19 - **perfMiddleware** - simple time measure for network request. - `logger` - log function (default: `console.log.bind(console, '[RELAY-NETWORK]')`) -- **gqlErrorsMiddleware** - display `errors` data to console from graphql response. If you want see stackTrace for errors, you should provide `formatError` to `express-graphql` (see example below where `graphqlServer` accept `formatError` function). +- **errorMiddleware** - display `errors` data to console from graphql response. If you want see stackTrace for errors, you should provide `formatError` to `express-graphql` (see example below where `graphqlServer` accept `formatError` function). - `logger` - log function (default: `console.error.bind(console)`) - `prefix` - prefix message (default: `[RELAY-NETWORK] GRAPHQL SERVER ERROR:`) @@ -109,7 +109,7 @@ import { urlMiddleware, batchMiddleware, loggerMiddleware, - gqlErrorsMiddleware, + errorMiddleware, perfMiddleware, retryMiddleware, authMiddleware, @@ -129,7 +129,7 @@ const network = new RelayNetworkLayer([ batchTimeout: 10, }), __DEV__ ? loggerMiddleware() : null, - __DEV__ ? gqlErrorsMiddleware() : null, + __DEV__ ? errorMiddleware() : null, __DEV__ ? perfMiddleware() : null, retryMiddleware({ fetchTimeout: 15000, diff --git a/src/index.js b/src/index.js index cb8f4b5..7153460 100644 --- a/src/index.js +++ b/src/index.js @@ -7,7 +7,7 @@ import urlMiddleware from './middlewares/url'; import authMiddleware from './middlewares/auth'; import perfMiddleware from './middlewares/perf'; import loggerMiddleware from './middlewares/logger'; -import gqlErrorsMiddleware from './middlewares/gqlErrors'; +import errorMiddleware from './middlewares/error'; import cacheMiddleware from './middlewares/cache'; import graphqlBatchHTTPWrapper from './express-middleware/graphqlBatchHTTPWrapper'; import RelayNetworkLayerRequest from './RelayRequest'; @@ -25,7 +25,7 @@ export { authMiddleware, perfMiddleware, loggerMiddleware, - gqlErrorsMiddleware, + errorMiddleware, cacheMiddleware, graphqlBatchHTTPWrapper, }; diff --git a/src/middlewares/__tests__/__snapshots__/gqlErrors-test.js.snap b/src/middlewares/__tests__/__snapshots__/error-test.js.snap similarity index 94% rename from src/middlewares/__tests__/__snapshots__/gqlErrors-test.js.snap rename to src/middlewares/__tests__/__snapshots__/error-test.js.snap index f575cc5..6e46f39 100644 --- a/src/middlewares/__tests__/__snapshots__/gqlErrors-test.js.snap +++ b/src/middlewares/__tests__/__snapshots__/error-test.js.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`middlewares/gqlErrors should display graphql errors 1`] = ` +exports[`middlewares/error should display graphql errors 1`] = ` "[RELAY-NETWORK] GRAPHQL SERVER ERROR: %cError: Wow! diff --git a/src/middlewares/__tests__/gqlErrors-test.js b/src/middlewares/__tests__/error-test.js similarity index 94% rename from src/middlewares/__tests__/gqlErrors-test.js rename to src/middlewares/__tests__/error-test.js index cef4042..b14f6e9 100644 --- a/src/middlewares/__tests__/gqlErrors-test.js +++ b/src/middlewares/__tests__/error-test.js @@ -3,9 +3,9 @@ import fetchMock from 'fetch-mock'; import RelayNetworkLayer from '../../RelayNetworkLayer'; import { mockReq } from '../../__mocks__/mockReq'; -import gqlErrorsMiddleware from '../gqlErrors'; +import errorMiddleware from '../error'; -describe('middlewares/gqlErrors', () => { +describe('middlewares/error', () => { beforeEach(() => { fetchMock.restore(); }); @@ -43,7 +43,7 @@ describe('middlewares/gqlErrors', () => { const logger = jest.fn(); const rnl = new RelayNetworkLayer([ - gqlErrorsMiddleware({ + errorMiddleware({ logger, }), ]); diff --git a/src/middlewares/gqlErrors.js b/src/middlewares/error.js similarity index 96% rename from src/middlewares/gqlErrors.js rename to src/middlewares/error.js index 484c50e..b4ffff5 100644 --- a/src/middlewares/gqlErrors.js +++ b/src/middlewares/error.js @@ -12,7 +12,7 @@ export type GqlErrorMiddlewareOpts = {| disableServerMiddlewareTip?: boolean, |}; -export default function gqlErrorsMiddleware(options?: GqlErrorMiddlewareOpts): Middleware { +export default function errorMiddleware(options?: GqlErrorMiddlewareOpts): Middleware { const opts = options || {}; const logger = opts.logger || console.error.bind(console); const prefix = opts.prefix || '[RELAY-NETWORK] GRAPHQL SERVER ERROR:\n\n';