Query Language Fields, aliases, variables, fragments, directives, search, JSON paths, and expressions. core reference core/query-language core/query-language.md

Query Language

Fields, aliases, variables, fragments, directives, search, JSON paths, and expressions.

Basic selection

GraphQL
query {
  products(limit: 3, order_by: { id: asc }) {
    id
    name
    owner {
      id
      fullName: full_name
    }
  }
}
Verified by Example_query tests/query_test.go:18

Primary-key lookup and object shape

GraphQL
query Product($id: ID!) {
  products(id: $id) {
    id
    name
    owner {
      email
    }
  }
}
JSON
{ "id": 2 }

Primary-key lookup returns a single object. Collection queries return arrays.

Verified by Example_queryByID tests/query_test.go:558

Variables and defaults

GraphQL
query Products($limit: Int = 5) {
  products(limit: $limit, order_by: { id: asc }) {
    id
    name
  }
}
Verified by Example_queryWithVariablesDefaultValue tests/query_test.go:942

Use variables for values, not for whole query structures. In filters, keep the filter object inline and place variables at leaf values.

Fragments

GraphQL
fragment userFields on users {
  id
  email
}

query {
  users {
    ...userFields
  }
}
Verified by Example_queryWithFragments1 tests/query_test.go:1004

Aliases

Aliases are useful when the database column name is not the public field name you want to expose.

GraphQL
query {
  users {
    id
    fullName: full_name
  }
}
Verified by Example_queryWithAlternateFieldNames tests/query_test.go:532

Directives

GraphJin supports GraphQL-style conditional fields plus GraphJin-specific add/remove directives for dynamic response shaping.

GraphQL
query ($showProducts: Boolean!) {
  users {
    id
    products @include(if: $showProducts) {
      id
    }
  }
}
Verified by Example_queryWithSkipAndIncludeDirective1 tests/query_test.go:1192

GraphJin 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.

GraphQL
query {
  products(where: { id: { lteq: 100 } }) {
    doubled: sum(expr: { mul: [id, 2] })
  }
}
Verified by Example_queryWithExprMul tests/query_test.go:2390
GraphQL
query {
  products(limit: 10, order_by: { id: asc }, where: { metadata_foo: { eq: true } }) {
    id
    metadata_foo
  }
}
GraphQL
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.

Verified by Example_queryJSONPathOperationsAlternativeSyntax tests/query_test.go:129
Verified by Example_queryBySearch tests/query_test.go:586

Docs