Skip to content

Commit

Permalink
fix(entity/context): coalesce default/forced context properties
Browse files Browse the repository at this point in the history
  • Loading branch information
ssube committed Oct 28, 2019
1 parent 02b7cc3 commit 3d2adb2
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/entity/Context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Column, Entity, PrimaryGeneratedColumn } from 'typeorm';
import { Listener } from '../listener';
import { Parser } from '../parser';
import { ServiceMetadata } from '../Service';
import { doesExist, Optional } from '../utils';
import { doesExist, mustCoalesce, Optional } from '../utils';
import { Token } from './auth/Token';
import { GRAPH_OUTPUT_USER, User } from './auth/User';
import { BaseEntity, BaseEntityOptions } from './base/BaseEntity';
Expand Down Expand Up @@ -193,12 +193,19 @@ export function extractRedirect(stage: Optional<Partial<ContextRedirectStage>>):
}

export function redirectContext(original: Context, redirect: ContextRedirect): Context {
const channel = mustCoalesce(redirect.defaults.channel, original.channel, redirect.forces.channel);
const name = mustCoalesce(redirect.defaults.name, original.name, redirect.forces.name);
const uid = mustCoalesce(redirect.defaults.uid, original.uid, redirect.forces.uid);
// loop up source and target services, user
const source = original.source;
const target = original.target;

return new Context({
...extractRedirect(redirect.defaults),
...original,
...extractRedirect(redirect.forces),
channel,
name,
source,
target,
uid,
});
}

Expand Down

0 comments on commit 3d2adb2

Please sign in to comment.