GraphQL: Optimize queries, fixes some null returns (on object), fix stitched GraphQLUpload (#6709)
* Optimize query, fixes some null returns, fix stitched GraphQLUpload * Fix authData key selection * Prefer Iso string since other GraphQL solutions use this format * fix tests Co-authored-by: Antonio Davi Macedo Coelho de Castro <adavimacedo@gmail.com>
This commit is contained in:
@@ -239,13 +239,13 @@ export function handleParseHeaders(req, res, next) {
|
||||
});
|
||||
}
|
||||
})
|
||||
.then((auth) => {
|
||||
.then(auth => {
|
||||
if (auth) {
|
||||
req.auth = auth;
|
||||
next();
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
.catch(error => {
|
||||
if (error instanceof Parse.Error) {
|
||||
next(error);
|
||||
return;
|
||||
@@ -416,12 +416,16 @@ export function promiseEnforceMasterKeyAccess(request) {
|
||||
*/
|
||||
export function promiseEnsureIdempotency(req) {
|
||||
// Enable feature only for MongoDB
|
||||
if (!(req.config.database.adapter instanceof MongoStorageAdapter)) { return Promise.resolve(); }
|
||||
if (!(req.config.database.adapter instanceof MongoStorageAdapter)) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
// Get parameters
|
||||
const config = req.config;
|
||||
const requestId = ((req || {}).headers || {})["x-parse-request-id"];
|
||||
const requestId = ((req || {}).headers || {})['x-parse-request-id'];
|
||||
const { paths, ttl } = config.idempotencyOptions;
|
||||
if (!requestId || !config.idempotencyOptions) { return Promise.resolve(); }
|
||||
if (!requestId || !config.idempotencyOptions) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
// Request path may contain trailing slashes, depending on the original request, so remove
|
||||
// leading and trailing slashes to make it easier to specify paths in the configuration
|
||||
const reqPath = req.path.replace(/^\/|\/$/, '');
|
||||
@@ -435,23 +439,27 @@ export function promiseEnsureIdempotency(req) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!match) { return Promise.resolve(); }
|
||||
if (!match) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
// Try to store request
|
||||
const expiryDate = new Date(new Date().setSeconds(new Date().getSeconds() + ttl));
|
||||
return rest.create(
|
||||
config,
|
||||
auth.master(config),
|
||||
'_Idempotency',
|
||||
{ reqId: requestId, expire: Parse._encode(expiryDate) }
|
||||
).catch (e => {
|
||||
if (e.code == Parse.Error.DUPLICATE_VALUE) {
|
||||
throw new Parse.Error(
|
||||
Parse.Error.DUPLICATE_REQUEST,
|
||||
'Duplicate request'
|
||||
);
|
||||
}
|
||||
throw e;
|
||||
});
|
||||
const expiryDate = new Date(
|
||||
new Date().setSeconds(new Date().getSeconds() + ttl)
|
||||
);
|
||||
return rest
|
||||
.create(config, auth.master(config), '_Idempotency', {
|
||||
reqId: requestId,
|
||||
expire: Parse._encode(expiryDate),
|
||||
})
|
||||
.catch(e => {
|
||||
if (e.code == Parse.Error.DUPLICATE_VALUE) {
|
||||
throw new Parse.Error(
|
||||
Parse.Error.DUPLICATE_REQUEST,
|
||||
'Duplicate request'
|
||||
);
|
||||
}
|
||||
throw e;
|
||||
});
|
||||
}
|
||||
|
||||
function invalidRequest(req, res) {
|
||||
|
||||
Reference in New Issue
Block a user