Query Language
Fields, aliases, variables, fragments, directives, search, JSON paths, and expressions.
Basic selection
query {
products(limit: 3, order_by: { id: asc }) {
id
name
owner {
id
fullName: full_name
}
}
}Example_query
tests/query_test.go:18Primary-key lookup and object shape
query Product($id: ID!) {
products(id: $id) {
id
name
owner {
email
}
}
}{ "id": 2 }Primary-key lookup returns a single object. Collection queries return arrays.
Example_queryByID
tests/query_test.go:558Variables and defaults
query Products($limit: Int = 5) {
products(limit: $limit, order_by: { id: asc }) {
id
name
}
}Example_queryWithVariablesDefaultValue
tests/query_test.go:942Use variables for values, not for whole query structures. In filters, keep the filter object inline and place variables at leaf values.
Fragments
fragment userFields on users {
id
email
}
query {
users {
...userFields
}
}Example_queryWithFragments1
tests/query_test.go:1004Aliases
Aliases are useful when the database column name is not the public field name you want to expose.
query {
users {
id
fullName: full_name
}
}Example_queryWithAlternateFieldNames
tests/query_test.go:532Directives
GraphJin supports GraphQL-style conditional fields plus GraphJin-specific add/remove directives for dynamic response shaping.
query ($showProducts: Boolean!) {
users {
id
products @include(if: $showProducts) {
id
}
}
}Example_queryWithSkipAndIncludeDirective1
tests/query_test.go:1192GraphJin also supports role and variable variants such as @include(ifRole:), @skip(ifRole:), @include(ifVar:), and @skip(ifVar:), plus relationship directives such as @through(table:) and @through(column:).
Expressions
Expression fields let you compute values from selected columns while staying inside the compiled query path.
query {
products(where: { id: { lteq: 100 } }) {
doubled: sum(expr: { mul: [id, 2] })
}
}Example_queryWithExprMul
tests/query_test.go:2390JSON paths and search
query {
products(limit: 10, order_by: { id: asc }, where: { metadata_foo: { eq: true } }) {
id
metadata_foo
}
}query SearchProducts($query: String!) {
products(search: $query, limit: 5) {
id
name
}
}JSON path shorthand and full-text search are backend-dependent features. Use Database Support when writing portable docs or examples.
Example_queryJSONPathOperationsAlternativeSyntax
tests/query_test.go:129Example_queryBySearch
tests/query_test.go:586