Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] - Feature: Discriminator Support on composeMongoose #340

Draft
wants to merge 19 commits into
base: master
Choose a base branch
from
Draft
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
643bae0
Switch type check to use 'instanceof' instead of constructor.name for…
jhbuchanan45 May 10, 2021
afe10e6
Fix linting error in case block
jhbuchanan45 May 12, 2021
8d9bdc6
Merge branch 'graphql-compose:master' into master
jhbuchanan45 May 21, 2021
7d11ae9
Implement optional discriminator handling inside composeMongoose func…
jhbuchanan45 May 24, 2021
0799c4e
Add unit test cases for enhanced discriminator handling
jhbuchanan45 May 24, 2021
fc20db7
Refactor input TC field adding into class method
jhbuchanan45 May 25, 2021
e602693
Export EDiscriminatorTypeComposer index exports and fix type error wi…
jhbuchanan45 May 25, 2021
d586798
Ensure correct types for DTCs are referenced in resolvers using tc.ge…
jhbuchanan45 May 25, 2021
16a5140
Fix bugs with discrimTC resolvers, such as preferring model over scha…
jhbuchanan45 May 26, 2021
425fbb4
Add test case for getDiscriminatorTCs()
jhbuchanan45 May 26, 2021
3cd5c33
Override makeFieldNullable/NonNull() for eDTC with tests
jhbuchanan45 May 27, 2021
01a7d71
Merge branch 'graphql-compose:master' into master
jhbuchanan45 Jun 10, 2021
1523524
Refactor calls to schemaComposer.getAnyTC(...) to use only tc.getType…
jhbuchanan45 Jun 10, 2021
e4b22a5
Merge branch 'graphql-compose:master' into master
jhbuchanan45 Jul 9, 2021
595b147
Merge changes from upstream (Especially allowing resolvers to accept …
jhbuchanan45 Jul 27, 2021
5c8bde5
Merge branch 'master' of https://github.com/graphql-compose/graphql-c…
jhbuchanan45 Jul 27, 2021
14d82de
Change eDTC to extend InterfaceTypeComposer and fix various resulting…
jhbuchanan45 Jul 29, 2021
7d29a85
Tidy eDTC code
jhbuchanan45 Jul 29, 2021
0167cb2
Revert resolvers using tc.getTypeName() instead of directly passing t…
jhbuchanan45 Jul 29, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Tidy eDTC code
  • Loading branch information
jhbuchanan45 committed Jul 29, 2021
commit 7d29a856a3a5f3865239d8005f1999a62550dc13
13 changes: 6 additions & 7 deletions src/enhancedDiscriminators/eDiscriminatorTypeComposer.ts
Original file line number Diff line number Diff line change
@@ -89,6 +89,7 @@ export class EDiscriminatorTypeComposer<TSource, TContext> extends InterfaceType
opts
) as ObjectTypeComposer;

// create new enhanced discriminator TC
const eDTC = new EDiscriminatorTypeComposer(
new GraphQLInterfaceType({
name: typeName,
@@ -104,18 +105,16 @@ export class EDiscriminatorTypeComposer<TSource, TContext> extends InterfaceType
'A custom discriminator key must be set on the model options in mongoose for discriminator behaviour to function correctly'
);
}

eDTC._buildDiscriminatedInterface(model, baseTC);
eDTC.setInputTypeComposer(eDTC.DInputObject.getInputTypeComposer());

// eDTC.setInterfaces([eDTC.DInterface]);
// set input to custom OTC since IFTCs are not supported in graphQL as inputs
eDTC.setInputTypeComposer(eDTC.DInputObject.getInputTypeComposer());
eDTC._gqcInputTypeComposer = eDTC.DInputObject._gqcInputTypeComposer;

// reorderFields(eDTC, eDTC.opts.reorderFields, eDTC.discriminatorKey);
eDTC.schemaComposer.addSchemaMustHaveType(eDTC as any);

// prepare Base Resolvers
// prepareBaseResolvers(eDTC);

// cleanup baseTC
schemaComposer.delete(baseTC.getTypeName());
return eDTC as any;
@@ -125,8 +124,7 @@ export class EDiscriminatorTypeComposer<TSource, TContext> extends InterfaceType
model: Model<any, any>,
baseTC: ObjectTypeComposer<any, TContext>
): EDiscriminatorTypeComposer<TSource, TContext> {
this.removeOtherFields('');
this.setFields(baseTC.getFields());
this.setFields(baseTC.getFields()); // should be overriden at internal setField call?
this.DInputObject.setFields(baseTC.getFields());

const discriminators = model.discriminators || model.schema.discriminators;
@@ -172,6 +170,7 @@ export class EDiscriminatorTypeComposer<TSource, TContext> extends InterfaceType
this._addFieldToInputOTC(fieldName, field);
});

// make field optional on input if not from baseTC, since we cannot specify individual union types, but rather must produce an input object type that can accept all union types at once
this.DInputObject.makeFieldNullable(
discrimTC.getFieldNames().filter((field) => !baseTC.hasField(field))
);