@@ -109,10 +109,8 @@ Query::Query()
109109 { R"gql( unreadCounts)gql" sv, [this ](service::ResolverParams&& params) { return resolveUnreadCounts (std::move (params)); } },
110110 { R"gql( unreadCountsById)gql" sv, [this ](service::ResolverParams&& params) { return resolveUnreadCountsById (std::move (params)); } }
111111 })
112- , _schema(std::make_shared<schema::Schema> ())
112+ , _schema(GetSchema ())
113113{
114- introspection::AddTypesToSchema (_schema);
115- today::AddTypesToSchema (_schema);
116114}
117115
118116service::FieldResult<std::shared_ptr<service::Object>> Query::getNode (service::FieldParams&&, response::IdType&&) const
@@ -1033,7 +1031,7 @@ Operations::Operations(std::shared_ptr<object::Query> query, std::shared_ptr<obj
10331031 { " query" , query },
10341032 { " mutation" , mutation },
10351033 { " subscription" , subscription }
1036- }, nullptr )
1034+ }, GetSchema() )
10371035 , _query(std::move(query))
10381036 , _mutation(std::move(mutation))
10391037 , _subscription(std::move(subscription))
@@ -1261,5 +1259,21 @@ void AddTypesToSchema(const std::shared_ptr<schema::Schema>& schema)
12611259 schema->AddSubscriptionType (typeSubscription);
12621260}
12631261
1262+ std::shared_ptr<schema::Schema> GetSchema ()
1263+ {
1264+ static std::weak_ptr<schema::Schema> s_wpSchema;
1265+ auto schema = s_wpSchema.lock ();
1266+
1267+ if (!schema)
1268+ {
1269+ schema = std::make_shared<schema::Schema>();
1270+ introspection::AddTypesToSchema (schema);
1271+ AddTypesToSchema (schema);
1272+ s_wpSchema = schema;
1273+ }
1274+
1275+ return schema;
1276+ }
1277+
12641278} /* namespace today */
12651279} /* namespace graphql */
0 commit comments