Skip to content
This repository was archived by the owner on Sep 3, 2021. It is now read-only.

feat: User-defined Role enum name #519

Merged
merged 1 commit into from
Oct 15, 2020

Conversation

AdrienLemaire
Copy link
Contributor

@AdrienLemaire AdrienLemaire commented Oct 13, 2020

Let the user define an environment variable AUTH_ROLE_ENUM_NAME if he needs to use the name Role for something else.

While hasScope and hasRole are useful for basic authorization cases, other cases are better handled with a Role type and relationships instead of an enum.
I would like to be able to use Role for a graphql type, and RoleTitle for the graphql-auth-directives required enum name.

Example:

enum RoleTitle {
  ADMIN
  STAFF
  TRAINER
  STUDENT
}

type Role {
  title: RoleTitle!
  scopes: [Scope!]
  users: [User!] @relation(name: "HAS", direction: "IN")
}

type User {
  role: Role @relation(name: "HAS", direction: "OUT")
}

type Mutation {
  updateUserRole(id: ID!, role: RoleTitle): User
    @hasScope(scopes: ["User: UpdateRole"])
    @cypher(
      statement: """
      MATCH (u1:User {id: $cypherParams.myId}),
            (u2:User {id: $id}),
            (r:Role {title: $role})
      WHERE (u1)-[:HAS]->(:Role)-[:CAN_UPDATE]->(:Role)<-[rel:HAS]-(u2)
      CALL apoc.refactor.to(rel, r)
      YIELD input, output
      RETURN input, output
      """
    )
}

.env

AUTH_ROLE_ENUM_NAME=RoleTitle

@AdrienLemaire
Copy link
Contributor Author

@johnymontana @michaeldgraham it would be lovely if this trivial PR could be merged soon ❤️

@johnymontana
Copy link
Contributor

Looks good to me. Thanks, @AdrienLemaire!

@johnymontana johnymontana merged commit ef00376 into neo4j-graphql:master Oct 15, 2020
@johnymontana johnymontana added the Needs docs Document the features added in this PR better label Oct 15, 2020
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
Needs docs Document the features added in this PR better
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants