GraphQL filter on second relationship not working (one to many to one)

I defined product, contributions and actors (a collection for each). A product has contributions (list of ObjectID) and a contribution has an actor [and a product] (objectID reference). When I want all products with contributions with actors with a certain name or postcode, it doesn’t work. The name or postcode filter is not applied.

The query :

query {
  product_contributions(query: { actor: { name: "test"} } ) {
    product{
      name
    }
    actor {
      name
    }
  }
  products(query: { contributions: { actor : { name: "test" } } }) {
    name
    contributions {
      actor {
        name
      }
    }
  }
}

gives

{
  "data": {
    "product_contributions": [],
    "products": [
      {
        "contributions": [
          {
            "actor": {
              "name": "Coopérative Pur Ardenne"
            }
          }
        ],
        "name": "Lait de Pâturage demi-écrémé"
      }
    ]
  }
}

Both should be empty …

Defined relationship for product :

{
  "contributions": {
    "foreign_key": "_id",
    "ref": "#/relationship/mongodb-atlas/digicirco/product_contributions",
    "is_list": true
  }
}

Defined relationships for product_contributions :

{
  "actor": {
    "ref": "#/relationship/mongodb-atlas/digicirco/actors",
    "foreign_key": "_id",
    "is_list": false
  },
  "product": {
    "ref": "#/relationship/mongodb-atlas/digicirco/products",
    "foreign_key": "_id",
    "is_list": false
  }
}
1 Like

Hello @Olivier_Wouters ,

I have the same problem,
Did you find a solution?

Thank you

Hi Cyril, no I didn’t :wink:

Hi @Olivier_Wouters

I have found a way. Maybe not the best but it works :smiley:

If i take your example, what i do is managing my record with product_contribution query and mutation. This way i can create Products and Contribution from the product_contribution definition.
If you use the product_contribution mutation, you can query product_contribution also

Moreover when you use the product_contribution mutation, you can also query Product but you wont be able to get the relation with contribution (you can do that only with product_contribution)

You can query any product (per id or all of them)
You can query any contribution (per id or all of them)

The entry point for your mutation should be product_contribution

Best regards

I even noticed that one to many with filter doesn’t always work … For instance, greater than doesn’t work for subfield in one to many relationship …

1 Like