Resolving updateGQLSchema failed because Type User: @auth: failed to validate GraphQL rule [reason : Field "eq" is not defined by type ID.]

Weird error. If I paste my schema into Dgraph Cloud and deploy it I get the following error:

resolving updateGQLSchema failed because Type User: @auth: failed to validate GraphQL rule [reason : Field "eq" is not defined by type ID.]

The User type from my schema:

type User @auth(
  query: { or: [
    { rule: """
        query($EMAIL: String!) {
          queryUser(filter: {
            email: {
              eq: $EMAIL
            }
          }) {
            id
          }
        }
      """
    }
    { rule: """
        query($USERID: String!) {
          queryUser(filter: {
            id: {
              eq: $USERID
            }
          }) {
            id
          }
        }
      """
    }
    { rule:  "{$ROLE: { eq: \"ADMIN\" } }" }
  ]}
  add: { or: [
    { rule: "{ $ROLE: { eq: \"ADMIN\" } }" }
    { rule: """
        query($EMAIL: String!) {
          queryUser(filter: {
            email: {
              eq: $EMAIL
            }
          }) {
            id
          }
        }
      """
    }
  ]},
) {
  id: ID!
  email: String! @id
  username: String
  stripeCustomerId: String
}

EDIT: So I verified that it has a problem with this specific rule:

    { rule: """
        query($USERID: String!) {
          queryUser(filter: {
            id: {
              eq: $USERID
            }
          }) {
            id
          }
        }
      """
    }

Changing the rule in question to the following fixed the issue. For some reason eq: doesn’t work with ID fields and the $USERID value from the JWT needs to be typed as ID!:

    { rule: """
        query($USERID: ID!) {
          queryUser(filter: {
            id: [$USERID]
          }) {
            id
          }
        }
      """
    }
1 Like