Given a GraphQL query requesting name and price fields of products, and a cost model where name costs 1 unit and price costs 3 units per item, what is the total cost for 5 products?
query {
products {
name
price
}
}Multiply the cost per field by the number of products and sum.
Each product requests two fields: name (1 unit) and price (3 units). Total per product is 4 units. For 5 products, total cost is 4 * 5 = 20 units.
In a GraphQL query, a user has a nested posts field. If user fields cost 2 units each and posts fields cost 1 unit each, which factor most increases total cost?
Think about how nested lists multiply cost.
More posts per user multiply the cost of posts fields by the number of posts, increasing total cost significantly.
Which option contains a syntax error in applying a cost directive to a GraphQL field?
type Query {
products: [Product] @cost(multipliers: ["first"])
}
type Product {
name: String @cost(value: 1)
price: Float @cost(value: 2)
}Check the syntax for directive arguments in GraphQL.
GraphQL directive arguments use colon :, not equals =. Option A uses =, causing syntax error.
You have a query requesting id, name, description, and price fields for 10 products. Costs per field are: id = 1, name = 2, description = 5, price = 3. Which option reduces total cost the most while keeping id and price?
Calculate cost savings for each removal.
Removing name and description saves (2 + 5) * 10 = 70 units, more than removing name only (20 units) or description only (50 units). Removing price is not allowed.
A query requests users with nested posts and comments. Each user has 3 posts, each post has 4 comments. Costs: user fields = 2 units each, post fields = 1 unit each, comment fields = 0.5 units each. The query requests 2 fields per user, 3 fields per post, and 2 fields per comment. Why is the total cost unexpectedly high?
Consider how nested lists multiply total cost.
The total cost multiplies the number of fields by the count of nested items. With 3 posts per user and 4 comments per post, the comment fields multiply by 3 * 4 = 12 per user, increasing cost significantly.