You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The source code of microGraphql in apollo-server-micro is as follow:
export function microGraphql(options: GraphQLOptions | MicroGraphQLOptionsFunction): RequestHandler {
if (!options) {
throw new Error('Apollo Server requires options.');
}
if (arguments.length > 1) {
throw new Error(`Apollo Server expects exactly one argument, got ${arguments.length}`);
}
return async function (req: IncomingMessage, res: ServerResponse) {
let query;
if (req.method === 'POST') {
try {
query = await json(req);
} catch (err) {
query = undefined;
}
} else {
query = url.parse(req.url, true).query;
}
It uses the json body parser to parse the request. The json parser can only process the request length shorter than 1mb by default. When I uploaded a file(larger than 1mb), the program stopped executation at the line of query = await json(req)
How to overcome this obstacle?
The text was updated successfully, but these errors were encountered:
I solved this problem as this:
try {
await json(req, {limit: '1gb'})
} catch (e) {
throw e
}
return microGraphql({
schema,
context: {
db
}
})(req, res)
As you can see, I call json(req, {limit: '1gb'}) before calling the microGraphql method. The trick is json will cache the content it has prased in an inner WeakMap, thus when the microGraphql method call the json method again in its body, the content in the caching WeakMap will be returned.
The source code of microGraphql in apollo-server-micro is as follow:
It uses the json body parser to parse the request. The json parser can only process the request length shorter than 1mb by default. When I uploaded a file(larger than 1mb), the program stopped executation at the line of query = await json(req)
How to overcome this obstacle?
The text was updated successfully, but these errors were encountered: