Inconsistent results when searching for node via GraphQL

I’ve noticed that certain filters doesn’t work as expected when running GraphQL query against dgraph, but works fine when running GraphQL± query from Ratel.

Given following GraphQL schema applied to local dgraph instance and after uploading data.

interface Node{
    id: ID!
}

type Company implements Node {
    companyId: String! @search(by: [hash])
    entityId: String! @search(by: [hash])
    name: String! @search(by: [hash, fulltext, trigram])
}

This GraphQL query

{
  getCompany(id: "0x2") {
    id
    name
    companyId
    entityId
  }
  byEntityId: queryCompany(filter: { entityId: { eq: "061TZG-E" } }) {
    id
    name
    companyId
    entityId
  }
  byCompanyId: queryCompany(filter: { companyId: { eq: "241285" } }) {
    id
    name
    companyId
    entityId
  }
}

Doesn’t return data when filtering by companyId

{
  "data": {
    "getCompany": {
      "id": "0x2",
      "name": "University of Miami",
      "companyId": "241285",
      "entityId": "061TZG-E"
    },
    "byEntityId": [
      {
        "id": "0x2",
        "name": "University of Miami",
        "companyId": "241285",
        "entityId": "061TZG-E"
      }
    ],
    "byCompanyId": []
  }
}

Similar query in Ratel

{
  getCompany(func: uid(0x2)) {
    uid
    Company.name
    Company.companyId
    Company.entityId
  }
  byEntityId(func: eq(Company.entityId, "061TZG-E")) {
    uid
    Company.name
    Company.companyId
    Company.entityId
  }
  byCompanyId(func: eq(Company.companyId, "241285")) {
    uid
    Company.name
    Company.companyId
    Company.entityId
  }
}

Returns all data as expected

{
  "data": {
    "getCompany": [
      {
        "uid": "0x2",
        "Company.name": "University of Miami",
        "Company.companyId": "241285",
        "Company.entityId": "061TZG-E"
      }
    ],
    "byEntityId": [
      {
        "uid": "0x2",
        "Company.name": "University of Miami",
        "Company.companyId": "241285",
        "Company.entityId": "061TZG-E"
      }
    ],
    "byCompanyId": [
      {
        "uid": "0x2",
        "Company.name": "University of Miami",
        "Company.companyId": "241285",
        "Company.entityId": "061TZG-E"
      }
    ]
  },
  "extensions": {
    "server_latency": {
      "parsing_ns": 102305,
      "processing_ns": 14200971,
      "encoding_ns": 23572,
      "assign_timestamp_ns": 551218,
      "total_ns": 14944192
    },
    "txn": {
      "start_ts": 1819
    },
    "metrics": {
      "num_uids": {
        "": 1,
        "Company.companyId": 3,
        "Company.entityId": 3,
        "Company.name": 3,
        "uid": 3
      }
    }
  }
}

What might be causing this inconsitency?

Hi @KTannenberg, Thanks for reporting this. Could you please also share the “extensions” section from the graphql query, just as you have shared from graphql±?
I am not able to see this inconsistency. Here is the response I get from the graphql query.

{
  "data": {
    "getCompany": {
      "id": "0x2",
      "name": "University of Miami",
      "companyId": "241285",
      "entityId": "061TZG-E"
    },
    "byEntityId": [
      {
        "id": "0x2",
        "name": "University of Miami",
        "companyId": "241285",
        "entityId": "061TZG-E"
      }
    ],
    "byCompanyId": [
      {
        "id": "0x2",
        "name": "University of Miami",
        "companyId": "241285",
        "entityId": "061TZG-E"
      }
    ]
  },
  "extensions": {
    "touched_uids": 16,
    "tracing": {
      "version": 1,
      "startTime": "2020-08-06T16:39:11.262380597Z",
      "endTime": "2020-08-06T16:39:11.27031757Z",
      "duration": 7936973,
      "execution": {
        "resolvers": [
          {
            "path": [
              "getCompany"
            ],
            "parentType": "Query",
            "fieldName": "getCompany",
            "returnType": "Company",
            "startOffset": 314144,
            "duration": 7337111,
            "dgraph": [
              {
                "label": "query",
                "startOffset": 383705,
                "duration": 7197919
              }
            ]
          },
          {
            "path": [
              "byEntityId"
            ],
            "parentType": "Query",
            "fieldName": "byEntityId",
            "returnType": "[Company]",
            "startOffset": 408289,
            "duration": 7389562,
            "dgraph": [
              {
                "label": "query",
                "startOffset": 487767,
                "duration": 7245341
              }
            ]
          },
          {
            "path": [
              "byCompanyId"
            ],
            "parentType": "Query",
            "fieldName": "byCompanyId",
            "returnType": "[Company]",
            "startOffset": 293820,
            "duration": 7573592,
            "dgraph": [
              {
                "label": "query",
                "startOffset": 380911,
                "duration": 7432095
              }
            ]
          }
        ]
      }
    }
  }
}

Also please share how you created data (ratel, graphql or some other way)?

How can I do that? Using GraphiQL/Postman/Graphql Playground all returns me results without extensions node, all of them also consistently doesn’t return anything in byCompanyId node.

Data was created from Java application using dgraphj 20.03.0. Dgraph is running in local docker as following (no further modifications besides applying GraphQL schema via /admin/schema endpoint)

docker run --name dgraph --restart unless-stopped  -d -p 8080:8080 -p 9080:9080 -p 8000:8000 -v ~/dgraph:/dgraph dgraph/standalone:v20.03.0

I’ve now completely wiped data folder, recreated container and started uploading data again. UIDs changed obviously but filter on both external IDs seems to work fine now.

{
  "data": {
    "getCompany": {
      "id": "0xfd",
      "name": "University of Miami",
      "companyId": "241285",
      "entityId": "061TZG-E"
    },
    "byEntityId": [
      {
        "id": "0xfd",
        "name": "University of Miami",
        "companyId": "241285",
        "entityId": "061TZG-E"
      }
    ],
    "byCompanyId": [
      {
        "id": "0xfd",
        "name": "University of Miami",
        "companyId": "241285",
        "entityId": "061TZG-E"
      }
    ]
  }
}
1 Like

Particular code responsible for creating Company entities is as following:

    Function<SqlRowSet, Mutation> mapper = row -> {
      var contents = Map.of(
          "uid", "_:" + row.getString("ENTITY_ID"),
          "dgraph.type", List.of("Node", "Company"),
          "Company.companyId", row.getString("COMPANY_ID"),
          "Company.entityId", row.getString("ENTITY_ID"),
          "Company.name", row.getString("NAME")
      );
      return fromJson(contents);
    };
  @SneakyThrows
  private Mutation fromJson(Map<String, ?> jsonContents) {
    var json = jackson.writeValueAsString(jsonContents);
    return Mutation.newBuilder()
        .setSetJson(ByteString.copyFromUtf8(json))
        .build();
  }

I was not able to recreate this issue. I tried creating data via ratel as well as graphiql. Please let me know if there is some way we can recreate this.