From 5a74ef3eeb7de8a6ec76cdbd04e48ca0d5e2d781 Mon Sep 17 00:00:00 2001 From: Damir Mukimov Date: Wed, 13 Aug 2025 07:49:02 +0200 Subject: [PATCH] chore: remove duplicate GraphQL folder and legacy server helper; baseline stays green --- graphql/resolver.go | 61 ------ graphql/schema.graphqls | 418 ---------------------------------------- server.go | 39 ---- 3 files changed, 518 deletions(-) delete mode 100644 graphql/resolver.go delete mode 100644 graphql/schema.graphqls delete mode 100644 server.go diff --git a/graphql/resolver.go b/graphql/resolver.go deleted file mode 100644 index c7631d0..0000000 --- a/graphql/resolver.go +++ /dev/null @@ -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 -} diff --git a/graphql/schema.graphqls b/graphql/schema.graphqls deleted file mode 100644 index 85539b6..0000000 --- a/graphql/schema.graphqls +++ /dev/null @@ -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] -} diff --git a/server.go b/server.go deleted file mode 100644 index 72e6509..0000000 --- a/server.go +++ /dev/null @@ -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) -}