Comments (4)
urlMiddleware
determines which type of query single or batched via req.relayReqType === 'batch-query'
and passes to next middleware just url
for fetching (supposing that all other middlewares do not care about url).
So if you want to create more complex logic, do not use urlMiddleware
and write your own inline middleware (find example with next => req => {...}
in readme.md).
from react-relay-network-layer.
I agree with that but I am not sure we are talkin gabout the same thing.
I see this example in the documentation:
urlMiddleware({
url: (req) => '/graphql',
}),
and thus would expect this code to work:
urlMiddleware({
url: (req) => req.someProperty + '/graphql',
batchUrl: (req) => req.someProperty + '/graphql/batch',
}),
but it seems that batchUrl does not accept a function.
from react-relay-network-layer.
export default function urlMiddleware(opts = {}) {
const urlOrThunk = opts.url || '/graphql';
const batchUrlOrThunk = opts.batchUrl || '/graphql/batch';
const fetchOpts = opts.opts;
return next => req => {
if (fetchOpts) {
const { headers, ...otherOpts } = fetchOpts;
Object.assign(req, otherOpts);
if (headers) {
Object.assign(req.headers, headers);
}
}
let url;
if (req.relayReqType === 'batch-query') {
url = batchUrlOrThunk;
} else {
url = urlOrThunk;
}
req.url = isFunction(url) ? url(req) : url;
return next(req);
};
}
See carefully that url
variable assigned to batchUrlOrThunk
(opts.batchUrl) or urlOrThunk
(opts.url) according to req.relayReqType
value. And after that checking is url
function or not.
So it should work as you expected.
from react-relay-network-layer.
Ok got it, my error should came from another part then. I am closing this now as the behavior is the one expected.
from react-relay-network-layer.
Related Issues (20)
- Throwing errors from middleware HOT 5
- Support max batch size HOT 2
- authMiddleware stop working as of 2.0.0! HOT 2
- __dataID__ unknown field HOT 2
- Rendering partial response with error messages HOT 1
- error: Processing of node_modules/react-relay-network-layer/lib/middleware/gqErrors.js failed. SyntaxError: Unexpected token (80:376) HOT 3
- Syntax Error GraphQL request (1:1) Unexpected EOF HOT 1
- Chinese Characters Issue HOT 3
- When will subscriptions be supported? HOT 2
- How to pass data from express req object to the req received by middleware HOT 3
- Relay Modern equivalent? HOT 6
- Redirect to login page and network layer HOT 1
- Token not refreshing after user logs out and login again with different user. HOT 4
- regeneratorRuntime not defined in lib/fetchWithMiddleware.js HOT 2
- Batching: make query id optional HOT 1
- Cannot access response header from middleware HOT 1
- Retry middleware not retrying HOT 8
- One of the sources for assign has an enumerable key on the prototype chain HOT 4
- Flowtype failing on my repo
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-relay-network-layer.