Initial GraphQL API sort of working

This commit is contained in:
2023-01-04 19:31:52 +01:00
parent a2a2863d62
commit 8d5e523ab3
7 changed files with 206 additions and 13 deletions

View File

@@ -1,16 +1,18 @@
use super::super::schema::{langandagents, languages};
use diesel::prelude::*;
use juniper::GraphQLEnum;
#[derive(diesel_derive_enum::DbEnum, Debug, Clone, PartialEq, Eq)]
#[derive(diesel_derive_enum::DbEnum, Debug, Clone, PartialEq, Eq, GraphQLEnum)]
#[DieselTypePath = "crate::db::schema::sql_types::Release"]
pub enum Release {
Public,
#[graphql(name="NON_COMMERCIAL")]
NonCommercial,
Research,
Private,
}
#[derive(diesel_derive_enum::DbEnum, Debug, Clone, PartialEq, Eq)]
#[derive(diesel_derive_enum::DbEnum, Debug, Clone, PartialEq, Eq, GraphQLEnum)]
#[DieselTypePath = "crate::db::schema::sql_types::Dictgenre"]
pub enum DictGenre {
General,
@@ -22,7 +24,7 @@ pub enum DictGenre {
Terminology,
}
#[derive(diesel_derive_enum::DbEnum, Debug, Clone, PartialEq, Eq)]
#[derive(diesel_derive_enum::DbEnum, Debug, Clone, PartialEq, Eq, GraphQLEnum)]
#[DieselTypePath = "crate::db::schema::sql_types::Agentlanguagerelation"]
pub enum AgentLanguageRelation {
Publisher,
@@ -31,17 +33,35 @@ pub enum AgentLanguageRelation {
#[derive(Queryable, Insertable, Debug, Clone, PartialEq, Eq)]
pub struct Language {
release: Release,
created: chrono::NaiveDateTime,
name: String,
owner: String,
targetlanguage: Vec<String>,
genre: Vec<DictGenre>,
native: Option<String>,
release: Release,
targetlanguage: Vec<Option<String>>,
genre: Vec<Option<DictGenre>>,
abstract_: Option<String>,
created: chrono::NaiveDateTime,
description: Option<String>,
rights: Option<String>,
license: Option<String>,
owner: String,
}
#[juniper::graphql_object]
impl Language {
#[graphql(name = "release")]
fn release(&self) -> Release {
self.release.clone()
}
#[graphql(name = "created")]
fn created(&self) -> String {
self.created.to_string()
}
#[graphql(name = "name")]
fn name(&self) -> String {
self.name.clone()
}
}
#[derive(Queryable, Insertable, Debug, Clone, PartialEq, Eq)]