mirror of
https://github.com/SamyRai/tercul-backend.git
synced 2025-12-27 05:11:34 +00:00
chore: remove duplicate GraphQL folder and legacy server helper; baseline stays green
This commit is contained in:
parent
4957117cb6
commit
5a74ef3eeb
@ -1,61 +0,0 @@
|
|||||||
package graphql
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"fmt"
|
|
||||||
"tercul/models"
|
|
||||||
|
|
||||||
"tercul/repositories"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Resolver holds repository dependencies.
|
|
||||||
type Resolver struct {
|
|
||||||
WorkRepo repositories.WorkRepository
|
|
||||||
}
|
|
||||||
|
|
||||||
// QueryResolver implements Query resolvers.
|
|
||||||
type QueryResolver struct {
|
|
||||||
*Resolver
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *QueryResolver) Work(ctx context.Context, id string) (*models.Work, error) {
|
|
||||||
var uid uint
|
|
||||||
_, err := fmt.Sscanf(id, "%d", &uid)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return r.WorkRepo.GetByID(ctx, uid)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *QueryResolver) Works(ctx context.Context, filter *struct {
|
|
||||||
Name *string
|
|
||||||
Language *string
|
|
||||||
}, limit *int, offset *int) ([]*models.Work, error) {
|
|
||||||
// Default pagination values
|
|
||||||
page := 1
|
|
||||||
pageSize := 20
|
|
||||||
if limit != nil {
|
|
||||||
pageSize = *limit
|
|
||||||
}
|
|
||||||
if offset != nil {
|
|
||||||
page = *offset
|
|
||||||
}
|
|
||||||
|
|
||||||
var paginated *repositories.PaginatedResult[models.Work]
|
|
||||||
var err error
|
|
||||||
|
|
||||||
if filter != nil && filter.Language != nil {
|
|
||||||
paginated, err = r.WorkRepo.FindByLanguage(ctx, *filter.Language, page, pageSize)
|
|
||||||
} else {
|
|
||||||
paginated, err = r.WorkRepo.List(ctx, page, pageSize)
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
result := make([]*models.Work, len(paginated.Items))
|
|
||||||
for i := range paginated.Items {
|
|
||||||
result[i] = &paginated.Items[i]
|
|
||||||
}
|
|
||||||
return result, nil
|
|
||||||
}
|
|
||||||
@ -1,418 +0,0 @@
|
|||||||
schema {
|
|
||||||
query: Query
|
|
||||||
}
|
|
||||||
|
|
||||||
type Query {
|
|
||||||
work(id: ID!): Work
|
|
||||||
works(filter: WorkFilter, limit: Int, offset: Int): [Work!]!
|
|
||||||
translation(id: ID!): Translation
|
|
||||||
author(id: ID!): Author
|
|
||||||
user(id: ID!): User
|
|
||||||
media(id: ID!): Media
|
|
||||||
book(id: ID!): Book
|
|
||||||
}
|
|
||||||
|
|
||||||
input WorkFilter {
|
|
||||||
name: String
|
|
||||||
language: String
|
|
||||||
}
|
|
||||||
|
|
||||||
type Work {
|
|
||||||
id: ID!
|
|
||||||
name: String
|
|
||||||
language: String
|
|
||||||
source: Source
|
|
||||||
embedding: Embedding
|
|
||||||
copyright: Copyright
|
|
||||||
collection: Collection
|
|
||||||
tags: [Tag]
|
|
||||||
readabilityScore: ReadabilityScore
|
|
||||||
media: [Media]
|
|
||||||
writingStyle: WritingStyle
|
|
||||||
emotion: Emotion
|
|
||||||
translations: [Translation]
|
|
||||||
category: Category
|
|
||||||
topicCluster: TopicCluster
|
|
||||||
mood: Mood
|
|
||||||
concept: Concept
|
|
||||||
linguisticLayer: LinguisticLayer
|
|
||||||
workStats: WorkStats
|
|
||||||
textMetadata: TextMetadata
|
|
||||||
poeticAnalysis: PoeticAnalysis
|
|
||||||
hybridEntityWork: HybridEntity_Work
|
|
||||||
copyrightClaim: CopyrightClaim
|
|
||||||
}
|
|
||||||
|
|
||||||
type Translation {
|
|
||||||
id: ID!
|
|
||||||
name: String
|
|
||||||
language: String
|
|
||||||
work: Work
|
|
||||||
embedding: Embedding
|
|
||||||
translationStats: TranslationStats
|
|
||||||
hybridEntityWork: HybridEntity_Work
|
|
||||||
copyright: Copyright
|
|
||||||
copyrightClaim: CopyrightClaim
|
|
||||||
}
|
|
||||||
|
|
||||||
type TopicCluster {
|
|
||||||
id: ID!
|
|
||||||
name: String
|
|
||||||
works: [Work]
|
|
||||||
}
|
|
||||||
|
|
||||||
type Emotion {
|
|
||||||
id: ID!
|
|
||||||
name: String
|
|
||||||
language: String
|
|
||||||
user: User
|
|
||||||
work: Work
|
|
||||||
collection: Collection
|
|
||||||
}
|
|
||||||
|
|
||||||
type Embedding {
|
|
||||||
id: ID!
|
|
||||||
vector: [Float]
|
|
||||||
work: Work
|
|
||||||
translation: Translation
|
|
||||||
}
|
|
||||||
|
|
||||||
type Gamification {
|
|
||||||
id: ID!
|
|
||||||
name: String
|
|
||||||
user: User
|
|
||||||
}
|
|
||||||
|
|
||||||
type Contribution {
|
|
||||||
id: ID!
|
|
||||||
name: String
|
|
||||||
user: User
|
|
||||||
}
|
|
||||||
|
|
||||||
type Stats {
|
|
||||||
id: ID!
|
|
||||||
name: String
|
|
||||||
user: User
|
|
||||||
work: Work
|
|
||||||
}
|
|
||||||
|
|
||||||
type LanguageAnalysis {
|
|
||||||
id: ID!
|
|
||||||
name: String
|
|
||||||
work: Work
|
|
||||||
}
|
|
||||||
|
|
||||||
type WritingStyle {
|
|
||||||
id: ID!
|
|
||||||
name: String
|
|
||||||
language: String
|
|
||||||
work: Work
|
|
||||||
}
|
|
||||||
|
|
||||||
type Media {
|
|
||||||
id: ID!
|
|
||||||
name: String
|
|
||||||
language: String
|
|
||||||
author: Author
|
|
||||||
translation: Translation
|
|
||||||
country: Country
|
|
||||||
city: City
|
|
||||||
mediaStats: MediaStats
|
|
||||||
copyright: Copyright
|
|
||||||
copyrightClaim: CopyrightClaim
|
|
||||||
}
|
|
||||||
|
|
||||||
type Collection {
|
|
||||||
id: ID!
|
|
||||||
name: String
|
|
||||||
works: [Work]
|
|
||||||
collectionStats: CollectionStats
|
|
||||||
}
|
|
||||||
|
|
||||||
type Bookmark {
|
|
||||||
id: ID!
|
|
||||||
name: String
|
|
||||||
work: Work
|
|
||||||
}
|
|
||||||
|
|
||||||
type Word {
|
|
||||||
id: ID!
|
|
||||||
name: String
|
|
||||||
concept: Concept
|
|
||||||
work: Work
|
|
||||||
}
|
|
||||||
|
|
||||||
type Copyright {
|
|
||||||
id: ID!
|
|
||||||
name: String
|
|
||||||
language: String
|
|
||||||
workOwner: Author
|
|
||||||
}
|
|
||||||
|
|
||||||
type Admin {
|
|
||||||
id: ID!
|
|
||||||
name: String
|
|
||||||
user: User
|
|
||||||
work: Work
|
|
||||||
}
|
|
||||||
|
|
||||||
type Author {
|
|
||||||
id: ID!
|
|
||||||
name: String
|
|
||||||
language: String
|
|
||||||
works: [Work]
|
|
||||||
books: [Book]
|
|
||||||
country: Country
|
|
||||||
city: City
|
|
||||||
place: Place
|
|
||||||
address: Address
|
|
||||||
copyrightClaim: CopyrightClaim
|
|
||||||
copyright: Copyright
|
|
||||||
}
|
|
||||||
|
|
||||||
type Category {
|
|
||||||
id: ID!
|
|
||||||
name: String
|
|
||||||
works: [Work]
|
|
||||||
}
|
|
||||||
|
|
||||||
type User {
|
|
||||||
id: ID!
|
|
||||||
name: String
|
|
||||||
works: [Work]
|
|
||||||
bookmarks: [Bookmark]
|
|
||||||
translations: [Translation]
|
|
||||||
collections: [Collection]
|
|
||||||
likes: [Like]
|
|
||||||
comments: [Comment]
|
|
||||||
authors: [Author]
|
|
||||||
topicClusters: [TopicCluster]
|
|
||||||
country: Country
|
|
||||||
city: City
|
|
||||||
userStats: UserStats
|
|
||||||
books: [Book]
|
|
||||||
media: [Media]
|
|
||||||
address: Address
|
|
||||||
emotions: [Emotion]
|
|
||||||
copyrightClaims: [CopyrightClaim]
|
|
||||||
}
|
|
||||||
|
|
||||||
type Book {
|
|
||||||
id: ID!
|
|
||||||
name: String
|
|
||||||
language: String
|
|
||||||
works: [Work]
|
|
||||||
bookStats: BookStats
|
|
||||||
copyright: Copyright
|
|
||||||
copyrightClaim: CopyrightClaim
|
|
||||||
}
|
|
||||||
|
|
||||||
type Source {
|
|
||||||
id: ID!
|
|
||||||
name: String
|
|
||||||
language: String
|
|
||||||
copyrights: [Copyright]
|
|
||||||
copyrightClaims: [CopyrightClaim]
|
|
||||||
}
|
|
||||||
|
|
||||||
type Tag {
|
|
||||||
id: ID!
|
|
||||||
name: String
|
|
||||||
works: [Work]
|
|
||||||
}
|
|
||||||
|
|
||||||
type Concept {
|
|
||||||
id: ID!
|
|
||||||
name: String
|
|
||||||
words: [Word]
|
|
||||||
works: [Work]
|
|
||||||
}
|
|
||||||
|
|
||||||
type Comment {
|
|
||||||
id: ID!
|
|
||||||
text: String
|
|
||||||
user: User
|
|
||||||
work: Work
|
|
||||||
}
|
|
||||||
|
|
||||||
type ReadabilityScore {
|
|
||||||
id: ID!
|
|
||||||
score: Float
|
|
||||||
language: String
|
|
||||||
work: Work
|
|
||||||
}
|
|
||||||
|
|
||||||
type LanguageEntity {
|
|
||||||
id: ID!
|
|
||||||
name: String
|
|
||||||
}
|
|
||||||
|
|
||||||
type Vote {
|
|
||||||
id: ID!
|
|
||||||
value: Int
|
|
||||||
user: User
|
|
||||||
}
|
|
||||||
|
|
||||||
type Edition {
|
|
||||||
id: ID!
|
|
||||||
version: String
|
|
||||||
book: Book
|
|
||||||
work: Work
|
|
||||||
}
|
|
||||||
|
|
||||||
type LinguisticLayer {
|
|
||||||
id: ID!
|
|
||||||
name: String
|
|
||||||
language: String
|
|
||||||
works: [Work]
|
|
||||||
}
|
|
||||||
|
|
||||||
type Mood {
|
|
||||||
id: ID!
|
|
||||||
name: String
|
|
||||||
language: String
|
|
||||||
works: [Work]
|
|
||||||
}
|
|
||||||
|
|
||||||
type Like {
|
|
||||||
id: ID!
|
|
||||||
name: String
|
|
||||||
user: User
|
|
||||||
}
|
|
||||||
|
|
||||||
type Notification {
|
|
||||||
id: ID!
|
|
||||||
message: String
|
|
||||||
language: String
|
|
||||||
user: User
|
|
||||||
}
|
|
||||||
|
|
||||||
type EditorialWorkflow {
|
|
||||||
id: ID!
|
|
||||||
stage: String
|
|
||||||
language: String
|
|
||||||
work: Work
|
|
||||||
}
|
|
||||||
|
|
||||||
type Monetization {
|
|
||||||
id: ID!
|
|
||||||
amount: Float
|
|
||||||
language: String
|
|
||||||
author: Author
|
|
||||||
work: Work
|
|
||||||
}
|
|
||||||
|
|
||||||
type Country {
|
|
||||||
id: ID!
|
|
||||||
name: String
|
|
||||||
language: String
|
|
||||||
users: [User]
|
|
||||||
media: [Media]
|
|
||||||
authors: [Author]
|
|
||||||
}
|
|
||||||
|
|
||||||
type City {
|
|
||||||
id: ID!
|
|
||||||
name: String
|
|
||||||
language: String
|
|
||||||
users: [User]
|
|
||||||
media: [Media]
|
|
||||||
authors: [Author]
|
|
||||||
}
|
|
||||||
|
|
||||||
type Address {
|
|
||||||
id: ID!
|
|
||||||
street: String
|
|
||||||
city: City
|
|
||||||
place: Place
|
|
||||||
}
|
|
||||||
|
|
||||||
type WorkStats {
|
|
||||||
id: ID!
|
|
||||||
views: Int
|
|
||||||
work: Work
|
|
||||||
}
|
|
||||||
|
|
||||||
type TranslationStats {
|
|
||||||
id: ID!
|
|
||||||
views: Int
|
|
||||||
translation: Translation
|
|
||||||
}
|
|
||||||
|
|
||||||
type MediaStats {
|
|
||||||
id: ID!
|
|
||||||
views: Int
|
|
||||||
media: Media
|
|
||||||
}
|
|
||||||
|
|
||||||
type UserStats {
|
|
||||||
id: ID!
|
|
||||||
activity: Int
|
|
||||||
user: User
|
|
||||||
}
|
|
||||||
|
|
||||||
type Place {
|
|
||||||
id: ID!
|
|
||||||
name: String
|
|
||||||
language: String
|
|
||||||
authors: [Author]
|
|
||||||
}
|
|
||||||
|
|
||||||
type BookStats {
|
|
||||||
id: ID!
|
|
||||||
sales: Int
|
|
||||||
book: Book
|
|
||||||
}
|
|
||||||
|
|
||||||
type CollectionStats {
|
|
||||||
id: ID!
|
|
||||||
items: Int
|
|
||||||
collection: Collection
|
|
||||||
}
|
|
||||||
|
|
||||||
type TextMetadata {
|
|
||||||
id: ID!
|
|
||||||
analysis: String
|
|
||||||
language: String
|
|
||||||
work: Work
|
|
||||||
translation: Translation
|
|
||||||
copyright: Copyright
|
|
||||||
}
|
|
||||||
|
|
||||||
type PoeticAnalysis {
|
|
||||||
id: ID!
|
|
||||||
structure: String
|
|
||||||
language: String
|
|
||||||
work: Work
|
|
||||||
copyright: Copyright
|
|
||||||
copyrightClaim: CopyrightClaim
|
|
||||||
}
|
|
||||||
|
|
||||||
type HybridEntity_Work {
|
|
||||||
id: ID!
|
|
||||||
name: String
|
|
||||||
work: Work
|
|
||||||
translation: Translation
|
|
||||||
topicCluster: TopicCluster
|
|
||||||
}
|
|
||||||
|
|
||||||
type CopyrightClaim {
|
|
||||||
id: ID!
|
|
||||||
details: String
|
|
||||||
work: Work
|
|
||||||
translation: Translation
|
|
||||||
author: Author
|
|
||||||
source: Source
|
|
||||||
contributor: Contributor
|
|
||||||
}
|
|
||||||
|
|
||||||
type Contributor {
|
|
||||||
id: ID!
|
|
||||||
name: String
|
|
||||||
copyrightClaims: [CopyrightClaim]
|
|
||||||
copyrights: [Copyright]
|
|
||||||
contributions: [Contribution]
|
|
||||||
gamification: [Gamification]
|
|
||||||
works: [Work]
|
|
||||||
media: [Media]
|
|
||||||
}
|
|
||||||
39
server.go
39
server.go
@ -1,39 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"net/http"
|
|
||||||
"tercul/graph"
|
|
||||||
|
|
||||||
"github.com/99designs/gqlgen/graphql/handler"
|
|
||||||
"github.com/99designs/gqlgen/graphql/handler/extension"
|
|
||||||
"github.com/99designs/gqlgen/graphql/handler/lru"
|
|
||||||
"github.com/99designs/gqlgen/graphql/handler/transport"
|
|
||||||
"github.com/99designs/gqlgen/graphql/playground"
|
|
||||||
"github.com/vektah/gqlparser/v2/ast"
|
|
||||||
)
|
|
||||||
|
|
||||||
const defaultPort = "8080"
|
|
||||||
|
|
||||||
// SetupGraphQLServer configures and returns a GraphQL server with the provided resolver
|
|
||||||
func SetupGraphQLServer(resolver *graph.Resolver) *handler.Server {
|
|
||||||
srv := handler.New(graph.NewExecutableSchema(graph.Config{Resolvers: resolver}))
|
|
||||||
|
|
||||||
srv.AddTransport(transport.Options{})
|
|
||||||
srv.AddTransport(transport.GET{})
|
|
||||||
srv.AddTransport(transport.POST{})
|
|
||||||
|
|
||||||
srv.SetQueryCache(lru.New[*ast.QueryDocument](1000))
|
|
||||||
|
|
||||||
srv.Use(extension.Introspection{})
|
|
||||||
srv.Use(extension.AutomaticPersistedQuery{
|
|
||||||
Cache: lru.New[string](100),
|
|
||||||
})
|
|
||||||
|
|
||||||
return srv
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetupHTTPHandlers configures HTTP routes for the GraphQL playground and API
|
|
||||||
func SetupHTTPHandlers(srv *handler.Server, queryPath string) {
|
|
||||||
http.Handle("/", playground.Handler("GraphQL playground", queryPath))
|
|
||||||
http.Handle(queryPath, srv)
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue
Block a user