How to make auth work with interfaces?

I can’t seem to query interfaces if I have @auth on the implemented types. Here’s a quick example:

I start with this basic schema:

type User {
  email: String! @id
}

interface Person {
  id: ID!
  user: User!
  name: String
}

type Employee implements Person {
    position: String
}

type Customer implements Person {
    Points: Int
}

I add one employee and one customer named Joe and Fiona using the default Create handler. Now this query:

{
  queryCustomer {
    name
  }
  queryEmployee {
    name
  }
  queryPerson {
    name
  }
}

returns as expected:

"data": {
    "queryCustomer": [
      {
        "name": "Joe"
      }
    ],
    "queryEmployee": [
      {
        "name": "Fiona"
      }
    ],
    "queryPerson": [
      {
        "name": "Joe"
      },
      {
        "name": "Fiona"
      }
    ]
  }

But now I want to add auth to the schema:

type User {
  email: String! @id
}

interface Person {
  id: ID!
  user: User!
  name: String
}

type Employee implements Person @auth(
  query: {
    rule: """
      query($USER: String!) {
        queryEmployee {
          user(filter: {email: {eq: $USER}}) {
            __typename
          }
        }
      }
    """
  }
) {
    position: String
}

type Customer implements Person @auth(
  query: {
    rule: """
      query($USER: String!) {
        queryCustomer {
          user(filter: {email: {eq: $USER}}) {
            __typename
          }
        }
      }
    """
  }
) {
    Points: Int
}

# Dgraph.Authorization <snip>

Now the same query as before returns:

"data": {
    "queryCustomer": [
      {
        "name": "Joe"
      }
    ],
    "queryEmployee": [
      {
        "name": "Fiona"
      }
    ],
    "queryPerson": []
  },

Note that queryPerson is now empty, but I expected two results.

I tried modifying the auth rule to use queryPerson instead of queryCustomer, but the schema said it only expected queryCustomer rules. How can I query the interface with auth and still get expected data?

1 Like

Hi @dusty-phillips,

Dgraph does not support auth with interfaces currently. Supporting auth with interfaces has been asked by users before and is worked upon. You may read more about it here.

1 Like