From 20de6a58e4f90eb25da3abec3a75280c5ca3b908 Mon Sep 17 00:00:00 2001 From: Kevin Naidoo <50574209+KevinNaidoo@users.noreply.github.com> Date: Mon, 30 Oct 2023 17:22:40 +0100 Subject: [PATCH] Updated schema and generated files for v1.0 --- bbconf/bb_todo-datamodel.sql | 11 ++ bbconf/bb_todo-resolver.toml | 218 ++++++++++++++++++++--------------- bbconf/bb_todo-typemap.json | 12 +- bbconf/todo_schema.graphql | 89 +++++++++++--- 4 files changed, 217 insertions(+), 113 deletions(-) diff --git a/bbconf/bb_todo-datamodel.sql b/bbconf/bb_todo-datamodel.sql index 14de577..d5f6796 100644 --- a/bbconf/bb_todo-datamodel.sql +++ b/bbconf/bb_todo-datamodel.sql @@ -1,3 +1,6 @@ +-- +-- Generated by basebox compiler (bbc) version 0.1.0-beta.23 at 2023-10-30 16:54:43+01:00 +-- CREATE EXTENSION IF NOT EXISTS pgcrypto; CREATE TABLE "List" ( @@ -32,3 +35,11 @@ ALTER TABLE "Task" ADD CONSTRAINT fk_task_2 FOREIGN KEY ("user_username") REFERE ALTER TABLE "Task" ADD CONSTRAINT fk_task_3 FOREIGN KEY ("list_id") REFERENCES "List" ("id"); +ALTER TABLE "User" ADD CONSTRAINT uq_user_4 UNIQUE (".ownerId"); + +ALTER TABLE "List" ADD COLUMN ".ownerId" VARCHAR NOT NULL; + +ALTER TABLE "Task" ADD COLUMN ".ownerId" VARCHAR NOT NULL; + +ALTER TABLE "User" ADD COLUMN ".ownerId" VARCHAR NOT NULL; + diff --git a/bbconf/bb_todo-resolver.toml b/bbconf/bb_todo-resolver.toml index 76288ff..7709456 100644 --- a/bbconf/bb_todo-resolver.toml +++ b/bbconf/bb_todo-resolver.toml @@ -1,40 +1,22 @@ -[resolvers.getUser] -operation_name = "getUser" +# +# Generated by bbc (basebox compiler) version 0.1.0-beta.23 at 2023-10-30 16:54:43+01:00 +# +[resolvers.deleteTask] +operation_name = "deleteTask" -[resolvers.getUser.resolver] +[resolvers.deleteTask.resolver.QueryBuilder] +command_type = "SQLDelete" + +[resolvers.deleteTask.resolver.QueryBuilder.command] +table = "Task" command_type = "SQLSelect" - -[resolvers.getUser.resolver.command] -table = "User" columns = [] modify_values = [] nested_modify_tables = [] aggregate_result = true -[[resolvers.getUser.resolver.command.where_clauses]] -table = "User" -column = "username" -condition_str = "= '$username'" -index = "" - -[resolvers.updateList] -operation_name = "updateList" - -[resolvers.updateList.resolver] -command_type = "SQLUpdate" - -[resolvers.updateList.resolver.command] -table = "List" -columns = [] -nested_modify_tables = [] -aggregate_result = true - -[[resolvers.updateList.resolver.command.modify_values]] -column = "title" -value = "'$title'" - -[[resolvers.updateList.resolver.command.where_clauses]] -table = "List" +[[resolvers.deleteTask.resolver.QueryBuilder.command.where_clauses]] +table = "Task" column = "id" condition_str = "= '$id'" index = "" @@ -42,146 +24,200 @@ index = "" [resolvers.createList] operation_name = "createList" -[resolvers.createList.resolver] +[resolvers.createList.resolver.QueryBuilder] command_type = "SQLInsert" -[resolvers.createList.resolver.command] +[resolvers.createList.resolver.QueryBuilder.command] table = "List" +command_type = "SQLSelect" columns = [] nested_modify_tables = [] where_clauses = [] aggregate_result = true -[[resolvers.createList.resolver.command.modify_values]] +[[resolvers.createList.resolver.QueryBuilder.command.modify_values]] column = "title" value = "'$title'" -[[resolvers.createList.resolver.command.modify_values]] +[[resolvers.createList.resolver.QueryBuilder.command.modify_values]] column = "user_username" value = "'$user.$username'" -[resolvers.createUser] -operation_name = "createUser" - -[resolvers.createUser.resolver] -command_type = "SQLInsert" - -[resolvers.createUser.resolver.command] -table = "User" -columns = [] -nested_modify_tables = [] -where_clauses = [] -aggregate_result = true - -[[resolvers.createUser.resolver.command.modify_values]] -column = "username" -value = "'$username'" - -[[resolvers.createUser.resolver.command.modify_values]] -column = "name" -value = "'$name'" - -[resolvers.deleteTask] -operation_name = "deleteTask" - -[resolvers.deleteTask.resolver] -command_type = "SQLDelete" - -[resolvers.deleteTask.resolver.command] -table = "Task" -columns = [] -modify_values = [] -nested_modify_tables = [] -aggregate_result = true - -[[resolvers.deleteTask.resolver.command.where_clauses]] -table = "Task" -column = "id" -condition_str = "= '$id'" -index = "" - [resolvers.createTask] operation_name = "createTask" -[resolvers.createTask.resolver] +[resolvers.createTask.resolver.QueryBuilder] command_type = "SQLInsert" -[resolvers.createTask.resolver.command] +[resolvers.createTask.resolver.QueryBuilder.command] table = "Task" +command_type = "SQLSelect" columns = [] nested_modify_tables = [] where_clauses = [] aggregate_result = true -[[resolvers.createTask.resolver.command.modify_values]] +[[resolvers.createTask.resolver.QueryBuilder.command.modify_values]] column = "title" value = "'$title'" -[[resolvers.createTask.resolver.command.modify_values]] +[[resolvers.createTask.resolver.QueryBuilder.command.modify_values]] column = "description" value = "'$description'" -[[resolvers.createTask.resolver.command.modify_values]] +[[resolvers.createTask.resolver.QueryBuilder.command.modify_values]] column = "completed" value = "'$completed'" -[[resolvers.createTask.resolver.command.modify_values]] +[[resolvers.createTask.resolver.QueryBuilder.command.modify_values]] column = "list_id" value = "'$list.$id'" -[[resolvers.createTask.resolver.command.modify_values]] +[[resolvers.createTask.resolver.QueryBuilder.command.modify_values]] column = "user_username" value = "'$user.$username'" [resolvers.deleteList] operation_name = "deleteList" -[resolvers.deleteList.resolver] +[resolvers.deleteList.resolver.QueryBuilder] command_type = "SQLDelete" -[resolvers.deleteList.resolver.command] +[resolvers.deleteList.resolver.QueryBuilder.command] table = "List" +command_type = "SQLSelect" columns = [] modify_values = [] nested_modify_tables = [] aggregate_result = true -[[resolvers.deleteList.resolver.command.where_clauses]] +[[resolvers.deleteList.resolver.QueryBuilder.command.where_clauses]] table = "List" column = "id" condition_str = "= '$id'" index = "" +[resolvers._bb_user_User] +operation_name = "_bb_user_User" + +[resolvers._bb_user_User.resolver.InternalQueryBuilder] +command_type = "SQLSelect" + +[resolvers._bb_user_User.resolver.InternalQueryBuilder.command] +table = "User" +command_type = "SQLSelect" +modify_values = [] +nested_modify_tables = [] +aggregate_result = true + +[[resolvers._bb_user_User.resolver.InternalQueryBuilder.command.columns]] + +[resolvers._bb_user_User.resolver.InternalQueryBuilder.command.columns.Column] +table = "User" +column = "username" + +[[resolvers._bb_user_User.resolver.InternalQueryBuilder.command.where_clauses]] +table = "User" +column = ".ownerId" +condition_str = "= $1" +index = "" + +[resolvers.getUser] +operation_name = "getUser" + +[resolvers.getUser.resolver.QueryBuilder] +command_type = "SQLSelect" + +[resolvers.getUser.resolver.QueryBuilder.command] +table = "User" +command_type = "SQLSelect" +columns = [] +modify_values = [] +nested_modify_tables = [] +aggregate_result = true + +[[resolvers.getUser.resolver.QueryBuilder.command.where_clauses]] +table = "User" +column = "username" +condition_str = "= '$username'" +index = "" + [resolvers.updateTask] operation_name = "updateTask" -[resolvers.updateTask.resolver] +[resolvers.updateTask.resolver.QueryBuilder] command_type = "SQLUpdate" -[resolvers.updateTask.resolver.command] +[resolvers.updateTask.resolver.QueryBuilder.command] table = "Task" +command_type = "SQLSelect" columns = [] nested_modify_tables = [] aggregate_result = true -[[resolvers.updateTask.resolver.command.modify_values]] +[[resolvers.updateTask.resolver.QueryBuilder.command.modify_values]] column = "title" value = "'$title'" -[[resolvers.updateTask.resolver.command.modify_values]] +[[resolvers.updateTask.resolver.QueryBuilder.command.modify_values]] column = "description" value = "'$description'" -[[resolvers.updateTask.resolver.command.modify_values]] +[[resolvers.updateTask.resolver.QueryBuilder.command.modify_values]] column = "completed" value = "'$completed'" -[[resolvers.updateTask.resolver.command.modify_values]] +[[resolvers.updateTask.resolver.QueryBuilder.command.modify_values]] column = "list_id" value = "'$list.$id'" -[[resolvers.updateTask.resolver.command.where_clauses]] +[[resolvers.updateTask.resolver.QueryBuilder.command.where_clauses]] table = "Task" column = "id" condition_str = "= '$id'" index = "" + +[resolvers.createUser] +operation_name = "createUser" + +[resolvers.createUser.resolver.QueryBuilder] +command_type = "SQLInsert" + +[resolvers.createUser.resolver.QueryBuilder.command] +table = "User" +command_type = "SQLSelect" +columns = [] +nested_modify_tables = [] +where_clauses = [] +aggregate_result = true + +[[resolvers.createUser.resolver.QueryBuilder.command.modify_values]] +column = "username" +value = "'$username'" + +[[resolvers.createUser.resolver.QueryBuilder.command.modify_values]] +column = "name" +value = "'$name'" + +[resolvers.updateList] +operation_name = "updateList" + +[resolvers.updateList.resolver.QueryBuilder] +command_type = "SQLUpdate" + +[resolvers.updateList.resolver.QueryBuilder.command] +table = "List" +command_type = "SQLSelect" +columns = [] +nested_modify_tables = [] +aggregate_result = true + +[[resolvers.updateList.resolver.QueryBuilder.command.modify_values]] +column = "title" +value = "'$title'" + +[[resolvers.updateList.resolver.QueryBuilder.command.where_clauses]] +table = "List" +column = "id" +condition_str = "= '$id'" +index = "" diff --git a/bbconf/bb_todo-typemap.json b/bbconf/bb_todo-typemap.json index 04bad23..532a667 100644 --- a/bbconf/bb_todo-typemap.json +++ b/bbconf/bb_todo-typemap.json @@ -88,7 +88,7 @@ "gql_field": "user", "gql_type": "User", "sql_join_type": { - "OneToMany": { + "ManyToOne": { "sql_table_of_object": "List", "sql_table_of_field": "User", "sql_mapped_columns": [ @@ -107,7 +107,7 @@ "gql_field": "lists", "gql_type": "List", "sql_join_type": { - "ManyToOne": { + "OneToMany": { "sql_table_of_object": "User", "sql_table_of_field": "List", "sql_mapped_columns": [ @@ -126,7 +126,7 @@ "gql_field": "user", "gql_type": "User", "sql_join_type": { - "OneToMany": { + "ManyToOne": { "sql_table_of_object": "Task", "sql_table_of_field": "User", "sql_mapped_columns": [ @@ -145,7 +145,7 @@ "gql_field": "tasks", "gql_type": "Task", "sql_join_type": { - "ManyToOne": { + "OneToMany": { "sql_table_of_object": "User", "sql_table_of_field": "Task", "sql_mapped_columns": [ @@ -164,7 +164,7 @@ "gql_field": "list", "gql_type": "List", "sql_join_type": { - "OneToMany": { + "ManyToOne": { "sql_table_of_object": "Task", "sql_table_of_field": "List", "sql_mapped_columns": [ @@ -183,7 +183,7 @@ "gql_field": "tasks", "gql_type": "Task", "sql_join_type": { - "ManyToOne": { + "OneToMany": { "sql_table_of_object": "List", "sql_table_of_field": "Task", "sql_mapped_columns": [ diff --git a/bbconf/todo_schema.graphql b/bbconf/todo_schema.graphql index 71b7223..6de1263 100644 --- a/bbconf/todo_schema.graphql +++ b/bbconf/todo_schema.graphql @@ -1,17 +1,26 @@ directive @bb_primaryKey on FIELD_DEFINITION directive @bb_resolver on FIELD_DEFINITION +directive @bb_owned on OBJECT +directive @bb_user on OBJECT -type List { +""" +List of tasks or todo items. +""" +type List @bb_owned { id: ID! title: String! tasks: [Task] user: User! } +input ListInput { + id: ID! +} + """ Task or todo item. """ -type Task { +type Task @bb_owned { id: ID! title: String! description: String, @@ -23,13 +32,17 @@ type Task { """ User type; owner of lists and tasks """ -type User { +type User @bb_user { username: String! @bb_primaryKey name: String tasks: [Task] lists: [List] } +input UserInput { + username: String! + name: String +} type Query { @@ -38,7 +51,11 @@ type Query { """ getUser( username: String! - ): User @bb_resolver(_type: SELECT, _object: User, _filter: { username: { _eq: "$username" } }) + ): User + @bb_resolver( + _type: SELECT, + _object: User, + _filter: { username: { _eq: "$username" } }) } @@ -47,36 +64,76 @@ type Mutation { createUser( username: String!, name: String! - ): User @bb_resolver(_type: INSERT, _object: User, _fields: { username: "$username", name: "$name" }) + ): User + @bb_resolver( + _type: INSERT, + _object: User, + _fields: { username: "$username", name: "$name" }) createList( title: String! - user: User! # username needs to be specified as it's non-nullable - ): List @bb_resolver(_type: INSERT, _object: List, _fields: { title: "$title", user: "$user" }) + user: UserInput! + ): List + @bb_resolver( + _type: INSERT, + _object: List, + _fields: { + title: "$title", + user: { username: "$user.$username" } + }) updateList( id: ID!, title: String! - ): List @bb_resolver(_type: UPDATE, _object: List, _filter: { id: { _eq: "$id" } }, _fields: { title: "$title" }) + ): List + @bb_resolver( + _type: UPDATE, + _object: List, + _filter: { id: { _eq: "$id" } }, + _fields: { title: "$title" }) - deleteList(id: ID!): List @bb_resolver(_type: DELETE, _object: List, _filter: { id: { _eq: "$id" } }) + deleteList(id: ID!): List + @bb_resolver(_type: DELETE, _object: List, _filter: { id: { _eq: "$id" } }) createTask( title: String!, description: String, - completed: Boolean!, # default not implemented yet, this needs to be added as it's non-nullable - list: List! # list needs to be specified as it's non-nullable - user: User! # username needs to be specified as it's non-nullable - ): Task @bb_resolver(_type: INSERT, _object: Task, _fields: { title: "$title", description: "$description", completed: "$completed", list: "$list", user: "$user" }) + completed: Boolean!, + list: ListInput! + user: UserInput! + ): Task + @bb_resolver( + _type: INSERT, + _object: Task, + _fields: { + title: "$title", + description: "$description", + completed: "$completed", + list: { id: "$list.$id" }, + user: { username: "$user.$username" } }) updateTask( id: ID!, title: String, description: String, completed: Boolean, - list: List - ): Task @bb_resolver(_type: UPDATE, _object: Task, _filter: { id: { _eq: "$id" } }, _fields: { title: "$title", description: "$description", completed: "$completed", list: "$list" }) + list: ListInput + ): Task + @bb_resolver( + _type: UPDATE, + _object: Task, + _filter: { id: { _eq: "$id" } }, + _fields: { + title: "$title", + description: "$description", + completed: "$completed", + list: { id: "$list.$id" } + }) - deleteTask(id: ID!): Task @bb_resolver(_type: DELETE, _object: Task, _filter: { id: { _eq: "$id" } }) + deleteTask(id: ID!): Task + @bb_resolver( + _type: DELETE, + _object: Task, + _filter: { id: { _eq: "$id" }}) }