Skip to content

Commit

Permalink
Merge pull request #15 from Enigmatis/empty-context-bug
Browse files Browse the repository at this point in the history
Empty context bug
  • Loading branch information
chenshoo authored Jan 6, 2020
2 parents 9801d43 + b5e3746 commit 164ba17
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/data-version/data-version-middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ export class DataVersionMiddleware {
this.logger.debug('Data version middleware started job', { context });
const result = await resolve(root, args, context, info);
let finalResult = result;
context = context || {};
if (
!root &&
context &&
context.requestHeaders &&
context.requestHeaders.dataVersion &&
!isNaN(context.requestHeaders.dataVersion) &&
Expand Down
10 changes: 6 additions & 4 deletions src/realities/realities-middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ export class RealitiesMiddleware {
return result;
}
const operationalRealityId: number = 0;
context.requestHeaders.realityId = context.requestHeaders.realityId || 0;
const realityId =
(context && context.requestHeaders && context.requestHeaders.realityId) || 0;
const noRealityIdOrSameAsHeader = (entity: any) =>
entity.realityId === undefined ||
entity.realityId === context.requestHeaders.realityId;
entity.realityId === undefined || entity.realityId === realityId;
if (!root) {
if (Array.isArray(result)) {
return result.filter(noRealityIdOrSameAsHeader);
Expand All @@ -35,7 +35,9 @@ export class RealitiesMiddleware {
}
} else if (
noRealityIdOrSameAsHeader(result) ||
(context.requestHeaders.includeLinkedOper &&
(context &&
context.requestHeaders &&
context.requestHeaders.includeLinkedOper &&
result.realityId === operationalRealityId)
) {
return result;
Expand Down

0 comments on commit 164ba17

Please sign in to comment.