github.com/weaviate/weaviate@v1.24.6/adapters/handlers/rest/state/state.go (about) 1 // _ _ 2 // __ _____ __ ___ ___ __ _| |_ ___ 3 // \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \ 4 // \ V V / __/ (_| |\ V /| | (_| | || __/ 5 // \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___| 6 // 7 // Copyright © 2016 - 2024 Weaviate B.V. All rights reserved. 8 // 9 // CONTACT: hello@weaviate.io 10 // 11 12 package state 13 14 import ( 15 "context" 16 "net/http" 17 "sync" 18 19 "github.com/sirupsen/logrus" 20 "github.com/weaviate/weaviate/adapters/handlers/graphql" 21 "github.com/weaviate/weaviate/adapters/repos/classifications" 22 "github.com/weaviate/weaviate/adapters/repos/db" 23 "github.com/weaviate/weaviate/usecases/auth/authentication/anonymous" 24 "github.com/weaviate/weaviate/usecases/auth/authentication/apikey" 25 "github.com/weaviate/weaviate/usecases/auth/authentication/oidc" 26 "github.com/weaviate/weaviate/usecases/auth/authorization" 27 "github.com/weaviate/weaviate/usecases/backup" 28 "github.com/weaviate/weaviate/usecases/cluster" 29 "github.com/weaviate/weaviate/usecases/config" 30 "github.com/weaviate/weaviate/usecases/locks" 31 "github.com/weaviate/weaviate/usecases/modules" 32 "github.com/weaviate/weaviate/usecases/monitoring" 33 "github.com/weaviate/weaviate/usecases/objects" 34 "github.com/weaviate/weaviate/usecases/replica" 35 "github.com/weaviate/weaviate/usecases/scaler" 36 "github.com/weaviate/weaviate/usecases/schema" 37 "github.com/weaviate/weaviate/usecases/sharding" 38 "github.com/weaviate/weaviate/usecases/traverser" 39 ) 40 41 // State is the only source of application-wide state 42 // NOTE: This is not true yet, see gh-723 43 // TODO: remove dependencies to anything that's not an ent or uc 44 type State struct { 45 OIDC *oidc.Client 46 AnonymousAccess *anonymous.Client 47 APIKey *apikey.Client 48 Authorizer authorization.Authorizer 49 ServerConfig *config.WeaviateConfig 50 Locks locks.ConnectorSchemaLock 51 Logger *logrus.Logger 52 gqlMutex sync.Mutex 53 GraphQL graphql.GraphQL 54 Modules *modules.Provider 55 SchemaManager *schema.Manager 56 Scaler *scaler.Scaler 57 Cluster *cluster.State 58 RemoteIndexIncoming *sharding.RemoteIndexIncoming 59 RemoteNodeIncoming *sharding.RemoteNodeIncoming 60 RemoteReplicaIncoming *replica.RemoteReplicaIncoming 61 Traverser *traverser.Traverser 62 63 ClassificationRepo *classifications.DistributedRepo 64 Metrics *monitoring.PrometheusMetrics 65 BackupManager *backup.Handler 66 DB *db.DB 67 BatchManager *objects.BatchManager 68 ClusterHttpClient *http.Client 69 ReindexCtxCancel context.CancelFunc 70 } 71 72 // GetGraphQL is the safe way to retrieve GraphQL from the state as it can be 73 // replaced at runtime. Instead of passing appState.GraphQL to your adapters, 74 // pass appState itself which you can abstract with a local interface such as: 75 // 76 // type gqlProvider interface { GetGraphQL graphql.GraphQL } 77 func (s *State) GetGraphQL() graphql.GraphQL { 78 s.gqlMutex.Lock() 79 gql := s.GraphQL 80 s.gqlMutex.Unlock() 81 return gql 82 } 83 84 func (s *State) SetGraphQL(gql graphql.GraphQL) { 85 s.gqlMutex.Lock() 86 s.GraphQL = gql 87 s.gqlMutex.Unlock() 88 }