Instant GraphQL APIs on DuckDB

Have you ever wanted to query Parquet files with Hasura? Been feeling blue because you can’t write Hasura-flavored GraphQL to query your pandas and polar dataframes? Have you found yourself wishing you could wrangle data from your CSV files with GraphQL?

If so, it’s your lucky day, because today we are excited to bring you instant GraphQL APIs on top of DuckDB with the Hasura DuckDB connector.

To try it out, get started with Hasura DDN here. The steps for working with the DuckDB connector can be found in this GitHub repository.

What can the Hasura DuckDB connector do?

The Hasura DuckDB connector can connect to a local DuckDB database or a MotherDuck-hosted DuckDB database, introspect the underlying data, and expose a GraphQL query layer for the database.

What capabilities does the Hasura DuckDB connector have?

The Hasura DuckDB connector comes with a handful of capabilities out of the box, with even more coming soon! Here’s an overview of some queries you can currently run with the Hasura DuckDB connector.

Simple queries:

query Query {
  duckdb_chinookMainAlbum {
    albumId
    artistId
    title
  }
}

Queries with predicates:

query Query {
  simple_predicate: duckdb_chinookMainAlbum(where: {albumId: {_eq: 10}}) {
    albumId
    artistId
    title
  }
  and_predicate: duckdb_chinookMainAlbum(
    where: {_and: [{albumId: {_gt: 1}}, {albumId: {_lte: 2}}]}
  ) {
    albumId
    artistId
    title
  }
}

Queries with ordering and pagination:

query Query {
  order_by: duckdb_chinookMainAlbum(order_by: {albumId: Desc}) {
    albumId
    artistId
    title
  }
  paginate: duckdb_chinookMainAlbum(offset: 10, limit: 10) {
    albumId
    artistId
    title
  }
}

Queries with a combination of predicates, ordering, and pagination:

query Query {
  complex_query: duckdb_chinookMainAlbum(
    limit: 10
    offset: 10
    order_by: {albumId: Desc}
    where: {_or: [{albumId: {_lt: 10}}, {albumId: {_gt: 20}}]}
  ) {
    albumId
    artistId
    title
  }
}

The connector also supports querying with relationships:

query Query {
  relationship_query: duckdb_chinookMainAlbum {
    albumId
    title
    artist {
      artistId
      name
    }
    tracks {
      trackId
      name
    }
  }
}

Queries across relationships can utilize predicates, ordering, and pagination:

query Query {
  relationship_filter_query: duckdb_chinookMainAlbum {
    albumId
    title
    tracks(
      limit: 10
      order_by: {trackId: Desc}
      where: {name: {_like: "%Spellbound%"}}
    ) {
      trackId
      name
    }
  }
}

Queries can also filter across a relationship:

query Query {
  relationship_predicate_query: duckdb_chinookMainAlbum(
    where: {tracks: {name: {_like: "%Spellbound%"}}}
  ) {
    albumId
    title
    tracks {
      trackId
      name
    }
  }
}

Conclusion

The Hasura DuckDB connector is a game-changer for anyone looking to leverage the power of GraphQL for their data stored in DuckDB databases. Whether you are dealing with local DuckDB instances or databases hosted on MotherDuck, this connector provides a seamless and efficient way to expose your data through GraphQL queries.

At Hasura, we’re constantly adding new connectors and upgrading existing ones. Stay tuned because additional capabilities, such as performing aggregations and grouping, will be coming to the DuckDB connector.

To try out the DuckDB connector, first start with Hasura DDN here. The steps for working with the DuckDB connector can be found in this GitHub repository.

Blog
03 Jul, 2024
Email
Subscribe to stay up-to-date on all things Hasura. One newsletter, once a month.
Loading...
v3-pattern
Accelerate development and data access with radically reduced complexity.