What does JWT stand for and what is its main purpose?
JWT stands for JSON Web Token. Its main purpose is to securely transmit information between parties as a JSON object, often used for authentication.
Click to reveal answer
beginner
How is a JWT typically structured?
A JWT has three parts separated by dots: Header, Payload, and Signature. The Header describes the token type and algorithm, the Payload contains claims, and the Signature verifies the token's integrity.
Click to reveal answer
beginner
In GraphQL, where is the JWT usually sent from the client to the server?
The JWT is usually sent in the HTTP Authorization header as a Bearer token when making GraphQL requests.
Click to reveal answer
intermediate
What is the role of the JWT signature in integration?
The signature ensures the token was not altered and verifies the sender's identity by using a secret or public/private key pair.
Click to reveal answer
intermediate
How can you verify a JWT in a GraphQL server resolver?
You decode the JWT from the Authorization header, verify its signature and expiration, then use the decoded data (like user ID) to control access or fetch user info.
Click to reveal answer
What part of a JWT contains the user information or claims?
APayload
BHeader
CSignature
DToken type
✗ Incorrect
The Payload contains the claims or user information in a JWT.
How is a JWT usually sent in a GraphQL request?
AIn the HTTP Authorization header
BIn the query string
CAs a cookie only
DIn the response body
✗ Incorrect
JWTs are typically sent in the HTTP Authorization header as Bearer tokens.
What does the JWT signature protect against?
AToken expiration
BToken size limits
CToken encoding
DToken tampering
✗ Incorrect
The signature ensures the token has not been tampered with.
Which algorithm is commonly used to sign JWTs?
ASHA-256
BRSA or HMAC
CMD5
DAES
✗ Incorrect
JWTs are commonly signed using RSA or HMAC algorithms.
What should a GraphQL server do if a JWT is expired?
AAccept the token anyway
BRefresh the token automatically
CReject the request and ask for re-authentication
DIgnore expiration and continue
✗ Incorrect
Expired JWTs should be rejected and the user asked to re-authenticate.
Explain how JWT integration works in a GraphQL API from client request to server verification.
Think about the steps from sending the token to checking it on the server.
You got /4 concepts.
Describe the structure of a JWT and the role of each part in security.
Consider how each part helps keep the token safe and trustworthy.
You got /3 concepts.
Practice
(1/5)
1. What is the main purpose of using JWT in GraphQL database integration?
easy
A. To store large amounts of data
B. To speed up database queries
C. To verify the user's identity and secure database access
D. To format the GraphQL schema
Solution
Step 1: Understand JWT role in security
JWT (JSON Web Token) is used to confirm who the user is by verifying their identity.
Step 2: Connect JWT to database access
This verification controls who can access or change data in the GraphQL database.
Final Answer:
To verify the user's identity and secure database access -> Option C
Quick Check:
JWT secures access [OK]
Hint: JWT = user identity check for secure access [OK]
Common Mistakes:
Thinking JWT speeds up queries
Confusing JWT with data storage
Assuming JWT changes schema format
2. Which is the correct way to send a JWT token in a GraphQL request header?
easy
A. Token: Authorization <token>
B. Authorization: Token <token>
C. Auth: Bearer <token>
D. Authorization: Bearer <token>
Solution
Step 1: Recall standard JWT header format
The JWT token is sent in the HTTP header named 'Authorization' with the prefix 'Bearer'.
Step 2: Match the correct header syntax
The correct syntax is 'Authorization: Bearer <token>'. Other options use wrong header names or order.
const user = verifyToken(context.headers.authorization);
if (!user) return null;
return db.getUserData(user.id);
What happens if the token is invalid or missing?
medium
A. The resolver returns null and no data is fetched
B. The resolver throws a syntax error
C. The resolver returns all user data without restriction
D. The resolver crashes the server
Solution
Step 1: Analyze token verification
The function verifyToken returns null or false if the token is invalid or missing.
Step 2: Check resolver behavior on invalid token
If user is falsy, the resolver returns null, meaning no data is sent back.
Final Answer:
The resolver returns null and no data is fetched -> Option A
Quick Check:
Invalid token leads to null return [OK]
Hint: Invalid token means no user, so resolver returns null [OK]
Common Mistakes:
Expecting a syntax error on invalid token
Assuming data is returned without user
Thinking server crashes on bad token
4. Identify the error in this JWT integration snippet:
const token = context.headers.Authorization;
const user = verifyToken(token);
if (!user) throw new Error('Unauthorized');
return db.getUserData(user.id);
medium
A. verifyToken should be called with context.token, not token
B. Header name should be lowercase 'authorization', not 'Authorization'
C. The error message should be 'Forbidden' instead of 'Unauthorized'
D. db.getUserData should be called before verifying the token
Solution
Step 1: Check header name case sensitivity
HTTP headers in Node.js are usually lowercase, so 'authorization' is correct, not 'Authorization'.
Step 2: Confirm token extraction correctness
Using 'Authorization' may cause token to be undefined, leading to verification failure.
Final Answer:
Header name should be lowercase 'authorization', not 'Authorization' -> Option B
Quick Check:
Header keys are lowercase [OK]
Hint: Use lowercase 'authorization' header key in code [OK]
Common Mistakes:
Using uppercase header keys in Node.js
Calling db before verifying user
Confusing error message types
5. You want to restrict a GraphQL query so only users with role 'admin' can access sensitive data. Which JWT integration approach is best?
hard
A. Verify token, then check if user.role === 'admin' before returning data
B. Return data first, then verify token asynchronously
C. Skip token verification and rely on frontend checks
D. Verify token but ignore user roles for simplicity
Solution
Step 1: Understand role-based access control
To restrict access, verify the token and check the user's role before sending data.
Step 2: Evaluate options for security
Returning data before verification or skipping roles risks exposing sensitive info.
Final Answer:
Verify token, then check if user.role === 'admin' before returning data -> Option A
Quick Check:
Check role after token verification [OK]
Hint: Check user role after verifying JWT token [OK]
Common Mistakes:
Sending data before verifying user
Ignoring roles in backend checks
Trusting frontend for security
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.