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?
Focus on the exact field names defined in the GraphQL schema for the REST API data.
The GraphQL query must match the schema fields exactly. The field users returns the list, and name and email are valid fields. Option A correctly queries these fields.
In GraphQL, what is the main role of a resolver function when integrating an external data source like a database or REST API?
Think about what happens when a GraphQL query asks for data.
Resolvers are functions that run when a field is requested in a query. They fetch and return the data from the connected data source.
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
}Consider what is needed to connect the schema to the data source properly.
The schema is correct, but to integrate with a SQL database, you must provide a resolver function for getUser that takes the id argument and returns the matching User. Other options either break the schema or do not fix the integration.
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?
Think about reducing the number of calls to the database.
Batching requests reduces the number of calls by fetching all needed orders in one query, improving performance. Caching indefinitely may cause stale data, removing data reduces functionality, and parallel calls still cause many requests.
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?
Check how each field gets its data from the database.
If other fields return correctly but price is always null, it usually means the resolver for price is missing or incorrectly implemented. The schema and query include price, and the database has the field, so the resolver is the issue.