Getting Filter to Work

I am using the tutorial schema of:

type Task {
  id: ID!
  title: String! @search(by: [fulltext])
  completed: Boolean! @search
  user: User!
}
type User {
  username: String! @id @search(by: [hash])
  name: String
  tasks: [Task] @hasInverse(field: user)
}

and running the query:

query MyQuery {
  queryTask {
    user(filter: {username: {eq: "alice@dgraph.io"}}) {
      username
    }
  }
}

gives the error:

  "errors": [
    {
      "message": "Non-nullable field 'user' (type User!) was not present in result from Dgraph.  GraphQL error propagation triggered.",
      "locations": [
        {
          "line": 3,
          "column": 5
        }
      ],
      "path": [
        "queryTask",
        2,
        "user"
      ]
    },
    {
      "message": "Non-nullable field 'user' (type User!) was not present in result from Dgraph.  GraphQL error propagation triggered.",
      "locations": [
        {
          "line": 3,
          "column": 5
        }
      ],
      "path": [
        "queryTask",
        3,
        "user"
      ]
    },
    {
      "message": "Non-nullable field 'user' (type User!) was not present in result from Dgraph.  GraphQL error propagation triggered.",
      "locations": [
        {
          "line": 3,
          "column": 5
        }
      ],
      "path": [
        "queryTask",
        4,
        "user"
      ]
    },
    {
      "message": "Non-nullable field 'user' (type User!) was not present in result from Dgraph.  GraphQL error propagation triggered.",
      "locations": [
        {
          "line": 3,
          "column": 5
        }
      ],
      "path": [
        "queryTask",
        5,
        "user"
      ]
    },
    {
      "message": "Non-nullable field 'user' (type User!) was not present in result from Dgraph.  GraphQL error propagation triggered.",
      "locations": [
        {
          "line": 3,
          "column": 5
        }
      ],
      "path": [
        "queryTask",
        6,
        "user"
      ]
    }
  ],
  "data": {
    "queryTask": [
      {
        "user": {
          "username": "alice@dgraph.io"
        }
      },
      {
        "user": {
          "username": "alice@dgraph.io"
        }
      },
      null,
      null,
      null,
      null,
      null
    ]
  },
  "extensions": {
    "touched_uids": 19,
    "tracing": {
      "version": 1,
      "startTime": "2021-06-07T03:05:14.398709351Z",
      "endTime": "2021-06-07T03:05:14.400413034Z",
      "duration": 1703705,
      "execution": {
        "resolvers": [
          {
            "path": [
              "queryTask"
            ],
            "parentType": "Query",
            "fieldName": "queryTask",
            "returnType": "[Task]",
            "startOffset": 111457,
            "duration": 1538085,
            "dgraph": [
              {
                "label": "query",
                "startOffset": 169347,
                "duration": 1443267
              }
            ]
          }
        ]
      }
    }
  }
}

FWIW, without the filter the query:

query MyQuery {
  queryTask {
    user {
      username
    }
  }
}

returns

{
  "data": {
    "queryTask": [
      {
        "user": {
          "username": "alice@dgraph.io"
        }
      },
      {
        "user": {
          "username": "alice@dgraph.io"
        }
      },
      {
        "user": {
          "username": "email@example.com"
        }
      },
      {
        "user": {
          "username": "email@example.com"
        }
      },
      {
        "user": {
          "username": "email@example.com"
        }
      },
      {
        "user": {
          "username": "email@example.com"
        }
      },
      {
        "user": {
          "username": "alice@graph.io"
        }
      }
    ]
  },
  "extensions": {
    "touched_uids": 20,
    "tracing": {
      "version": 1,
      "startTime": "2021-06-07T03:06:03.144379984Z",
      "endTime": "2021-06-07T03:06:03.146002789Z",
      "duration": 1622823,
      "execution": {
        "resolvers": [
          {
            "path": [
              "queryTask"
            ],
            "parentType": "Query",
            "fieldName": "queryTask",
            "returnType": "[Task]",
            "startOffset": 83378,
            "duration": 1488732,
            "dgraph": [
              {
                "label": "query",
                "startOffset": 124075,
                "duration": 1400160
              }
            ]
          }
        ]
      }
    }
  }
}

What version of Dgraph are you using? I was unable to reproduce this on my Cloud instance (v21.03.0-31-gdbd574439)

I’m using dgraph cloud (v20.11.2-rc1-23-gaf5030a5). Feel free to checkout my instance if you want, it’s all public https://empty-pine.us-west-2.aws.cloud.dgraph.io/graphql

@ chewxy any idea?

I’d wait for the cloud upgrades to finish processing

I experienced this too.

Solution right now is to either add @cascade to some extent to remove nodes that do not have the filtered edges when those edges are required, or remove the requirement ! from an edge that you want to query that may not be present when filtered.

Depending on your code, you make want to make sure the @auth rule is set when you add the task.

J