0
0
GraphQLquery~10 mins

Abstract type resolution in GraphQL - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Abstract type resolution
Query with abstract type
Identify abstract type (Interface/Union)
Fetch possible concrete types
For each result item:
Determine actual concrete type
Resolve fields specific to concrete type
Return resolved data to client
This flow shows how GraphQL resolves abstract types by identifying the concrete type of each result and fetching the correct fields.
Execution Sample
GraphQL
query {
  search(text: "cat") {
    ... on Animal {
      name
      sound
    }
    ... on Vehicle {
      model
      wheels
    }
  }
}
This query searches for items that can be either Animal or Vehicle and requests fields based on the actual type.
Execution Table
StepActionAbstract TypeConcrete Type DeterminedFields ResolvedOutput Data
1Receive query with abstract type 'search'search (Union: Animal | Vehicle)N/AN/AN/A
2Fetch results matching 'cat'searchN/AN/A[Item1, Item2]
3Check Item1 typesearchAnimalname, sound{"name": "Cat", "sound": "Meow"}
4Check Item2 typesearchVehiclemodel, wheels{"model": "CatMobile", "wheels": 4}
5Return combined resultssearchAnimal, Vehiclename, sound, model, wheels[{"name": "Cat", "sound": "Meow"}, {"model": "CatMobile", "wheels": 4}]
💡 All items resolved to concrete types and fields returned.
Variable Tracker
VariableStartAfter Step 2After Step 3After Step 4Final
results[][Item1, Item2][Item1, Item2][Item1, Item2][Item1, Item2]
Item1_typeN/AN/AAnimalAnimalAnimal
Item2_typeN/AN/AN/AVehicleVehicle
resolved_fields_Item1N/AN/A{name, sound}{name, sound}{name, sound}
resolved_fields_Item2N/AN/AN/A{model, wheels}{model, wheels}
Key Moments - 2 Insights
How does GraphQL know which concrete type to use for each item?
GraphQL uses the __typename field or type resolver functions to determine the actual concrete type of each item, as shown in execution_table rows 3 and 4.
Why do we need to resolve fields differently for each concrete type?
Because abstract types can represent multiple types with different fields, GraphQL must resolve only the fields valid for the concrete type, as seen in execution_table rows 3 and 4.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what concrete type is determined for Item2 at step 4?
AAnimal
BVehicle
CUnknown
DInterface
💡 Hint
Check the 'Concrete Type Determined' column at step 4 in the execution_table.
At which step does GraphQL return the combined results to the client?
AStep 2
BStep 3
CStep 5
DStep 4
💡 Hint
Look for the step where 'Return combined results' is the action in the execution_table.
If the query requested a field not present on Vehicle, what would happen during resolution?
AGraphQL returns an error for Vehicle items
BGraphQL ignores the field for Vehicle items
CGraphQL returns null for that field on Vehicle items
DGraphQL treats Vehicle as Animal
💡 Hint
Consider how GraphQL enforces field validity per concrete type as shown in the key moments.
Concept Snapshot
Abstract type resolution in GraphQL:
- Abstract types: Interface or Union
- Query requests fields on abstract type
- Server determines concrete type per item
- Resolves only fields valid for that concrete type
- Returns combined results with correct fields
Full Transcript
In GraphQL, abstract type resolution happens when a query requests data from an abstract type like an interface or union. The server fetches all matching items, then for each item, it determines the actual concrete type. Based on this type, it resolves only the fields valid for that type. Finally, it returns the combined results to the client. This ensures the client gets the correct data shape depending on the actual type of each item.