0
0
GraphQLquery~5 mins

Interface types in GraphQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is an interface type in GraphQL?
An interface type in GraphQL is a way to define a set of fields that multiple object types can share. It acts like a contract that those object types must follow.
Click to reveal answer
beginner
How do you declare an interface type in GraphQL schema?
You use the interface keyword followed by the interface name and the fields it contains. For example:<br>
interface Character {<br>  id: ID!<br>  name: String!<br>}
Click to reveal answer
beginner
How does an object type implement an interface in GraphQL?
An object type implements an interface by using the implements keyword and including all fields defined in the interface. For example:<br>
type Human implements Character {<br>  id: ID!<br>  name: String!<br>  homePlanet: String<br>}
Click to reveal answer
intermediate
Why use interface types in GraphQL?
Interfaces help to reuse common fields across different object types and allow queries to be more flexible by returning different types that share the same interface.
Click to reveal answer
intermediate
Can you query an interface type directly in GraphQL?
Yes, you can query an interface type, but you must specify which fields you want from the interface and also use inline fragments to get fields specific to the implementing object types.
Click to reveal answer
What keyword is used to define an interface type in GraphQL?
Ainterface
Btype
Cimplements
Dunion
If an object type implements an interface, what must it do?
AIgnore the interface fields
BOnly include some fields from the interface
CInclude all fields defined in the interface
DRename the interface fields
Which of the following is true about querying interfaces?
AInterfaces are only used for mutations
BYou cannot query interfaces directly
CYou can query an interface and get fields from all implementing types without specifying them
DYou can query an interface but need inline fragments to get fields from specific types
What is a main benefit of using interface types in GraphQL?
AThey allow reuse of common fields across types
BThey speed up database queries
CThey replace unions
DThey prevent any type from having unique fields
Which keyword does an object type use to show it follows an interface?
Ainherits
Bimplements
Cextends
Duses
Explain what an interface type is in GraphQL and why it is useful.
Think about how different characters in a story might share common traits.
You got /3 concepts.
    Describe how you would query data from an interface type and its implementing object types.
    Remember you need to ask for common fields and then specify extra fields for each type.
    You got /3 concepts.