First Query
Understand how a GraphQL selection maps to nested database results.
Shape the response
GraphJin treats the database schema as the source of truth. A table becomes a root field, columns become fields, and foreign-key relationships become nested selections.
query {
products(id: $id) {
id
name
owner {
email
}
}
}{ "id": 2 }When you query by primary key, GraphJin returns a single object. When you query a collection, it returns a list.
Example_queryByID
tests/query_test.go:558Primary-key lookup works because GraphJin has discovered the table primary key from the database schema. For composite keys or manually mapped tables, keep table metadata explicit in config so the compiler can still distinguish single-row lookup from collection lookup.
Use aliases
GraphQL aliases let you expose API-friendly names without changing the database:
query {
users {
id
fullName: full_name
}
}Example_queryWithAlternateFieldNames
tests/query_test.go:532Add variables
Variables replace scalar values, not arbitrary GraphQL fragments:
query Products($ownerID: ID!, $limit: Int = 10) {
products(
where: { owner_id: { eq: $ownerID } }
limit: $limit
order_by: { id: asc }
) {
id
name
}
}Example_queryWithVariablesDefaultValue
tests/query_test.go:942Keep order explicit
SQL result order is undefined without order_by. Tests and production clients should ask for deterministic ordering whenever order matters.
query {
products(limit: 5, order_by: { id: asc }) {
id
name
}
}This rule matters across dialects. A result that appears stable on PostgreSQL without order_by is still relying on undefined SQL ordering.