0
0
GraphQLquery~20 mins

Federated authentication in GraphQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Federated Authentication Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
What is the main purpose of federated authentication?
Choose the best description of federated authentication.
AIt stores all user passwords in a single database for easy access.
BIt encrypts user data locally on their device before sending it to the server.
CIt requires users to create new accounts for every service they use.
DIt allows users to log in using credentials from multiple trusted identity providers.
Attempts:
2 left
💡 Hint
Think about how users can use one login for many services.
query_result
intermediate
2:00remaining
What is the output of this GraphQL query for federated user info?
Given this GraphQL query requesting user email and provider, what is the expected JSON response?
GraphQL
query {
  user(id: "123") {
    email
    authProvider
  }
}
A{ "data": { "user": { "email": "user@example.com", "authProvider": "Google" } } }
B{ "data": { "user": { "email": null, "authProvider": null } } }
C{ "error": "User not found" }
D{ "data": { "user": { "email": "user@example.com" } } }
Attempts:
2 left
💡 Hint
The user exists and uses Google as their login provider.
📝 Syntax
advanced
2:00remaining
Which GraphQL schema snippet correctly defines a federated user type with an external key?
Select the valid GraphQL SDL code that defines a federated User type with an external key.
A
type User @key(fields: "id") {
  id: ID!
  email: String
  authProvider: String
}
B
type User @external(fields: "id") {
  id: ID!
  email: String
  authProvider: String
}
C
type User @key(fields: id) {
  id: ID!
  email: String
  authProvider: String
}
D
type User @key(fields: "id") {
  id: ID
  email: String
  authProvider: String
}
Attempts:
2 left
💡 Hint
The @key directive requires quoted field names and non-null id.
optimization
advanced
2:00remaining
How to optimize federated GraphQL queries to reduce data fetching overhead?
Which approach best reduces unnecessary data fetching in a federated GraphQL service?
AFetch all fields from every service regardless of query to cache data.
BDisable query batching to send each request separately for clarity.
CUse @requires directive to specify dependent fields and avoid fetching unrelated data.
DUse multiple nested queries to fetch data from each service independently.
Attempts:
2 left
💡 Hint
Think about how to tell the gateway what fields are needed for resolving.
🔧 Debug
expert
3:00remaining
Why does this federated GraphQL query fail with a 'Cannot query field' error?
Given this query: query { user(id: "123") { id email profilePicture } } And the User type schema: type User @key(fields: "id") { id: ID! email: String } Why does querying profilePicture cause an error?
AThe id field is missing from the query, causing the error.
BThe profilePicture field is not defined in the User type schema, so it cannot be queried.
CThe @key directive is incorrectly used and causes all fields to be inaccessible.
DThe user id "123" does not exist, so no fields can be queried.
Attempts:
2 left
💡 Hint
Check if the requested field exists in the schema.