Given the following schema snippet:
interface Node {
id: ID!
}
type User implements Node {
id: ID!
username: String!
}
type Post implements Node {
id: ID!
title: String!
}
query {
node(id: "1") {
id
... on User {
username
}
... on Post {
title
}
}
}Assuming the node with id "1" is a User with username "alice", what is the query result?
Remember the ... on Type syntax fetches fields only if the node matches that type.
The query asks for a node with id "1". Since it is a User, the username field is returned along with id. The title field is only for Posts, so it is not included.
Choose the best description of the Node interface pattern.
Think about why many types share an id field and how clients fetch objects globally.
The Node interface pattern provides a common id field for all types, allowing clients to fetch any object by its global ID using a single query field.
Find the syntax error in the following schema:
interface Node {
id: ID!
}
type Comment implements Node {
id: ID!
text: String!
}
type Query {
node(id: ID!): Node
}Check the argument type syntax for fields in GraphQL schema.
The argument type 'ID!' is correctly used to indicate a non-null ID. No syntax error exists in the snippet.
You want to fetch multiple nodes by their IDs in one query using the Node interface. Which approach is best for performance and clarity?
Think about batching requests to reduce network overhead.
Creating a query field that accepts a list of IDs and returns a list of Nodes allows fetching multiple nodes in one request efficiently.
Given this query:
query {
node(id: "5") {
id
... on User {
username
}
}
}And the schema has a User with id "5", but the query returns {"data": {"node": null}}. What is the most likely cause?
Check the server-side resolver logic for the 'node' field.
If the resolver does not find or return the object for the given ID, the query returns null for 'node'. This is the most common cause.