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?
✗ Incorrect
The
interface keyword is used to define an interface type in GraphQL.If an object type implements an interface, what must it do?
✗ Incorrect
An object type must include all fields defined in the interface it implements.
Which of the following is true about querying interfaces?
✗ Incorrect
When querying an interface, you specify interface fields and use inline fragments to get fields from specific implementing types.
What is a main benefit of using interface types in GraphQL?
✗ Incorrect
Interfaces allow reuse of common fields across different object types.
Which keyword does an object type use to show it follows an interface?
✗ Incorrect
The
implements keyword is used by object types to indicate they follow an interface.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.