Complete the code to define an interface named Character.
interface Character [1] {
id: ID!
name: String!
}The keyword interface is used to define an interface in GraphQL.
Complete the code to make Human implement the Character interface.
type Human [1] Character {
id: ID!
name: String!
totalCredits: Int
}The implements keyword is used for a type to implement an interface in GraphQL.
Fix the error in the fragment to specify the correct type condition.
fragment characterDetails on [1] {
id
name
}Fragments on abstract types like interfaces use the interface name as the type condition.
Fill both blanks to define a union type SearchResult that includes Human and Droid.
union SearchResult = [1] | [2]
Union types list the possible types separated by |. Here, Human and Droid are included.
Fill all three blanks to write a query that fetches a character by ID and returns fields based on the concrete type.
query getCharacter($id: ID!) {
character(id: $id) {
id
name
... on [1] {
[2]
}
... on [3] {
primaryFunction
}
}
}The query uses inline fragments to fetch fields specific to Human and Droid types. Human has totalCredits, Droid has primaryFunction.