The schema defines the structure of the API by specifying what data types exist and what operations (queries and mutations) clients can perform. This acts like a contract between client and server, ensuring both sides agree on how to communicate.
The schema acts as a guide that tells clients what data they can ask for and helps servers check if the requests are valid before running them. This prevents errors and improves communication.
query IntrospectionQuery {
__schema {
types {
name
kind
}
}
}This query asks the GraphQL server to return all types it knows about and their kinds. This helps clients understand the API structure.
The query asks for a field 'age' which the schema does not define for 'User'. This causes the query to fail validation.
A clear schema lets clients ask for just the data they need. This means less data is sent over the network and the server does less work, improving performance.