graphql-compose / graphql-compose-mongoose

Mongoose model converter to GraphQL types with resolvers for graphql-compose https://github.com/nodkz/graphql-compose
MIT License
708 stars 94 forks source link

Filter arguments not filtering correct #318

Closed dmfilipenko closed 3 years ago

dmfilipenko commented 3 years ago

I have a such query

{
  couponFindMany {
    title
    discountType
  }
}

which return me a list of coupons

 [
  {
    "title": "New discount 3",
    "discountType": "standard"
  },
  {
    "title": "TEST10",
    "discountType": "standard"
  },
  {
    "title": "coupon",
    "discountType": "standard"
  }
]

When I'm trying to do a filter

{
  couponFindMany(filter:{
    discountType: standard
  }) {
    title
    discountType
  }
}

I got this result

[
  {
    "title": "coupon",
    "discountType": "standard"
  }
]

Schema composer looks like this

schemaComposer.Query.addFields({
  couponFindMany: CouponTC.mongooseResolvers.findMany({
    filter: {
      operators: true,
    },
  }),
})

Data model

const couponSchema = new Schema(
  {
    title: {
      type: String,
      unique: true,
    },
    discountType: {
      type: String,
      enum: [CouponType.STANDARD, CouponType.AUTO],
      default: CouponType.STANDARD,
    },
  },
  {
    timestamps: true,
  }
)
yurtaev commented 3 years ago

Could you try to turn on mongoose debugging https://mongoosejs.com/docs/faq.html#enable_debugging and check query in console.

dmfilipenko commented 3 years ago

@yurtaev coupons.find({ discountType: 'standard' }, { limit: 100, projection: { title: true, discountType: true } })

yurtaev commented 3 years ago

Looks like the correct query, try to check records in database or raw graphql query.

dmfilipenko commented 3 years ago

@yurtaev thanks for cooperation. just checked database, and it's seems incorrect. Some of the fields in database doesnt have field discountType, but since in mongoose schema default value is standart, I guess graphql showing this field, even if it empty. for now can be close