0
0
GraphQLquery~10 mins

Federated authentication in GraphQL - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to specify the authentication provider in the GraphQL schema directive.

GraphQL
type Query @auth(provider: "[1]") { user: User }
Drag options to blanks, or click blank then click option'
Atwitter
Bfacebook
Clocal
Dgoogle
Attempts:
3 left
💡 Hint
Common Mistakes
Using a provider name that is not supported or misspelled.
Confusing local authentication with federated providers.
2fill in blank
medium

Complete the code to request the user's email from the federated authentication token.

GraphQL
query getUser { user(email: [1]) { id name } }
Drag options to blanks, or click blank then click option'
A"auth.email"
B"token.email"
C"context.email"
D"user.email"
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect variable names that do not exist in the query context.
Assuming the email is directly under 'user' or 'token' without context.
3fill in blank
hard

Fix the error in the authentication directive by completing the missing argument.

GraphQL
type Mutation @auth([1]: "github") { updateUser(name: String): User }
Drag options to blanks, or click blank then click option'
Aprovider
Btoken
Cscope
Drole
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'token' or 'scope' which are not valid directive arguments here.
Omitting the argument name entirely.
4fill in blank
hard

Fill both blanks to complete the federated authentication header and token extraction.

GraphQL
headers: { Authorization: "Bearer [1]" }, context: { user: [2] }
Drag options to blanks, or click blank then click option'
Aaccess_token
BauthToken
Ctoken
DuserToken
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up token variable names causing authentication failure.
Using incorrect header formats.
5fill in blank
hard

Fill all three blanks to complete the federated authentication resolver with token validation and user extraction.

GraphQL
resolve(parent, args, context) { const [1] = context.headers["[2]"];
 if (![1]) throw new Error("No token");
 return getUserFromToken([1]); }
Drag options to blanks, or click blank then click option'
AauthToken
BAuthorization
Ctoken
DaccessToken
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase 'authorization' which may cause header lookup failure.
Using different variable names for token extraction and usage.