Skip to content

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

Closed
@KimMatt

Description

@KimMatt

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!
}

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions