Skip to content

Commit 43259ac

Browse files
committed
Merge branch 'master' into alpha
2 parents 4c0bf63 + 0575e15 commit 43259ac

File tree

4 files changed

+43
-7
lines changed

4 files changed

+43
-7
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"graphql-compose-pagination": "8.0.1"
3030
},
3131
"peerDependencies": {
32-
"graphql-compose": "^7.21.1",
32+
"graphql-compose": "^7.21.4",
3333
"mongoose": "^5.0.0 || ^4.4.0"
3434
},
3535
"devDependencies": {
@@ -44,7 +44,7 @@
4444
"eslint-plugin-import": "2.22.0",
4545
"eslint-plugin-prettier": "3.1.4",
4646
"graphql": "15.3.0",
47-
"graphql-compose": "7.21.1",
47+
"graphql-compose": "7.21.4",
4848
"jest": "26.4.2",
4949
"mongodb-memory-server": "6.7.5",
5050
"mongoose": "5.10.5",

src/discriminators/__tests__/composeChildTC-test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@ beforeAll(() => schemaComposer.clear());
88

99
describe('composeChildTC ->', () => {
1010
const CharacterDTC = composeWithMongooseDiscriminators(CharacterModel);
11+
CharacterDTC.addRelation('friends', {
12+
resolver: () => CharacterDTC.getResolver('findById'),
13+
prepareArgs: {
14+
_id: (source) => source.friends,
15+
},
16+
projection: { friends: 1 },
17+
});
18+
CharacterDTC.extendField('friends', { type: '[String!]' });
19+
1120
const PersonTC = CharacterDTC.discriminator(PersonModel);
1221
const DroidTC = CharacterDTC.discriminator(DroidModel);
1322

@@ -21,6 +30,16 @@ describe('composeChildTC ->', () => {
2130
expect(PersonTC.getFieldNames()).toEqual(expect.arrayContaining(CharacterDTC.getFieldNames()));
2231
});
2332

33+
it('should copy all relations from BaseDTC to ChildTCs', () => {
34+
expect(DroidTC.getRelations()).toEqual(CharacterDTC.getRelations());
35+
expect(PersonTC.getRelations()).toEqual(CharacterDTC.getRelations());
36+
});
37+
38+
it('should copy the extended Field from BaseDTC to ChildTCs', () => {
39+
expect(DroidTC.getField('friends').type).toEqual(CharacterDTC.getField('friends').type);
40+
expect(PersonTC.getField('friends').type).toEqual(CharacterDTC.getField('friends').type);
41+
});
42+
2443
it('should make childTC have same fieldTypes as baseTC', () => {
2544
const characterFields = CharacterDTC.getFieldNames();
2645

src/discriminators/composeChildTC.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,22 @@ import type {
66
import { prepareChildResolvers } from './prepareChildResolvers';
77
import { reorderFields } from './utils/reorderFields';
88

9+
function copyBaseTcRelationsToChildTc(
10+
baseDTC: ObjectTypeComposer<any, any>,
11+
childTC: ObjectTypeComposer<any, any>
12+
) {
13+
const relations = baseDTC.getRelations();
14+
const childRelations = childTC.getRelations();
15+
Object.keys(relations).forEach((name) => {
16+
if (childRelations[name]) {
17+
return;
18+
}
19+
childTC.addRelation(name, relations[name]);
20+
});
21+
22+
return childTC;
23+
}
24+
925
// copy all baseTypeComposer fields to childTC
1026
// these are the fields before calling discriminator
1127
function copyBaseTCFieldsToChildTC(
@@ -35,7 +51,8 @@ export function composeChildTC<TSource, TContext>(
3551
childTC: ObjectTypeComposer<TSource, TContext>,
3652
opts: ComposeWithMongooseDiscriminatorsOpts<TContext>
3753
): ObjectTypeComposer<TSource, TContext> {
38-
const composedChildTC = copyBaseTCFieldsToChildTC(baseDTC, childTC);
54+
let composedChildTC = copyBaseTcRelationsToChildTc(baseDTC, childTC);
55+
composedChildTC = copyBaseTCFieldsToChildTC(baseDTC, composedChildTC);
3956

4057
composedChildTC.addInterface(baseDTC.getDInterface());
4158

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3179,10 +3179,10 @@ graphql-compose-pagination@8.0.1:
31793179
resolved "https://registry.yarnpkg.com/graphql-compose-pagination/-/graphql-compose-pagination-8.0.1.tgz#785c4c83dec5c81dee7ce5baee71cdf5b7a55240"
31803180
integrity sha512-DxFVSFS9fuDdVOCUz6sr8r1wwwFytUUQ6a2ihQAEdXx7a7p3ZC797RWHdprnnKtLPrioHIIWPCbIoyn4c4kVgQ==
31813181

3182-
graphql-compose@7.21.1:
3183-
version "7.21.1"
3184-
resolved "https://registry.yarnpkg.com/graphql-compose/-/graphql-compose-7.21.1.tgz#e24da849c095485d1cec06c1f7517de8b81308b4"
3185-
integrity sha512-9Cpfdbl9EXla5SR0SmfHB7Q2cEzK9YHZzUPcyktzOO+40wfXsHfoFwCT7CtRU+TiENeHK07hG4zPyqRxD18t8w==
3182+
graphql-compose@7.21.4:
3183+
version "7.21.4"
3184+
resolved "https://registry.yarnpkg.com/graphql-compose/-/graphql-compose-7.21.4.tgz#5927b0906322f12c8ed6de2da204d17fde8fb1f4"
3185+
integrity sha512-sLehZREpIAr1TDnefmZBSrIC0NsyebdQ8I1NJS+OTp/Rkpw1HOWuCzbYosbttlkMewinKgAYFcjE2B3EnS7hIA==
31863186
dependencies:
31873187
graphql-type-json "0.3.2"
31883188
object-path "^0.11.4"

0 commit comments

Comments
 (0)