Sign inSign up

iromu/graphql-trino

By iromu

โ€ขUpdated over 1 year ago

Image
0

1.6K

iromu/graphql-trino repository overview

โ Trino GraphQL

Apache License 2 Build Status Sonar Coverage Quality Gate Status Maven Central Maven metadata URL OpenSSF Scorecard

A Spring Boot application that dynamically generates a GraphQL schema from Trino catalogs, schemas, and tables. It allows users to explore and query Trino data sources using GraphQL without manually writing schema definitions.

Diagram

โ ๐Ÿš€ Features

  • Dynamic GraphQL Schema: Automatically scans Trino catalogs, schemas, and tables and exposes them as GraphQL queries.
  • Auto-detect Columns: Generates GraphQL object types from Trino table column metadata.
  • Filter Support: Query data with dynamic filters using GraphQL input arguments.
  • Streamed Results: Efficient streaming of query results from Trino using JDBC.
  • GraphiQL Interface: Visual GraphQL playground is exposed at the root URL / for easy testing and exploration.
  • Export Schema: Exposes a REST endpoint to download the auto-generated GraphQL schema in SDL format.

โ ๐Ÿง  How It Works

  1. On startup, the app connects to Trino via JDBC.
  2. It fetches available catalogs, schemas, tables, and columns.
  3. GraphQL schema is dynamically generated using this metadata.
  4. Each table is exposed as a top-level query.
  5. Query fields support filters using a generic FilterInput object.
  6. Queries return streamed Map<String, Object> rows to minimize memory usage.

โ ๐Ÿ”ง Configuration

Set up your connection to Trino in application.yml or application.properties:

spring:
  datasource:
    url: jdbc:trino://localhost:8080
    username: your-trino-user
    driver-class-name: io.trino.jdbc.TrinoDriver

โ โš™๏ธ Application Configuration (app.*)

The application supports flexible configuration via application.yml or application.properties, using the app prefix. These properties control how GraphQL schemas are generated from Trino catalogs.

โ Available Configuration Options
PropertyDefault ValueDescription
app.schema-folder/etc/schemaFilesystem path where the fetched Trino schemas will be stored.
app.replace-objects-name-charactersfalseWhether to automatically replace invalid characters in GraphQL object names.
app.ignore-objects-with-wrong-characterstrueIf true, skips any object whose name contains invalid GraphQL characters.
app.ignore-cachefalseDisables caching if set to true. Schema metadata will be reloaded on every run.
app.include-catalogsemptyA list of catalogs to include explicitly in the schema generation process. If empty, all catalogs are considered (except those excluded).
app.exclude-catalogs["system"]Catalogs to exclude from processing. Useful for avoiding system/internal catalogs.
app.exclude-schemas["information_schema"]Schemas to ignore across any catalog. Prevents processing metadata tables.
โ Example (application.yml)
app:
  schema-folder: /tmp/schema
  replace-objects-name-characters: true
  ignore-objects-with-wrong-characters: false
  ignore-cache: true
  include-catalogs:
    - my_catalog
  exclude-catalogs:
    - system
  exclude-schemas:
    - information_schema
    - pg_catalog
โ ๐Ÿณ Overriding Configuration via Docker Environment Variables

Spring Boot automatically maps environment variables to configuration properties using a relaxed binding system. This means all the app.* properties can be overridden via Docker environment variables using the following rules:

  • Dots (.) in property names become underscores (_)
  • Everything is uppercased
  • Prefix with APP_ for properties under app
โ ๐Ÿงช Example Mappings
Property NameEnvironment Variable
app.schema-folderAPP_SCHEMA_FOLDER
app.replace-objects-name-charactersAPP_REPLACE_OBJECTS_NAME_CHARACTERS
app.ignore-objects-with-wrong-charactersAPP_IGNORE_OBJECTS_WITH_WRONG_CHARACTERS
app.ignore-cacheAPP_IGNORE_CACHE
app.include-catalogs[0]APP_INCLUDE_CATALOGS_0
app.exclude-catalogs[0]APP_EXCLUDE_CATALOGS_0
app.exclude-schemas[1]APP_EXCLUDE_SCHEMAS_1

โœ… Arrays/lists are supported by indexing: APP_INCLUDE_CATALOGS_0, APP_INCLUDE_CATALOGS_1, etc.


โ ๐Ÿณ Docker environment Example (in docker-compose.yml)
services:
  graphql-trino:
    image: iromu/graphql-trino:latest
    environment:
      - APP_SCHEMA_FOLDER=/tmp/schema
      - APP_REPLACE_OBJECTS_NAME_CHARACTERS=true
      - APP_IGNORE_OBJECTS_WITH_WRONG_CHARACTERS=false
      - APP_IGNORE_CACHE=true
      - APP_INCLUDE_CATALOGS_0=my_catalog
      - APP_EXCLUDE_CATALOGS_0=system
      - APP_EXCLUDE_SCHEMAS_0=information_schema
      - APP_EXCLUDE_SCHEMAS_1=pg_catalog

โ ๐Ÿงช Example GraphQL Query

query {
    my_table(limit: 10, filters: [
        { field: "age", operator: "gt", intValue: 30 },
        { field: "name", operator: "like", stringValue: "Ali" }
    ]) {
        id
        name
        age
    }
}

Tag summary

Content type

Image

Digest

sha256:47c0d9f0bโ€ฆ

Size

157.2 MB

Last updated

over 1 year ago

docker pull iromu/graphql-trino