What if you could fetch any item with one simple query, no matter its type?
Why Node interface pattern in GraphQL? - Purpose & Use Cases
Imagine you have many different types of items in your app, like books, movies, and songs. You want to find any item by its ID, but each type stores IDs differently and has its own way to fetch data.
Manually writing separate queries for each type is slow and confusing. You have to remember which query to use for which type, and it's easy to make mistakes or miss some items.
The Node interface pattern gives all items a common way to be fetched by a single ID. This means you can ask for any item with one simple query, and the system figures out the right type and data for you.
query { book(id: "1") { title } movie(id: "1") { title } }query { node(id: "1") { id ... on Book { title } ... on Movie { title } } }This pattern lets you fetch any object by ID in one place, making your queries simpler and your app easier to build and maintain.
Think of a library app where you want to search for any item by its barcode. Instead of searching separately in books, movies, or songs, you scan once and get the right item instantly.
Manually fetching different types by ID is complicated and error-prone.
The Node interface pattern unifies fetching by providing a single entry point.
This makes queries simpler and apps more flexible and maintainable.