Licensed to be used in conjunction with basebox, only.
Operation Handling
Overview
Operation handling is basically the process of handling requests to the services published by the schema. The Compiler compiles the GraphQL schema provided into a Data Model script that is used to create a new database as well as the necessary configuration needed to handle GraphQL requests.
The requests are handled by two processes, namely the basebox broker and the basebox Database Proxy (henceforth referred to as the Proxy).
The broker receives GraphQL requests from the outside world and takes care of authentication and authorization (together with KeyCloak or another OpenID Connect service), validation, GraphQL introspection, the Business Logic Layer and a few other processes. It has the power to decide whether to pass on requests to dbproxy which handles all requests to the database (the broker does not have access to the database and can only address calls to the database via dbproxy).
Dbproxy is responsible for the actual operation handling which, at its core, entails transforming GraphQL requests to SQL commands using the configuration provided by the Compiler.
GraphQL Operations
Let's jump straight into the handling of GraphQL operations/requests by way of an example:
type List {
id: ID!
title: String!
tasks: [Task]
user: User!
}
type Task {
id: ID!
title: String!
description: String,
completed: Boolean!
user: User!
list: List!
}
type User {
username: String! @bb_primaryKey
name: String
tasks: [Task]
lists: [List]
}
type Query {
getUser(
username: String!
): User @bb_resolver(_type: select, _object: User, _filter: { username: { _eq: "$username" } })
}
getUser
that takes a username
as an argument and returns a User object. The operation can then be requested (at execution time) as follows:
This is beauty of GraphQL, you can also specify the fields that you want returned, include from any linked objects (in this case, from List and Task). basebox will also automatically create the necessary SQL joins to fetch the data requested from the correct tables. The result will returned in json format.