Given the following GraphQL query to fetch user roles, what will be the output?
query { user(id: "123") { id name roles } }Assume the user with id "123" has roles: ["admin", "editor"]
query { user(id: "123") { id name roles } }Check the roles assigned to the user with id "123".
The user with id "123" has roles "admin" and "editor". The query returns these roles correctly.
In a role-based access control system, which statement best describes role hierarchies?
Think about how permissions can be shared or extended between roles.
Role hierarchies allow roles to inherit permissions from other roles, simplifying management.
Which of the following GraphQL schema snippets correctly defines a User type with roles as a list of strings?
type User { id: ID! name: String! roles: [String!]! }Roles should be a non-null list of non-null strings.
Option B correctly defines roles as a non-null list of non-null strings, ensuring roles are always present and valid.
You want to optimize role checks in your GraphQL resolvers to avoid repeated database calls. Which approach is best?
Think about efficiency and avoiding repeated work.
Caching user roles once per request reduces database calls and improves performance.
Given this resolver snippet, what error will occur if the user object is null?
const resolver = (parent, args, context) => { if (!context.user.roles.includes('admin')) { throw new Error('Access denied'); } return 'Success'; }Consider what happens if context.user is null.
If context.user is null, accessing roles causes a TypeError because you cannot read properties of null.