0
0
GraphQLquery~20 mins

Data source integration in GraphQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
πŸŽ–οΈ
Data Source Integration Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate
2:00remaining
Querying a REST API data source

You have a GraphQL server that integrates a REST API providing user data. The REST API returns a list of users with fields id, name, and email. Which GraphQL query will correctly fetch the name and email of all users?

A{ users { name email } }
B{ users { id name email } }
C{ users { username email } }
D{ userList { name email } }
Attempts:
2 left
πŸ’‘ Hint

Focus on the exact field names defined in the GraphQL schema for the REST API data.

🧠 Conceptual
intermediate
1:30remaining
Understanding GraphQL data source resolvers

In GraphQL, what is the main role of a resolver function when integrating an external data source like a database or REST API?

AIt defines the schema types and fields for the data source.
BIt fetches and returns the data for a specific field when queried.
CIt validates the GraphQL query syntax before execution.
DIt caches the entire data source to improve performance.
Attempts:
2 left
πŸ’‘ Hint

Think about what happens when a GraphQL query asks for data.

πŸ“ Syntax
advanced
2:30remaining
Fixing a GraphQL schema integration error

Given this GraphQL schema snippet integrating a SQL database, which option correctly fixes the syntax error?

type Query {
getUser(id: ID!): User
}

type User {
id: ID!
name: String
email: String
}
AAdd a resolver for getUser that accepts an argument and returns a User object.
BRemove the exclamation mark from <code>ID!</code> to make it optional.
CChange <code>getUser(id: ID!)</code> to <code>getUser: User</code> without arguments.
DRename the type <code>User</code> to <code>Users</code> to match the database table.
Attempts:
2 left
πŸ’‘ Hint

Consider what is needed to connect the schema to the data source properly.

❓ optimization
advanced
3:00remaining
Optimizing GraphQL data fetching from multiple sources

You have a GraphQL query that fetches user info from a REST API and order info from a SQL database. The current implementation makes separate calls for each user to fetch their orders, causing slow response times. What is the best optimization approach?

ARemove the order info from the query to speed up the response.
BUse multiple parallel calls for each user’s orders without batching.
CCache the REST API responses indefinitely to avoid repeated calls.
DBatch the order requests by collecting all user IDs and fetching orders in a single query.
Attempts:
2 left
πŸ’‘ Hint

Think about reducing the number of calls to the database.

πŸ”§ Debug
expert
3:00remaining
Debugging a GraphQL data source integration error

A GraphQL query to fetch products from a MongoDB data source returns null for the price field, but other fields like name and category return correctly. What is the most likely cause?

AThe GraphQL schema does not define the <code>price</code> field in the <code>Product</code> type.
BThe MongoDB collection does not contain the <code>price</code> field in documents.
CThe resolver for <code>price</code> is missing or returns <code>null</code>.
DThe query is missing the <code>price</code> field in the selection set.
Attempts:
2 left
πŸ’‘ Hint

Check how each field gets its data from the database.