How to use the graphql-compose-mongoose.composeWithMongooseDiscriminators function in graphql-compose-mongoose

To help you get started, we’ve selected a few graphql-compose-mongoose examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github graphql-compose / graphql-compose-examples / examples / mongooseDiscriminators / models.js View on Github external
gender: String,
  hairColor: String,
  starships: [String],
});

// set discriminator Key
CharacterSchema.set('discriminatorKey', DKey);

// create base Model
export const CharacterModel = mongoose.model('Character', CharacterSchema);

// create mongoose discriminator models
export const DroidModel = CharacterModel.discriminator(enumCharacterType.DROID, DroidSchema);
export const PersonModel = CharacterModel.discriminator(enumCharacterType.PERSON, PersonSchema);

export const CharacterDTC = composeWithMongooseDiscriminators(CharacterModel, {
  schemaComposer,
});

type DroidT = any;
export const DroidTC: ObjectTypeComposer = CharacterDTC.discriminator(
  DroidModel
);

type PersonT = any;
export const PersonTC: ObjectTypeComposer = CharacterDTC.discriminator(
  PersonModel
);