Cannot query field "username" on type "User"
The field doesnβt exist in the GraphQL schema.
Fix 1: Check the schema
# Check what fields are available
type User {
id: ID!
name: String! # β It's "name", not "username"
email: String!
}
Fix 2: Fix the query
# β Wrong field name
query {
user(id: "1") {
username
}
}
# β
Use the correct field
query {
user(id: "1") {
name
}
}
Fix 3: Use introspection
{
__type(name: "User") {
fields {
name
type { name }
}
}
}
Related: REST vs. GraphQL β Which API Style Should You Use?