Skip to content

Releases: graphql-compose/graphql-compose-mongoose

v4.5.0

09 Aug 19:02
Compare
Choose a tag to compare

4.5.0 (2018-08-09)

Features

  • TypeScript: added definition files (thanks @toverux) (723ae7c)
  • FieldConverter: now support deeply nested arrays (504aec0)

For field someDeepField will be returned type [SomeDeepFieldPeriods] instead of JSON:

const UserSchema = new Schema({
  someDeepField: {
    periods: [{ from: Number, to: Number }],
  },
});

v4.4.2

18 Jul 08:40
Compare
Choose a tag to compare

4.4.2 (2018-07-18)

Bug Fixes

  • Discriminators: copying base InputTypes to base resolver ArgTypes (88451fd)

v4.4.1

18 Jul 04:42
Compare
Choose a tag to compare

4.4.1 (2018-07-18)

Bug Fixes

  • replace wrong type input on TypeConverterResolverOpts to record (8fb2928)

v4.4.0

17 Jul 11:09
6d03cf0
Compare
Choose a tag to compare

4.4.0 (2018-07-17)

Features

  • discriminators: add composeWithMongooseDiscriminators (df8d4f4) Thanks a lot @mernxl for amazing work! 👍

How to use

  import mongoose from 'mongoose';
  import { schemaComposer } from 'graphql-compose';
  import { composeWithMongooseDiscriminators } from 'graphql-compose-mongoose';

  // pick a discriminatorKey
  const DKey = 'type';

  const enumCharacterType = {
    PERSON: 'Person',
    DROID: 'Droid',
  };

  // DEFINE BASE SCHEMA
  const CharacterSchema = new mongoose.Schema({
    // _id: field...
    type: {
      type: String,
      require: true,
      enum: (Object.keys(enumCharacterType): Array<string>),
      description: 'Character type Droid or Person',
    },

    name: String,
    height: Number,
    mass: Number,
    films: [String],
  });

  // DEFINE DISCRIMINATOR SCHEMAS
  const DroidSchema = new mongoose.Schema({
    makeDate: String,
    primaryFunction: [String],
  });

  const PersonSchema = new mongoose.Schema({
    gender: String,
    hairColor: String,
    starships: [String],
  });

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

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

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

  // create DiscriminatorTypeComposer
  const baseOptions = { // regular TypeConverterOptions, passed to composeWithMongoose
    fields: {
      remove: ['friends'],
    }
  }
  const CharacterDTC = composeWithMongooseDiscriminators(CharacterModel, baseOptions);

  // create Discriminator Types
  const droidTypeConverterOptions = {  // this options will be merged with baseOptions -> customisationsOptions
    fields: {
      remove: ['makeDate'],
    }
  };
  const DroidTC = CharacterDTC.discriminator(DroidModel, droidTypeConverterOptions);
  const PersonTC = CharacterDTC.discriminator(PersonModel);  // baseOptions -> customisationsOptions applied

  // You may now use CharacterDTC to add fields to all Discriminators
  // Use DroidTC, `PersonTC as any other TypeComposer.
  schemaComposer.Mutation.addFields({
    droidCreate: DroidTC.getResolver('createOne'),
    personCreate: PersonTC.getResolver('createOne'),
  });

  const schema = schemaComposer.buildSchema();

Live demo

screen shot 2018-07-17 at 16 34 22

v4.3.0

10 Jul 12:28
Compare
Choose a tag to compare

4.3.0 (2018-07-10)

Features

  • already generated TC may be obtained via schemaComposer.getTC(mongooseSchema) (34e756d)

v4.2.1

10 Jul 10:23
Compare
Choose a tag to compare

4.2.1 (2018-07-10)

Bug Fixes

  • mongoose 5.2.0 now uses countDocuments instead of count (86f05c9), closes #108

v4.2.0

26 Jun 15:24
Compare
Choose a tag to compare

4.2.0 (2018-06-26)

Features

  • add mjs build (es6 modules) (b3d67ee)

v4.1.1

27 Apr 17:12
Compare
Choose a tag to compare

4.1.1 (2018-04-27)

Bug Fixes

  • rename deprecated method getTypeAsRequired on getTypeNonNull (799954d)

v4.1.0

20 Apr 08:29
Compare
Choose a tag to compare

4.1.0 (2018-04-20)

Features

  • MongoID: allow to override build-in MongoID type (720f0ba)

From new 4.1.0 version you may override build-in MongoID type by your GraphQL class type implementation (related issue #98):

import { schemaComposer } from 'graphql-compose';
import { composeWithMongoose } from 'graphql-compose-mongoose';

schemaComposer.set('MongoID', YOUR_CLASS_TYPE_IMPLEMENTATION);
const UserTC = composeWithMongoose(UserModel, { schemaComposer });

v4.0.0

16 Apr 19:47
Compare
Choose a tag to compare

4.0.0 (2018-04-16)

Code Refactoring

BREAKING CHANGES

  • now min required graphql-compose version is 4.0.0