graphql-compose / graphql-compose/graphql-compose-mongoose

filter for array/list field does not work as expected

Open
#328 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
706
Forks
98
PR merge metrics
No merged PRs in 30d

Description

```javascript
const { Schema } = require('mongoose')
const { SchemaComposer } = require('graphql-compose')
const { composeWithMongoose } = require('graphql-compose-mongoose')

const ArticleSchema = new Schema({
title: {
type: String,
},
content: {
type: String,
},
viewers: {
type: [String],
},
}, {
})

const Article = mongoose.model('Article', ArticleSchema)
const ArticleTC = composeWithMongoose(Article)

schemaComposer.Query.addFields({
articles: ArticleTC.getResolver('findMany'),
})
```

If I have the data as follow
Articles:
```javascript
[
{ title: 'a only', content: 'a', viewers: ['a'] },
{ title: 'b only', content: 'a', viewers: ['b'] },
{ title: 'all 1', content: 'all 1', viewers: ['a', 'b'] },
{ title: 'all 2', content: 'all 2', viewers: ['a', 'b'] },
]
```
if I use the query:
```
query {
a: articles (filter: {
viewers: "a"
}) {
title
}
b: articles (filter: {
viewers: "b"
}) {
title
}
}
```

expected result:
```javascript
{
"data": {
"a": [
{
"title": "a only"
},
{
"title": "all 1"
},
{
"title": "all 2"
}
],
"b": [
{
"title": "b only"
},
{
"title": "all 1"
},
{
"title": "all 2"
}
]
}
}
```

but result becomes:
```javascript
{
"data": {
"a": [
{
"title": "a only"
},
{
"title": "all 1"
},
{
"title": "all 2"
}
],
"b": [
{
"title": "b only"
}
]
}
}
```

Is it something wrong with my implementation or a bug?

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.