Schema visibility control is the practice of limiting which parts of a GraphQL schema are visible or accessible to different users or clients, helping protect sensitive data and simplify the API.
Click to reveal answer
intermediate
How can you restrict access to certain fields in a GraphQL schema?
You can restrict access by using authorization logic in resolvers or by creating separate schema layers that expose only allowed fields to specific users.
Click to reveal answer
intermediate
What is a common method to implement schema visibility control?
A common method is to use schema stitching or schema delegation to create different schema views for different user roles, showing only permitted fields.
Click to reveal answer
beginner
Why is schema visibility control important in GraphQL APIs?
It helps protect sensitive information, reduces data exposure risks, and improves API usability by showing only relevant data to each user.
Click to reveal answer
intermediate
Can schema visibility control affect API performance?
Yes, by limiting visible fields, it can reduce data processing and network load, improving performance for clients.
Click to reveal answer
What does schema visibility control primarily help with in GraphQL?
ALimiting data exposure to users
BIncreasing query complexity
CAdding more fields to the schema
DImproving database indexing
✗ Incorrect
Schema visibility control limits which parts of the schema users can see, protecting sensitive data.
Which technique can be used to create different schema views for different users?
AIndexing
BDatabase sharding
CSchema stitching
DCaching
✗ Incorrect
Schema stitching allows combining or splitting schemas to control visibility for different users.
Where is authorization logic usually applied to control schema visibility?
AIn the network layer
BIn the database schema
CIn the client UI
DIn resolvers
✗ Incorrect
Resolvers handle data fetching and can include checks to restrict access to fields.
What is a benefit of hiding fields users don’t need in a GraphQL schema?
ASimplifies the API for users
BIncreases server load
CMakes queries slower
DExposes more data
✗ Incorrect
Showing only relevant fields makes the API easier to understand and use.
Does schema visibility control replace the need for authentication?
AYes, it replaces authentication
BNo, it complements authentication
COnly for public APIs
DOnly for internal APIs
✗ Incorrect
Schema visibility control works together with authentication to secure data access.
Explain how schema visibility control helps protect sensitive data in a GraphQL API.
Think about who can see what data and how to control it.
You got /4 concepts.
Describe methods to implement schema visibility control in GraphQL.
Consider both code and schema design approaches.
You got /4 concepts.
Practice
(1/5)
1. What is the main purpose of schema visibility control in GraphQL?
easy
A. To limit what parts of the schema users can see or access
B. To speed up query execution by caching results
C. To automatically generate schema documentation
D. To convert GraphQL queries into SQL queries
Solution
Step 1: Understand schema visibility control concept
Schema visibility control is about restricting access to parts of the GraphQL schema based on user roles or permissions.
Step 2: Identify the main goal
The goal is to protect sensitive data and tailor the API by limiting what users can see or use.
Final Answer:
To limit what parts of the schema users can see or access -> Option A
Quick Check:
Schema visibility control = limit schema access [OK]
Hint: Focus on access limits, not performance or docs [OK]
Common Mistakes:
Confusing visibility control with caching
Thinking it auto-generates docs
Assuming it converts queries to SQL
2. Which of the following is a correct way to hide a field in a GraphQL schema using a directive?
easy
A. @deprecated(reason: "hidden") on the field
B. @private on the query operation
C. @skip(if: false) on the schema type
D. @hide(if: true) on the field definition
Solution
Step 1: Understand directive usage for visibility
Directives like @hide(if: true) can be used on fields to conditionally hide them based on logic.
Step 2: Evaluate options
@private is not a standard directive; @skip(if: false) means do not skip (show field); @deprecated marks fields as deprecated but does not hide them.
Final Answer:
@hide(if: true) on the field definition -> Option D
Quick Check:
Use conditional directives like @hide to control visibility [OK]
Hint: Look for conditional directive on field, not operation [OK]
Common Mistakes:
Using @deprecated to hide fields
Applying directives on queries instead of fields
Misunderstanding @skip logic
3. Given this schema snippet with a visibility directive:
type User { id: ID! email: String @hide(if: $isGuest) name: String }
What fields will a guest user see if $isGuest is true?
medium
A. id and name only
B. id, email, and name
C. email and name only
D. id and email only
Solution
Step 1: Analyze the directive condition
The @hide(if: $isGuest) directive hides the email field when $isGuest is true.
Step 2: Determine visible fields for guest
Since $isGuest is true, email is hidden. The visible fields are id and name.
Final Answer:
id and name only -> Option A
Quick Check:
@hide(if: true) hides field = id and name visible [OK]
Hint: True condition hides field, so exclude it [OK]
Common Mistakes:
Including hidden fields in output
Confusing @hide with @skip
Ignoring variable values in directives
4. You wrote this directive to hide a field:
email: String @hide(if: isGuest)
But the field is always visible. What is the likely error?
medium
A. Using @hide on a field is not supported
B. Missing $ before variable name in directive condition
C. The field type String cannot have directives
D. The directive should be @skip, not @hide
Solution
Step 1: Check variable usage in directive
GraphQL variables in directives must be prefixed with $. Here, isGuest is missing $.
Step 2: Understand impact of missing $
Without $, the directive condition is invalid or always false, so the field is never hidden.
Final Answer:
Missing $ before variable name in directive condition -> Option B
Quick Check:
Variables need $ prefix in directives [OK]
Hint: Always prefix variables with $ in directives [OK]
Common Mistakes:
Forgetting $ before variable in directive
Assuming @hide is unsupported
Thinking directives can't be on scalar fields
5. You want to create a GraphQL API that shows users' email only to admins and hides it from regular users. Which approach best implements this schema visibility control?
hard
A. Return null for email in resolver for regular users without schema changes
B. Remove the email field from the schema entirely
C. Use @hide(if: $isNotAdmin) on the email field and pass $isNotAdmin from server context
D. Use @deprecated directive on email field for regular users
Solution
Step 1: Identify requirement for conditional visibility
The email field should be visible only to admins, so visibility depends on user role.
Step 2: Evaluate options for controlling visibility
Use a directive like @hide(if: $isNotAdmin) on the email field and pass $isNotAdmin from server context. This uses a directive with a variable from server context to hide email for non-admins, which is the correct schema visibility control method.
Step 3: Understand why other options fail
Removing the field removes it for all users; @deprecated only marks as outdated; returning null hides data but not schema field.
Final Answer:
Use @hide(if: $isNotAdmin) on the email field and pass $isNotAdmin from server context -> Option C
Quick Check:
Use conditional directives with server variables for visibility [OK]
Hint: Use directives with server variables for role-based hiding [OK]
Common Mistakes:
Removing fields instead of hiding conditionally
Using @deprecated to hide fields
Returning null but not hiding schema field
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.