Skip to content

Commit 599207b

Browse files
author
Alex Cory
committed
adding docs for scalable interceptor args
1 parent 84dd39a commit 599207b

File tree

2 files changed

+8
-14
lines changed

2 files changed

+8
-14
lines changed

README.md

+4-10
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,7 @@ function App() {
645645
// every time we make an http request, this will run 1st before the request is made
646646
// url, path and route are supplied to the interceptor
647647
// request options can be modified and must be returned
648-
request: async (options, url, path, route) => {
648+
request: async ({ options, url, path, route }) => {
649649
if (isExpired(token)) {
650650
token = await getNewToken()
651651
setToken(token)
@@ -654,7 +654,7 @@ function App() {
654654
return options
655655
},
656656
// every time we make an http request, before getting the response back, this will run
657-
response: async (response) => {
657+
response: async ({ response }) => {
658658
// unfortunately, because this is a JS Response object, we have to modify it directly.
659659
// It shouldn't have any negative affect since this is getting reset on each request.
660660
const res = response
@@ -879,10 +879,10 @@ const options = {
879879

880880
// typically, `interceptors` would be added as an option to the `<Provider />`
881881
interceptors: {
882-
request: async (options, url, path, route) => { // `async` is not required
882+
request: async ({ options, url, path, route }) => { // `async` is not required
883883
return options // returning the `options` is important
884884
},
885-
response: async (response) => {
885+
response: async ({ response }) => {
886886
// note: `response.data` is equivalent to `await response.json()`
887887
return response // returning the `response` is important
888888
}
@@ -1057,12 +1057,6 @@ Todos
10571057
// I don't really like this solution though.
10581058
// Another solution is to only allow the `cache` option with the `<Provider cache={new Map()} />`
10591059
cache: new Map(),
1060-
interceptors: {
1061-
// I think it's more scalable/clean to have this as an object.
1062-
// What if we only need the `route` and `options`?
1063-
request: async ({ options, url, path, route }) => {},
1064-
response: async ({ response }) => {}
1065-
},
10661060
// these will be the exact same ones as Apollo's
10671061
cachePolicy: 'cache-and-network', 'network-only', 'cache-only', 'no-cache' // 'cache-first'
10681062
// potential idea to fetch on server instead of just having `loading` state. Not sure if this is a good idea though

docs/README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ function App() {
462462
// every time we make an http request, this will run 1st before the request is made
463463
// url, path and route are supplied to the interceptor
464464
// request options can be modified and must be returned
465-
request: async (options, url, path, route) => {
465+
request: async ({ options, url, path, route }) => {
466466
if (isExpired(token)) {
467467
token = await getNewToken()
468468
setToken(token)
@@ -471,7 +471,7 @@ function App() {
471471
return options
472472
},
473473
// every time we make an http request, before getting the response back, this will run
474-
response: async (response) => {
474+
response: async ({ response }) => {
475475
const res = response
476476
if (res.data) res.data = toCamel(res.data)
477477
return res
@@ -830,10 +830,10 @@ const options = {
830830

831831
// typically, `interceptors` would be added as an option to the `<Provider />`
832832
interceptors: {
833-
request: async (options, url, path, route) => { // `async` is not required
833+
request: async ({ options, url, path, route }) => { // `async` is not required
834834
return options // returning the `options` is important
835835
},
836-
response: async (response) => {
836+
response: async ({ response }) => {
837837
// note: `response.data` is equivalent to `await response.json()`
838838
return response // returning the `response` is important
839839
}

0 commit comments

Comments
 (0)