Bring Your Own Schema (BYOS) is an implementation based on the concepts presented in my thesis, focusing on transpiling GraphQL queries to SQL. This repository provides a practical example of how to bring your own GraphQL schema and use it to generate efficient SQL queries.
- One SQL query for every root level query.
- GraphQL schema and SQL schema are not generated and do not contain BYOS specific code.
- jOOQ is used to ensure correctness of the SQL configuration.
- Supports filter arguments, pagination and sorting.
The number of results can be restricted by the limit argument.
query { filmByIds(limit: 3) { edges { node { film_id title } } } }The result can be restricted to a condition by the where argument.
query { filmByIds(where: {film_id: {_in: [1,2]}}) { edges { node { film_id title } } } }And with variables { "firstNames": ["ED", "JOE"] }:
query Actors_with_FirstName($firstNames: [String!]!) {
Actor(where: {firstName: { _in: $firstNames} }) {
actorId
firstName
}
}The order of the result can be defined by the orderBy argument.
query { allFilms(orderBy: [{title: asc}]) { edges { node { film_id title } } } }src/main/kotlin/byoscontains the BYOS implementation.src/main/kotlin/examplecontains the exemplary Spring Boot application.src/main/resources/graphqlcontains the GraphQL schema.src/test/kotlin/examplecontains the tests for the example application.
... you will have to have a local psql version of the sakila database with this small addition:
ALTER TABLE category
ADD COLUMN parent_category_id INTEGER;You could also set up your own database by:
- changing the connection of jOOQ (and the language if you do not want to use Postgres).
- using a GraphQL schema matching the SQL schema.
- defining relationships and how to resolve them.
To run the example run the main method in ByosApplication.kt.
After that you can query the GraphQL endpoint at http://localhost:8080 or open the GraphiQL interface at http://localhost:8080/graphiql.
For more details about the approach and implementation, refer to the associated thesis.
Happy querying and transpiling!