Skip to content

Filters for Nested Documents Via Relay Does Not Filter Properly #50

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
KimMatt opened this issue Aug 24, 2018 · 5 comments
Closed

Filters for Nested Documents Via Relay Does Not Filter Properly #50

KimMatt opened this issue Aug 24, 2018 · 5 comments
Assignees
Labels

Comments

@KimMatt
Copy link

KimMatt commented Aug 24, 2018

Filtering works for a base document to a query. But when filtering by a property for a nested document, the query returns all results regardless of the argument value.

Example.

Schema.py

class Subgraph(MongoengineObjectType):


    class Meta:
        model = SubgraphModel
        interfaces = (RelayNode,)


class Graph(MongoengineObjectType):

    class Meta:
        model = GraphModel
        interfaces = (RelayNode,)

class Query(graphene.ObjectType):

    node = RelayNode.Field()
    graph = RelayNode.Field(Graph)
    graphs = MongoengineConnectionField(Graph)

Model.py

class Subgraph(Document):
    meta = {'collection': 'subgraph'}
    key = StringField(required=True)

class Graph(Document):
    meta = {'collection': 'graph'}
    key = StringField(required=True)
    subgraphs = ListField(ReferenceField(Subgraph), required=True)

Query that fails:

{
 graphs(key:"graph1") {
  edges {
    node {
      id
      subgraphs(key:"none") {
        edges {
          node {
            id
            key
          }
        }
      }
    }
  }
}
}

The first argument to graphs filters properly. But the second argument does not filter at all, because all results are returned.

Result:

{
  "data": {
    "graphs": {
      "edges": [
        {
          "node": {
            "id": "R3JhcGg6NWI3NWU1YWYxMGYyMGMxZDliYmZmYzBj",
            "key": "graph1",
            "subgraphs": {
              "edges": [
                {
                  "node": {
                    "id": "U3ViZ3JhcGg6NWI3NWU1YWYxMGYyMGMxZDliYmZmYzAw",
                    "key": "subgraph1"
                  }
                },
                {
                  "node": {
                    "id": "U3ViZ3JhcGg6NWI3NWU1YWYxMGYyMGMxZDliYmZmYzAx",
                    "key": "subgraph2"
                  }
                },
                {
                  "node": {
                    "id": "U3ViZ3JhcGg6NWI3NWU1YWYxMGYyMGMxZDliYmZmYzAy",
                    "key": "subgraph3"
                  }
                }
              ]
            }
          }
        }
      ]
    }
  }
}

Here is the produced schema

schema {
  query: Query
}

type Graph implements Node {
  id: ID!
  key: String!
  subgraphs(before: String, after: String, first: Int, last: Int, id: ID, key: String): SubgraphConnection
}

type GraphConnection {
  pageInfo: PageInfo!
  edges: [GraphEdge]!
}

type GraphEdge {
  node: Graph
  cursor: String!
}

interface Node {
  id: ID!
}

type PageInfo {
  hasNextPage: Boolean!
  hasPreviousPage: Boolean!
  startCursor: String
  endCursor: String
}

type Query {
  node(id: ID!): Node
  graph(id: ID!): Graph
  graphs(before: String, after: String, first: Int, last: Int,  id: ID, key: String): GraphConnection
}

type Subgraph implements Node {
  id: ID!
  key: String!
}

type SubgraphConnection {
  pageInfo: PageInfo!
  edges: [SubgraphEdge]!
}

type SubgraphEdge {
  node: Subgraph
  cursor: String!
}
@KimMatt KimMatt changed the title Filters for Nested Documents Via Relay Not Filtering Filters for Nested Documents Via Relay Does Not Filter Properly Aug 24, 2018
@abawchen abawchen self-assigned this Oct 24, 2018
@abawchen
Copy link
Collaborator

abawchen commented Oct 25, 2018

@KimMatt, thanks for addressing this issue :)

Regarding your query example, what's the result do you expect?

{
  graphs(key:"graph1") {
    edges {
      node {
        id
        subgraphs(key:"none") {
          edges {
            node {
              id
              key
            }
          }
        }
      }
    }
  }
}
  1. Filter graph first, then subgraph
  {
    "data": {
      "graphs": {
        "edges": [
          {
            "node": {
              "id": "R3JhcGg6NWI3NWU1YWYxMGYyMGMxZDliYmZmYzBj",
              "key": "graph1",
              "subgraphs": {
                "edges": []
              }
            }
          }
        ]
      }
    }
  }
  1. Filter graph key and subgraph key at the same time
  {
    "data": {
      "graphs": {
        "edges": []
      }
    }
  }

@KimMatt
Copy link
Author

KimMatt commented Nov 1, 2018

I would expect number one

    "data": {
      "graphs": {
        "edges": [
          {
            "node": {
              "id": "R3JhcGg6NWI3NWU1YWYxMGYyMGMxZDliYmZmYzBj",
              "key": "graph1",
              "subgraphs": {
                "edges": []
              }
            }
          }
        ]
      }
    }
  }

@nephew92
Copy link

I have had the same problem.

@abawchen
Copy link
Collaborator

Trying to figure out it, memo the reference first: graphql-python/graphene-sqlalchemy#110

@abawchen
Copy link
Collaborator

abawchen commented May 8, 2019

@nephew92 @KimMatt : This feature is ready on updated master and 0.2.5, and you can refer https://github.com/graphql-python/graphene-mongo/blob/master/graphene_mongo/tests/test_relay_query.py#L131 for usage.

Close this one, feel free to reopen it if any issues.

@abawchen abawchen closed this as completed May 8, 2019
abhinand-c pushed a commit to strollby/graphene-mongo that referenced this issue Jun 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants