adaptic-backend 1.0.340 → 1.0.341

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (110) hide show
  1. package/Account.cjs +2543 -2265
  2. package/Account.d.ts +19 -2
  3. package/Action.cjs +1116 -838
  4. package/Action.d.ts +19 -2
  5. package/Alert.cjs +2626 -2348
  6. package/Alert.d.ts +19 -2
  7. package/Allocation.cjs +2578 -2300
  8. package/Allocation.d.ts +19 -2
  9. package/AlpacaAccount.cjs +2383 -2105
  10. package/AlpacaAccount.d.ts +19 -2
  11. package/Asset.cjs +1813 -1535
  12. package/Asset.d.ts +19 -2
  13. package/Authenticator.cjs +2568 -2290
  14. package/Authenticator.d.ts +19 -2
  15. package/Customer.cjs +2495 -2217
  16. package/Customer.d.ts +19 -2
  17. package/EconomicEvent.cjs +645 -367
  18. package/EconomicEvent.d.ts +19 -2
  19. package/MarketSentiment.cjs +618 -340
  20. package/MarketSentiment.d.ts +19 -2
  21. package/NewsArticle.cjs +1933 -1655
  22. package/NewsArticle.d.ts +19 -2
  23. package/NewsArticleAssetSentiment.cjs +1842 -1564
  24. package/NewsArticleAssetSentiment.d.ts +19 -2
  25. package/ScheduledOptionOrder.cjs +594 -316
  26. package/ScheduledOptionOrder.d.ts +19 -2
  27. package/Session.cjs +2570 -2292
  28. package/Session.d.ts +19 -2
  29. package/Trade.cjs +1073 -795
  30. package/Trade.d.ts +19 -2
  31. package/User.cjs +2288 -2010
  32. package/User.d.ts +19 -2
  33. package/VerificationToken.cjs +606 -328
  34. package/VerificationToken.d.ts +19 -2
  35. package/esm/Account.d.ts +19 -2
  36. package/esm/Account.d.ts.map +1 -1
  37. package/esm/Account.js.map +1 -1
  38. package/esm/Account.mjs +2534 -2263
  39. package/esm/Action.d.ts +19 -2
  40. package/esm/Action.d.ts.map +1 -1
  41. package/esm/Action.js.map +1 -1
  42. package/esm/Action.mjs +1107 -836
  43. package/esm/Alert.d.ts +19 -2
  44. package/esm/Alert.d.ts.map +1 -1
  45. package/esm/Alert.js.map +1 -1
  46. package/esm/Alert.mjs +2617 -2346
  47. package/esm/Allocation.d.ts +19 -2
  48. package/esm/Allocation.d.ts.map +1 -1
  49. package/esm/Allocation.js.map +1 -1
  50. package/esm/Allocation.mjs +2569 -2298
  51. package/esm/AlpacaAccount.d.ts +19 -2
  52. package/esm/AlpacaAccount.d.ts.map +1 -1
  53. package/esm/AlpacaAccount.js.map +1 -1
  54. package/esm/AlpacaAccount.mjs +2374 -2103
  55. package/esm/Asset.d.ts +19 -2
  56. package/esm/Asset.d.ts.map +1 -1
  57. package/esm/Asset.js.map +1 -1
  58. package/esm/Asset.mjs +1804 -1533
  59. package/esm/Authenticator.d.ts +19 -2
  60. package/esm/Authenticator.d.ts.map +1 -1
  61. package/esm/Authenticator.js.map +1 -1
  62. package/esm/Authenticator.mjs +2559 -2288
  63. package/esm/Customer.d.ts +19 -2
  64. package/esm/Customer.d.ts.map +1 -1
  65. package/esm/Customer.js.map +1 -1
  66. package/esm/Customer.mjs +2486 -2215
  67. package/esm/EconomicEvent.d.ts +19 -2
  68. package/esm/EconomicEvent.d.ts.map +1 -1
  69. package/esm/EconomicEvent.js.map +1 -1
  70. package/esm/EconomicEvent.mjs +636 -365
  71. package/esm/MarketSentiment.d.ts +19 -2
  72. package/esm/MarketSentiment.d.ts.map +1 -1
  73. package/esm/MarketSentiment.js.map +1 -1
  74. package/esm/MarketSentiment.mjs +609 -338
  75. package/esm/NewsArticle.d.ts +19 -2
  76. package/esm/NewsArticle.d.ts.map +1 -1
  77. package/esm/NewsArticle.js.map +1 -1
  78. package/esm/NewsArticle.mjs +1924 -1653
  79. package/esm/NewsArticleAssetSentiment.d.ts +19 -2
  80. package/esm/NewsArticleAssetSentiment.d.ts.map +1 -1
  81. package/esm/NewsArticleAssetSentiment.js.map +1 -1
  82. package/esm/NewsArticleAssetSentiment.mjs +1833 -1562
  83. package/esm/ScheduledOptionOrder.d.ts +19 -2
  84. package/esm/ScheduledOptionOrder.d.ts.map +1 -1
  85. package/esm/ScheduledOptionOrder.js.map +1 -1
  86. package/esm/ScheduledOptionOrder.mjs +585 -314
  87. package/esm/Session.d.ts +19 -2
  88. package/esm/Session.d.ts.map +1 -1
  89. package/esm/Session.js.map +1 -1
  90. package/esm/Session.mjs +2561 -2290
  91. package/esm/Trade.d.ts +19 -2
  92. package/esm/Trade.d.ts.map +1 -1
  93. package/esm/Trade.js.map +1 -1
  94. package/esm/Trade.mjs +1064 -793
  95. package/esm/User.d.ts +19 -2
  96. package/esm/User.d.ts.map +1 -1
  97. package/esm/User.js.map +1 -1
  98. package/esm/User.mjs +2279 -2008
  99. package/esm/VerificationToken.d.ts +19 -2
  100. package/esm/VerificationToken.d.ts.map +1 -1
  101. package/esm/VerificationToken.js.map +1 -1
  102. package/esm/VerificationToken.mjs +597 -326
  103. package/esm/prismaClient.d.ts +4 -5
  104. package/esm/prismaClient.d.ts.map +1 -1
  105. package/esm/prismaClient.js.map +1 -1
  106. package/esm/prismaClient.mjs +13 -11
  107. package/package.json +1 -1
  108. package/prismaClient.cjs +13 -11
  109. package/prismaClient.d.ts +4 -5
  110. package/server.cjs +37 -5
@@ -99,70 +99,580 @@ export const NewsArticle = {
99
99
  * @param client - Apollo Client instance.
100
100
  * @returns The created NewsArticle or null.
101
101
  */
102
+ /**
103
+ * Create a new NewsArticle record.
104
+ * Enhanced with connection resilience against Prisma connection errors.
105
+ * @param props - Properties for the new record.
106
+ * @param globalClient - Apollo Client instance.
107
+ * @returns The created NewsArticle or null.
108
+ */
102
109
  async create(props, globalClient) {
103
- const [modules, client] = await Promise.all([
104
- getApolloModules(),
105
- globalClient
106
- ? Promise.resolve(globalClient)
107
- : importedClient
108
- ]);
109
- const { gql, ApolloError } = modules;
110
- const CREATE_ONE_NEWSARTICLE = gql `
111
- mutation createOneNewsArticle($data: NewsArticleCreateInput!) {
112
- createOneNewsArticle(data: $data) {
113
- ${selectionSet}
114
- }
110
+ // Maximum number of retries for database connection issues
111
+ const MAX_RETRIES = 3;
112
+ let retryCount = 0;
113
+ let lastError = null;
114
+ // Retry loop to handle potential database connection issues
115
+ while (retryCount < MAX_RETRIES) {
116
+ try {
117
+ const [modules, client] = await Promise.all([
118
+ getApolloModules(),
119
+ globalClient
120
+ ? Promise.resolve(globalClient)
121
+ : importedClient
122
+ ]);
123
+ const { gql, ApolloError } = modules;
124
+ const CREATE_ONE_NEWSARTICLE = gql `
125
+ mutation createOneNewsArticle($data: NewsArticleCreateInput!) {
126
+ createOneNewsArticle(data: $data) {
127
+ ${selectionSet}
128
+ }
129
+ }
130
+ `;
131
+ const variables = {
132
+ data: {
133
+ title: props.title !== undefined ? props.title : undefined,
134
+ content: props.content !== undefined ? props.content : undefined,
135
+ source: props.source !== undefined ? props.source : undefined,
136
+ sourceDomain: props.sourceDomain !== undefined ? props.sourceDomain : undefined,
137
+ url: props.url !== undefined ? props.url : undefined,
138
+ sentiment: props.sentiment !== undefined ? props.sentiment : undefined,
139
+ authors: props.authors !== undefined ? {
140
+ set: props.authors
141
+ } : undefined,
142
+ summary: props.summary !== undefined ? props.summary : undefined,
143
+ bannerImage: props.bannerImage !== undefined ? props.bannerImage : undefined,
144
+ timePublished: props.timePublished !== undefined ? props.timePublished : undefined,
145
+ category: props.category !== undefined ? props.category : undefined,
146
+ topics: props.topics !== undefined ? {
147
+ set: props.topics
148
+ } : undefined,
149
+ logo: props.logo !== undefined ? props.logo : undefined,
150
+ assets: props.assets ?
151
+ Array.isArray(props.assets) && props.assets.length > 0 && props.assets.every((item) => typeof item === 'object' && 'id' in item && Object.keys(item).length === 1) ? {
152
+ connect: props.assets.map((item) => ({
153
+ id: item.id
154
+ }))
155
+ }
156
+ : { connectOrCreate: props.assets.map((item) => ({
157
+ where: {
158
+ id: item.id !== undefined ? item.id : undefined,
159
+ url: item.url !== undefined ? item.url : undefined,
160
+ newsArticleId: item.newsArticleId !== undefined ? {
161
+ equals: item.newsArticleId
162
+ } : undefined,
163
+ },
164
+ create: {
165
+ url: item.url !== undefined ? item.url : undefined,
166
+ relevancyScore: item.relevancyScore !== undefined ? item.relevancyScore : undefined,
167
+ sentimentScore: item.sentimentScore !== undefined ? item.sentimentScore : undefined,
168
+ sentimentLabel: item.sentimentLabel !== undefined ? item.sentimentLabel : undefined,
169
+ asset: item.asset ?
170
+ typeof item.asset === 'object' && Object.keys(item.asset).length === 1 && Object.keys(item.asset)[0] === 'id'
171
+ ? { connect: {
172
+ id: item.asset.id
173
+ }
174
+ }
175
+ : { connectOrCreate: {
176
+ where: {
177
+ id: item.asset.id !== undefined ? item.asset.id : undefined,
178
+ symbol: item.asset.symbol !== undefined ? item.asset.symbol : undefined,
179
+ name: item.asset.name !== undefined ? item.asset.name : undefined,
180
+ },
181
+ create: {
182
+ symbol: item.asset.symbol !== undefined ? item.asset.symbol : undefined,
183
+ name: item.asset.name !== undefined ? item.asset.name : undefined,
184
+ type: item.asset.type !== undefined ? item.asset.type : undefined,
185
+ logoUrl: item.asset.logoUrl !== undefined ? item.asset.logoUrl : undefined,
186
+ description: item.asset.description !== undefined ? item.asset.description : undefined,
187
+ cik: item.asset.cik !== undefined ? item.asset.cik : undefined,
188
+ exchange: item.asset.exchange !== undefined ? item.asset.exchange : undefined,
189
+ currency: item.asset.currency !== undefined ? item.asset.currency : undefined,
190
+ country: item.asset.country !== undefined ? item.asset.country : undefined,
191
+ sector: item.asset.sector !== undefined ? item.asset.sector : undefined,
192
+ industry: item.asset.industry !== undefined ? item.asset.industry : undefined,
193
+ address: item.asset.address !== undefined ? item.asset.address : undefined,
194
+ officialSite: item.asset.officialSite !== undefined ? item.asset.officialSite : undefined,
195
+ fiscalYearEnd: item.asset.fiscalYearEnd !== undefined ? item.asset.fiscalYearEnd : undefined,
196
+ latestQuarter: item.asset.latestQuarter !== undefined ? item.asset.latestQuarter : undefined,
197
+ marketCapitalization: item.asset.marketCapitalization !== undefined ? item.asset.marketCapitalization : undefined,
198
+ ebitda: item.asset.ebitda !== undefined ? item.asset.ebitda : undefined,
199
+ peRatio: item.asset.peRatio !== undefined ? item.asset.peRatio : undefined,
200
+ pegRatio: item.asset.pegRatio !== undefined ? item.asset.pegRatio : undefined,
201
+ bookValue: item.asset.bookValue !== undefined ? item.asset.bookValue : undefined,
202
+ dividendPerShare: item.asset.dividendPerShare !== undefined ? item.asset.dividendPerShare : undefined,
203
+ dividendYield: item.asset.dividendYield !== undefined ? item.asset.dividendYield : undefined,
204
+ eps: item.asset.eps !== undefined ? item.asset.eps : undefined,
205
+ revenuePerShareTTM: item.asset.revenuePerShareTTM !== undefined ? item.asset.revenuePerShareTTM : undefined,
206
+ profitMargin: item.asset.profitMargin !== undefined ? item.asset.profitMargin : undefined,
207
+ operatingMarginTTM: item.asset.operatingMarginTTM !== undefined ? item.asset.operatingMarginTTM : undefined,
208
+ returnOnAssetsTTM: item.asset.returnOnAssetsTTM !== undefined ? item.asset.returnOnAssetsTTM : undefined,
209
+ returnOnEquityTTM: item.asset.returnOnEquityTTM !== undefined ? item.asset.returnOnEquityTTM : undefined,
210
+ revenueTTM: item.asset.revenueTTM !== undefined ? item.asset.revenueTTM : undefined,
211
+ grossProfitTTM: item.asset.grossProfitTTM !== undefined ? item.asset.grossProfitTTM : undefined,
212
+ dilutedEPSTTM: item.asset.dilutedEPSTTM !== undefined ? item.asset.dilutedEPSTTM : undefined,
213
+ quarterlyEarningsGrowthYOY: item.asset.quarterlyEarningsGrowthYOY !== undefined ? item.asset.quarterlyEarningsGrowthYOY : undefined,
214
+ quarterlyRevenueGrowthYOY: item.asset.quarterlyRevenueGrowthYOY !== undefined ? item.asset.quarterlyRevenueGrowthYOY : undefined,
215
+ analystTargetPrice: item.asset.analystTargetPrice !== undefined ? item.asset.analystTargetPrice : undefined,
216
+ analystRatingStrongBuy: item.asset.analystRatingStrongBuy !== undefined ? item.asset.analystRatingStrongBuy : undefined,
217
+ analystRatingBuy: item.asset.analystRatingBuy !== undefined ? item.asset.analystRatingBuy : undefined,
218
+ analystRatingHold: item.asset.analystRatingHold !== undefined ? item.asset.analystRatingHold : undefined,
219
+ analystRatingSell: item.asset.analystRatingSell !== undefined ? item.asset.analystRatingSell : undefined,
220
+ analystRatingStrongSell: item.asset.analystRatingStrongSell !== undefined ? item.asset.analystRatingStrongSell : undefined,
221
+ trailingPE: item.asset.trailingPE !== undefined ? item.asset.trailingPE : undefined,
222
+ forwardPE: item.asset.forwardPE !== undefined ? item.asset.forwardPE : undefined,
223
+ priceToSalesRatioTTM: item.asset.priceToSalesRatioTTM !== undefined ? item.asset.priceToSalesRatioTTM : undefined,
224
+ priceToBookRatio: item.asset.priceToBookRatio !== undefined ? item.asset.priceToBookRatio : undefined,
225
+ evToRevenue: item.asset.evToRevenue !== undefined ? item.asset.evToRevenue : undefined,
226
+ evToEbitda: item.asset.evToEbitda !== undefined ? item.asset.evToEbitda : undefined,
227
+ beta: item.asset.beta !== undefined ? item.asset.beta : undefined,
228
+ week52High: item.asset.week52High !== undefined ? item.asset.week52High : undefined,
229
+ week52Low: item.asset.week52Low !== undefined ? item.asset.week52Low : undefined,
230
+ day50MovingAverage: item.asset.day50MovingAverage !== undefined ? item.asset.day50MovingAverage : undefined,
231
+ day200MovingAverage: item.asset.day200MovingAverage !== undefined ? item.asset.day200MovingAverage : undefined,
232
+ sharesOutstanding: item.asset.sharesOutstanding !== undefined ? item.asset.sharesOutstanding : undefined,
233
+ dividendDate: item.asset.dividendDate !== undefined ? item.asset.dividendDate : undefined,
234
+ exDividendDate: item.asset.exDividendDate !== undefined ? item.asset.exDividendDate : undefined,
235
+ askPrice: item.asset.askPrice !== undefined ? item.asset.askPrice : undefined,
236
+ bidPrice: item.asset.bidPrice !== undefined ? item.asset.bidPrice : undefined,
237
+ },
238
+ }
239
+ } : undefined,
240
+ },
241
+ }))
242
+ } : undefined,
243
+ },
244
+ };
245
+ const filteredVariables = removeUndefinedProps(variables);
246
+ const response = await client.mutate({
247
+ mutation: CREATE_ONE_NEWSARTICLE,
248
+ variables: filteredVariables,
249
+ // Don't cache mutations, but ensure we're using the freshest context
250
+ fetchPolicy: 'no-cache'
251
+ });
252
+ if (response.errors && response.errors.length > 0)
253
+ throw new Error(response.errors[0].message);
254
+ if (response && response.data && response.data.createOneNewsArticle) {
255
+ return response.data.createOneNewsArticle;
256
+ }
257
+ else {
258
+ return null;
259
+ }
260
+ }
261
+ catch (error) {
262
+ lastError = error;
263
+ // Check if this is a database connection error that we should retry
264
+ const isConnectionError = error.message?.includes('Server has closed the connection') ||
265
+ error.message?.includes('Cannot reach database server') ||
266
+ error.message?.includes('Connection timed out') ||
267
+ error.message?.includes('Accelerate') || // Prisma Accelerate proxy errors
268
+ (error.networkError && error.networkError.message?.includes('Failed to fetch'));
269
+ if (isConnectionError && retryCount < MAX_RETRIES - 1) {
270
+ retryCount++;
271
+ const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
272
+ console.warn("Database connection error, retrying...");
273
+ await new Promise(resolve => setTimeout(resolve, delay));
274
+ continue;
275
+ }
276
+ // Log the error and rethrow
277
+ console.error("Database error occurred:", error);
278
+ throw error;
279
+ }
115
280
  }
116
- `;
117
- const variables = {
118
- data: {
119
- title: props.title !== undefined ? props.title : undefined,
120
- content: props.content !== undefined ? props.content : undefined,
121
- source: props.source !== undefined ? props.source : undefined,
122
- sourceDomain: props.sourceDomain !== undefined ? props.sourceDomain : undefined,
123
- url: props.url !== undefined ? props.url : undefined,
124
- sentiment: props.sentiment !== undefined ? props.sentiment : undefined,
125
- authors: props.authors !== undefined ? {
126
- set: props.authors
127
- } : undefined,
128
- summary: props.summary !== undefined ? props.summary : undefined,
129
- bannerImage: props.bannerImage !== undefined ? props.bannerImage : undefined,
130
- timePublished: props.timePublished !== undefined ? props.timePublished : undefined,
131
- category: props.category !== undefined ? props.category : undefined,
132
- topics: props.topics !== undefined ? {
133
- set: props.topics
134
- } : undefined,
135
- logo: props.logo !== undefined ? props.logo : undefined,
136
- assets: props.assets ?
137
- Array.isArray(props.assets) && props.assets.length > 0 && props.assets.every((item) => typeof item === 'object' && 'id' in item && Object.keys(item).length === 1) ? {
138
- connect: props.assets.map((item) => ({
139
- id: item.id
140
- }))
141
- }
142
- : { connectOrCreate: props.assets.map((item) => ({
143
- where: {
144
- id: item.id !== undefined ? item.id : undefined,
145
- url: item.url !== undefined ? item.url : undefined,
146
- newsArticleId: item.newsArticleId !== undefined ? {
147
- equals: item.newsArticleId
148
- } : undefined,
149
- },
150
- create: {
151
- url: item.url !== undefined ? item.url : undefined,
152
- relevancyScore: item.relevancyScore !== undefined ? item.relevancyScore : undefined,
153
- sentimentScore: item.sentimentScore !== undefined ? item.sentimentScore : undefined,
154
- sentimentLabel: item.sentimentLabel !== undefined ? item.sentimentLabel : undefined,
155
- asset: item.asset ?
156
- typeof item.asset === 'object' && Object.keys(item.asset).length === 1 && Object.keys(item.asset)[0] === 'id'
157
- ? { connect: {
158
- id: item.asset.id
159
- }
160
- }
161
- : { connectOrCreate: {
281
+ // If we exhausted retries, throw the last error
282
+ throw lastError;
283
+ },
284
+ /**
285
+ * Create multiple NewsArticle records.
286
+ * Enhanced with connection resilience against Prisma connection errors.
287
+ * @param props - Array of NewsArticle objects for the new records.
288
+ * @param globalClient - Apollo Client instance.
289
+ * @returns The count of created records or null.
290
+ */
291
+ async createMany(props, globalClient) {
292
+ // Maximum number of retries for database connection issues
293
+ const MAX_RETRIES = 3;
294
+ let retryCount = 0;
295
+ let lastError = null;
296
+ // Retry loop to handle potential database connection issues
297
+ while (retryCount < MAX_RETRIES) {
298
+ try {
299
+ const [modules, client] = await Promise.all([
300
+ getApolloModules(),
301
+ globalClient
302
+ ? Promise.resolve(globalClient)
303
+ : importedClient
304
+ ]);
305
+ const { gql, ApolloError } = modules;
306
+ const CREATE_MANY_NEWSARTICLE = gql `
307
+ mutation createManyNewsArticle($data: [NewsArticleCreateManyInput!]!) {
308
+ createManyNewsArticle(data: $data) {
309
+ count
310
+ }
311
+ }`;
312
+ const variables = {
313
+ data: props.map(prop => ({
314
+ title: prop.title !== undefined ? prop.title : undefined,
315
+ content: prop.content !== undefined ? prop.content : undefined,
316
+ source: prop.source !== undefined ? prop.source : undefined,
317
+ sourceDomain: prop.sourceDomain !== undefined ? prop.sourceDomain : undefined,
318
+ url: prop.url !== undefined ? prop.url : undefined,
319
+ sentiment: prop.sentiment !== undefined ? prop.sentiment : undefined,
320
+ authors: prop.authors !== undefined ? {
321
+ set: prop.authors
322
+ } : undefined,
323
+ summary: prop.summary !== undefined ? prop.summary : undefined,
324
+ bannerImage: prop.bannerImage !== undefined ? prop.bannerImage : undefined,
325
+ timePublished: prop.timePublished !== undefined ? prop.timePublished : undefined,
326
+ category: prop.category !== undefined ? prop.category : undefined,
327
+ topics: prop.topics !== undefined ? {
328
+ set: prop.topics
329
+ } : undefined,
330
+ logo: prop.logo !== undefined ? prop.logo : undefined,
331
+ })),
332
+ };
333
+ const filteredVariables = removeUndefinedProps(variables);
334
+ const response = await client.mutate({
335
+ mutation: CREATE_MANY_NEWSARTICLE,
336
+ variables: filteredVariables,
337
+ // Don't cache mutations, but ensure we're using the freshest context
338
+ fetchPolicy: 'no-cache'
339
+ });
340
+ if (response.errors && response.errors.length > 0)
341
+ throw new Error(response.errors[0].message);
342
+ if (response && response.data && response.data.createManyNewsArticle) {
343
+ return response.data.createManyNewsArticle;
344
+ }
345
+ else {
346
+ return null;
347
+ }
348
+ }
349
+ catch (error) {
350
+ lastError = error;
351
+ // Check if this is a database connection error that we should retry
352
+ const isConnectionError = error.message?.includes('Server has closed the connection') ||
353
+ error.message?.includes('Cannot reach database server') ||
354
+ error.message?.includes('Connection timed out') ||
355
+ error.message?.includes('Accelerate') || // Prisma Accelerate proxy errors
356
+ (error.networkError && error.networkError.message?.includes('Failed to fetch'));
357
+ if (isConnectionError && retryCount < MAX_RETRIES - 1) {
358
+ retryCount++;
359
+ const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
360
+ console.warn("Database connection error, retrying...");
361
+ await new Promise(resolve => setTimeout(resolve, delay));
362
+ continue;
363
+ }
364
+ // Log the error and rethrow
365
+ console.error("Database error occurred:", error);
366
+ throw error;
367
+ }
368
+ }
369
+ // If we exhausted retries, throw the last error
370
+ throw lastError;
371
+ },
372
+ /**
373
+ * Update a single NewsArticle record.
374
+ * Enhanced with connection resilience against Prisma connection errors.
375
+ * @param props - Properties to update.
376
+ * @param globalClient - Apollo Client instance.
377
+ * @returns The updated NewsArticle or null.
378
+ */
379
+ async update(props, globalClient) {
380
+ // Maximum number of retries for database connection issues
381
+ const MAX_RETRIES = 3;
382
+ let retryCount = 0;
383
+ let lastError = null;
384
+ // Retry loop to handle potential database connection issues
385
+ while (retryCount < MAX_RETRIES) {
386
+ try {
387
+ const [modules, client] = await Promise.all([
388
+ getApolloModules(),
389
+ globalClient
390
+ ? Promise.resolve(globalClient)
391
+ : importedClient
392
+ ]);
393
+ const { gql, ApolloError } = modules;
394
+ const UPDATE_ONE_NEWSARTICLE = gql `
395
+ mutation updateOneNewsArticle($data: NewsArticleUpdateInput!, $where: NewsArticleWhereUniqueInput!) {
396
+ updateOneNewsArticle(data: $data, where: $where) {
397
+ ${selectionSet}
398
+ }
399
+ }`;
400
+ const variables = {
401
+ where: {
402
+ id: props.id !== undefined ? props.id : undefined,
403
+ url: props.url !== undefined ? props.url : undefined,
404
+ title: props.title !== undefined ? {
405
+ equals: props.title
406
+ } : undefined,
407
+ },
408
+ data: {
409
+ id: props.id !== undefined ? {
410
+ set: props.id
411
+ } : undefined,
412
+ title: props.title !== undefined ? {
413
+ set: props.title
414
+ } : undefined,
415
+ content: props.content !== undefined ? {
416
+ set: props.content
417
+ } : undefined,
418
+ source: props.source !== undefined ? {
419
+ set: props.source
420
+ } : undefined,
421
+ sourceDomain: props.sourceDomain !== undefined ? {
422
+ set: props.sourceDomain
423
+ } : undefined,
424
+ url: props.url !== undefined ? {
425
+ set: props.url
426
+ } : undefined,
427
+ sentiment: props.sentiment !== undefined ? {
428
+ set: props.sentiment
429
+ } : undefined,
430
+ authors: props.authors !== undefined ? {
431
+ set: props.authors
432
+ } : undefined,
433
+ summary: props.summary !== undefined ? {
434
+ set: props.summary
435
+ } : undefined,
436
+ bannerImage: props.bannerImage !== undefined ? {
437
+ set: props.bannerImage
438
+ } : undefined,
439
+ timePublished: props.timePublished !== undefined ? {
440
+ set: props.timePublished
441
+ } : undefined,
442
+ category: props.category !== undefined ? {
443
+ set: props.category
444
+ } : undefined,
445
+ topics: props.topics !== undefined ? {
446
+ set: props.topics
447
+ } : undefined,
448
+ logo: props.logo !== undefined ? {
449
+ set: props.logo
450
+ } : undefined,
451
+ createdAt: props.createdAt !== undefined ? {
452
+ set: props.createdAt
453
+ } : undefined,
454
+ updatedAt: props.updatedAt !== undefined ? {
455
+ set: props.updatedAt
456
+ } : undefined,
457
+ assets: props.assets ?
458
+ Array.isArray(props.assets) && props.assets.length > 0 && props.assets.every((item) => typeof item === 'object' && ('id' in item || 'symbol' in item) && Object.keys(item).length === 1) ? {
459
+ connect: props.assets.map((item) => ({
460
+ id: item.id
461
+ }))
462
+ } : { upsert: props.assets.map((item) => ({
463
+ where: {
464
+ id: item.id !== undefined ? item.id : undefined,
465
+ url: item.url !== undefined ? item.url : undefined,
466
+ assetId: item.assetId !== undefined ? {
467
+ equals: item.assetId
468
+ } : undefined,
469
+ newsArticleId: item.newsArticleId !== undefined ? {
470
+ equals: item.newsArticleId
471
+ } : undefined,
472
+ },
473
+ update: {
474
+ id: item.id !== undefined ? {
475
+ set: item.id
476
+ } : undefined,
477
+ url: item.url !== undefined ? {
478
+ set: item.url
479
+ } : undefined,
480
+ relevancyScore: item.relevancyScore !== undefined ? {
481
+ set: item.relevancyScore
482
+ } : undefined,
483
+ sentimentScore: item.sentimentScore !== undefined ? {
484
+ set: item.sentimentScore
485
+ } : undefined,
486
+ sentimentLabel: item.sentimentLabel !== undefined ? {
487
+ set: item.sentimentLabel
488
+ } : undefined,
489
+ asset: item.asset ?
490
+ typeof item.asset === 'object' && Object.keys(item.asset).length === 1 && (Object.keys(item.asset)[0] === 'id' || Object.keys(item.asset)[0] === 'symbol')
491
+ ? {
492
+ connect: {
493
+ id: item.asset.id
494
+ }
495
+ } : { upsert: {
162
496
  where: {
163
- id: item.asset.id !== undefined ? item.asset.id : undefined,
164
- symbol: item.asset.symbol !== undefined ? item.asset.symbol : undefined,
165
- name: item.asset.name !== undefined ? item.asset.name : undefined,
497
+ id: item.asset.id !== undefined ? {
498
+ equals: item.asset.id
499
+ } : undefined,
500
+ symbol: item.asset.symbol !== undefined ? {
501
+ equals: item.asset.symbol
502
+ } : undefined,
503
+ name: item.asset.name !== undefined ? {
504
+ equals: item.asset.name
505
+ } : undefined,
506
+ },
507
+ update: {
508
+ id: item.asset.id !== undefined ? {
509
+ set: item.asset.id
510
+ } : undefined,
511
+ symbol: item.asset.symbol !== undefined ? {
512
+ set: item.asset.symbol
513
+ } : undefined,
514
+ name: item.asset.name !== undefined ? {
515
+ set: item.asset.name
516
+ } : undefined,
517
+ type: item.asset.type !== undefined ? {
518
+ set: item.asset.type
519
+ } : undefined,
520
+ logoUrl: item.asset.logoUrl !== undefined ? {
521
+ set: item.asset.logoUrl
522
+ } : undefined,
523
+ description: item.asset.description !== undefined ? {
524
+ set: item.asset.description
525
+ } : undefined,
526
+ cik: item.asset.cik !== undefined ? {
527
+ set: item.asset.cik
528
+ } : undefined,
529
+ exchange: item.asset.exchange !== undefined ? {
530
+ set: item.asset.exchange
531
+ } : undefined,
532
+ currency: item.asset.currency !== undefined ? {
533
+ set: item.asset.currency
534
+ } : undefined,
535
+ country: item.asset.country !== undefined ? {
536
+ set: item.asset.country
537
+ } : undefined,
538
+ sector: item.asset.sector !== undefined ? {
539
+ set: item.asset.sector
540
+ } : undefined,
541
+ industry: item.asset.industry !== undefined ? {
542
+ set: item.asset.industry
543
+ } : undefined,
544
+ address: item.asset.address !== undefined ? {
545
+ set: item.asset.address
546
+ } : undefined,
547
+ officialSite: item.asset.officialSite !== undefined ? {
548
+ set: item.asset.officialSite
549
+ } : undefined,
550
+ fiscalYearEnd: item.asset.fiscalYearEnd !== undefined ? {
551
+ set: item.asset.fiscalYearEnd
552
+ } : undefined,
553
+ latestQuarter: item.asset.latestQuarter !== undefined ? {
554
+ set: item.asset.latestQuarter
555
+ } : undefined,
556
+ marketCapitalization: item.asset.marketCapitalization !== undefined ? {
557
+ set: item.asset.marketCapitalization
558
+ } : undefined,
559
+ ebitda: item.asset.ebitda !== undefined ? {
560
+ set: item.asset.ebitda
561
+ } : undefined,
562
+ peRatio: item.asset.peRatio !== undefined ? {
563
+ set: item.asset.peRatio
564
+ } : undefined,
565
+ pegRatio: item.asset.pegRatio !== undefined ? {
566
+ set: item.asset.pegRatio
567
+ } : undefined,
568
+ bookValue: item.asset.bookValue !== undefined ? {
569
+ set: item.asset.bookValue
570
+ } : undefined,
571
+ dividendPerShare: item.asset.dividendPerShare !== undefined ? {
572
+ set: item.asset.dividendPerShare
573
+ } : undefined,
574
+ dividendYield: item.asset.dividendYield !== undefined ? {
575
+ set: item.asset.dividendYield
576
+ } : undefined,
577
+ eps: item.asset.eps !== undefined ? {
578
+ set: item.asset.eps
579
+ } : undefined,
580
+ revenuePerShareTTM: item.asset.revenuePerShareTTM !== undefined ? {
581
+ set: item.asset.revenuePerShareTTM
582
+ } : undefined,
583
+ profitMargin: item.asset.profitMargin !== undefined ? {
584
+ set: item.asset.profitMargin
585
+ } : undefined,
586
+ operatingMarginTTM: item.asset.operatingMarginTTM !== undefined ? {
587
+ set: item.asset.operatingMarginTTM
588
+ } : undefined,
589
+ returnOnAssetsTTM: item.asset.returnOnAssetsTTM !== undefined ? {
590
+ set: item.asset.returnOnAssetsTTM
591
+ } : undefined,
592
+ returnOnEquityTTM: item.asset.returnOnEquityTTM !== undefined ? {
593
+ set: item.asset.returnOnEquityTTM
594
+ } : undefined,
595
+ revenueTTM: item.asset.revenueTTM !== undefined ? {
596
+ set: item.asset.revenueTTM
597
+ } : undefined,
598
+ grossProfitTTM: item.asset.grossProfitTTM !== undefined ? {
599
+ set: item.asset.grossProfitTTM
600
+ } : undefined,
601
+ dilutedEPSTTM: item.asset.dilutedEPSTTM !== undefined ? {
602
+ set: item.asset.dilutedEPSTTM
603
+ } : undefined,
604
+ quarterlyEarningsGrowthYOY: item.asset.quarterlyEarningsGrowthYOY !== undefined ? {
605
+ set: item.asset.quarterlyEarningsGrowthYOY
606
+ } : undefined,
607
+ quarterlyRevenueGrowthYOY: item.asset.quarterlyRevenueGrowthYOY !== undefined ? {
608
+ set: item.asset.quarterlyRevenueGrowthYOY
609
+ } : undefined,
610
+ analystTargetPrice: item.asset.analystTargetPrice !== undefined ? {
611
+ set: item.asset.analystTargetPrice
612
+ } : undefined,
613
+ analystRatingStrongBuy: item.asset.analystRatingStrongBuy !== undefined ? {
614
+ set: item.asset.analystRatingStrongBuy
615
+ } : undefined,
616
+ analystRatingBuy: item.asset.analystRatingBuy !== undefined ? {
617
+ set: item.asset.analystRatingBuy
618
+ } : undefined,
619
+ analystRatingHold: item.asset.analystRatingHold !== undefined ? {
620
+ set: item.asset.analystRatingHold
621
+ } : undefined,
622
+ analystRatingSell: item.asset.analystRatingSell !== undefined ? {
623
+ set: item.asset.analystRatingSell
624
+ } : undefined,
625
+ analystRatingStrongSell: item.asset.analystRatingStrongSell !== undefined ? {
626
+ set: item.asset.analystRatingStrongSell
627
+ } : undefined,
628
+ trailingPE: item.asset.trailingPE !== undefined ? {
629
+ set: item.asset.trailingPE
630
+ } : undefined,
631
+ forwardPE: item.asset.forwardPE !== undefined ? {
632
+ set: item.asset.forwardPE
633
+ } : undefined,
634
+ priceToSalesRatioTTM: item.asset.priceToSalesRatioTTM !== undefined ? {
635
+ set: item.asset.priceToSalesRatioTTM
636
+ } : undefined,
637
+ priceToBookRatio: item.asset.priceToBookRatio !== undefined ? {
638
+ set: item.asset.priceToBookRatio
639
+ } : undefined,
640
+ evToRevenue: item.asset.evToRevenue !== undefined ? {
641
+ set: item.asset.evToRevenue
642
+ } : undefined,
643
+ evToEbitda: item.asset.evToEbitda !== undefined ? {
644
+ set: item.asset.evToEbitda
645
+ } : undefined,
646
+ beta: item.asset.beta !== undefined ? {
647
+ set: item.asset.beta
648
+ } : undefined,
649
+ week52High: item.asset.week52High !== undefined ? {
650
+ set: item.asset.week52High
651
+ } : undefined,
652
+ week52Low: item.asset.week52Low !== undefined ? {
653
+ set: item.asset.week52Low
654
+ } : undefined,
655
+ day50MovingAverage: item.asset.day50MovingAverage !== undefined ? {
656
+ set: item.asset.day50MovingAverage
657
+ } : undefined,
658
+ day200MovingAverage: item.asset.day200MovingAverage !== undefined ? {
659
+ set: item.asset.day200MovingAverage
660
+ } : undefined,
661
+ sharesOutstanding: item.asset.sharesOutstanding !== undefined ? {
662
+ set: item.asset.sharesOutstanding
663
+ } : undefined,
664
+ dividendDate: item.asset.dividendDate !== undefined ? {
665
+ set: item.asset.dividendDate
666
+ } : undefined,
667
+ exDividendDate: item.asset.exDividendDate !== undefined ? {
668
+ set: item.asset.exDividendDate
669
+ } : undefined,
670
+ askPrice: item.asset.askPrice !== undefined ? {
671
+ set: item.asset.askPrice
672
+ } : undefined,
673
+ bidPrice: item.asset.bidPrice !== undefined ? {
674
+ set: item.asset.bidPrice
675
+ } : undefined,
166
676
  },
167
677
  create: {
168
678
  symbol: item.asset.symbol !== undefined ? item.asset.symbol : undefined,
@@ -223,617 +733,534 @@ export const NewsArticle = {
223
733
  },
224
734
  }
225
735
  } : undefined,
226
- },
227
- }))
228
- } : undefined,
229
- },
230
- };
231
- const filteredVariables = removeUndefinedProps(variables);
232
- try {
233
- const response = await client.mutate({ mutation: CREATE_ONE_NEWSARTICLE, variables: filteredVariables });
234
- if (response.errors && response.errors.length > 0)
235
- throw new Error(response.errors[0].message);
236
- if (response && response.data && response.data.createOneNewsArticle) {
237
- return response.data.createOneNewsArticle;
238
- }
239
- else {
240
- return null;
241
- }
242
- }
243
- catch (error) {
244
- console.error('Error in createOneNewsArticle:', error);
245
- throw error;
246
- }
247
- },
248
- /**
249
- * Create multiple NewsArticle records.
250
- * @param props - Array of NewsArticle objects for the new records.
251
- * @param globalClient - Apollo Client instance.
252
- * @returns The count of created records or null.
253
- */
254
- async createMany(props, globalClient) {
255
- const [modules, client] = await Promise.all([
256
- getApolloModules(),
257
- globalClient
258
- ? Promise.resolve(globalClient)
259
- : importedClient
260
- ]);
261
- const { gql, ApolloError } = modules;
262
- const CREATE_MANY_NEWSARTICLE = gql `
263
- mutation createManyNewsArticle($data: [NewsArticleCreateManyInput!]!) {
264
- createManyNewsArticle(data: $data) {
265
- count
266
- }
267
- }`;
268
- const variables = {
269
- data: props.map(prop => ({
270
- title: prop.title !== undefined ? prop.title : undefined,
271
- content: prop.content !== undefined ? prop.content : undefined,
272
- source: prop.source !== undefined ? prop.source : undefined,
273
- sourceDomain: prop.sourceDomain !== undefined ? prop.sourceDomain : undefined,
274
- url: prop.url !== undefined ? prop.url : undefined,
275
- sentiment: prop.sentiment !== undefined ? prop.sentiment : undefined,
276
- authors: prop.authors !== undefined ? {
277
- set: prop.authors
278
- } : undefined,
279
- summary: prop.summary !== undefined ? prop.summary : undefined,
280
- bannerImage: prop.bannerImage !== undefined ? prop.bannerImage : undefined,
281
- timePublished: prop.timePublished !== undefined ? prop.timePublished : undefined,
282
- category: prop.category !== undefined ? prop.category : undefined,
283
- topics: prop.topics !== undefined ? {
284
- set: prop.topics
285
- } : undefined,
286
- logo: prop.logo !== undefined ? prop.logo : undefined,
287
- })),
288
- };
289
- const filteredVariables = removeUndefinedProps(variables);
290
- try {
291
- const response = await client.mutate({ mutation: CREATE_MANY_NEWSARTICLE, variables: filteredVariables });
292
- if (response.errors && response.errors.length > 0)
293
- throw new Error(response.errors[0].message);
294
- if (response && response.data && response.data.createManyNewsArticle) {
295
- return response.data.createManyNewsArticle;
296
- }
297
- else {
298
- return null;
299
- }
300
- }
301
- catch (error) {
302
- console.error('Error in createManyNewsArticle:', error);
303
- throw error;
304
- }
305
- },
306
- /**
307
- * Update a single NewsArticle record.
308
- * @param props - Properties to update.
309
- * @param globalClient - Apollo Client instance.
310
- * @returns The updated NewsArticle or null.
311
- */
312
- async update(props, globalClient) {
313
- const [modules, client] = await Promise.all([
314
- getApolloModules(),
315
- globalClient
316
- ? Promise.resolve(globalClient)
317
- : importedClient
318
- ]);
319
- const { gql, ApolloError } = modules;
320
- const UPDATE_ONE_NEWSARTICLE = gql `
321
- mutation updateOneNewsArticle($data: NewsArticleUpdateInput!, $where: NewsArticleWhereUniqueInput!) {
322
- updateOneNewsArticle(data: $data, where: $where) {
323
- ${selectionSet}
324
- }
325
- }`;
326
- const variables = {
327
- where: {
328
- id: props.id !== undefined ? props.id : undefined,
329
- url: props.url !== undefined ? props.url : undefined,
330
- title: props.title !== undefined ? {
331
- equals: props.title
332
- } : undefined,
333
- },
334
- data: {
335
- id: props.id !== undefined ? {
336
- set: props.id
337
- } : undefined,
338
- title: props.title !== undefined ? {
339
- set: props.title
340
- } : undefined,
341
- content: props.content !== undefined ? {
342
- set: props.content
343
- } : undefined,
344
- source: props.source !== undefined ? {
345
- set: props.source
346
- } : undefined,
347
- sourceDomain: props.sourceDomain !== undefined ? {
348
- set: props.sourceDomain
349
- } : undefined,
350
- url: props.url !== undefined ? {
351
- set: props.url
352
- } : undefined,
353
- sentiment: props.sentiment !== undefined ? {
354
- set: props.sentiment
355
- } : undefined,
356
- authors: props.authors !== undefined ? {
357
- set: props.authors
358
- } : undefined,
359
- summary: props.summary !== undefined ? {
360
- set: props.summary
361
- } : undefined,
362
- bannerImage: props.bannerImage !== undefined ? {
363
- set: props.bannerImage
364
- } : undefined,
365
- timePublished: props.timePublished !== undefined ? {
366
- set: props.timePublished
367
- } : undefined,
368
- category: props.category !== undefined ? {
369
- set: props.category
370
- } : undefined,
371
- topics: props.topics !== undefined ? {
372
- set: props.topics
373
- } : undefined,
374
- logo: props.logo !== undefined ? {
375
- set: props.logo
376
- } : undefined,
377
- createdAt: props.createdAt !== undefined ? {
378
- set: props.createdAt
379
- } : undefined,
380
- updatedAt: props.updatedAt !== undefined ? {
381
- set: props.updatedAt
382
- } : undefined,
383
- assets: props.assets ?
384
- Array.isArray(props.assets) && props.assets.length > 0 && props.assets.every((item) => typeof item === 'object' && ('id' in item || 'symbol' in item) && Object.keys(item).length === 1) ? {
385
- connect: props.assets.map((item) => ({
386
- id: item.id
387
- }))
388
- } : { upsert: props.assets.map((item) => ({
389
- where: {
390
- id: item.id !== undefined ? item.id : undefined,
391
- url: item.url !== undefined ? item.url : undefined,
392
- assetId: item.assetId !== undefined ? {
393
- equals: item.assetId
394
- } : undefined,
395
- newsArticleId: item.newsArticleId !== undefined ? {
396
- equals: item.newsArticleId
397
- } : undefined,
398
- },
399
- update: {
400
- id: item.id !== undefined ? {
401
- set: item.id
402
- } : undefined,
403
- url: item.url !== undefined ? {
404
- set: item.url
405
- } : undefined,
406
- relevancyScore: item.relevancyScore !== undefined ? {
407
- set: item.relevancyScore
408
- } : undefined,
409
- sentimentScore: item.sentimentScore !== undefined ? {
410
- set: item.sentimentScore
411
- } : undefined,
412
- sentimentLabel: item.sentimentLabel !== undefined ? {
413
- set: item.sentimentLabel
414
- } : undefined,
415
- asset: item.asset ?
416
- typeof item.asset === 'object' && Object.keys(item.asset).length === 1 && (Object.keys(item.asset)[0] === 'id' || Object.keys(item.asset)[0] === 'symbol')
417
- ? {
418
- connect: {
419
- id: item.asset.id
420
- }
421
- } : { upsert: {
422
- where: {
423
- id: item.asset.id !== undefined ? {
424
- equals: item.asset.id
425
- } : undefined,
426
- symbol: item.asset.symbol !== undefined ? {
427
- equals: item.asset.symbol
428
- } : undefined,
429
- name: item.asset.name !== undefined ? {
430
- equals: item.asset.name
431
- } : undefined,
432
- },
433
- update: {
434
- id: item.asset.id !== undefined ? {
435
- set: item.asset.id
436
- } : undefined,
437
- symbol: item.asset.symbol !== undefined ? {
438
- set: item.asset.symbol
439
- } : undefined,
440
- name: item.asset.name !== undefined ? {
441
- set: item.asset.name
442
- } : undefined,
443
- type: item.asset.type !== undefined ? {
444
- set: item.asset.type
445
- } : undefined,
446
- logoUrl: item.asset.logoUrl !== undefined ? {
447
- set: item.asset.logoUrl
448
- } : undefined,
449
- description: item.asset.description !== undefined ? {
450
- set: item.asset.description
451
- } : undefined,
452
- cik: item.asset.cik !== undefined ? {
453
- set: item.asset.cik
454
- } : undefined,
455
- exchange: item.asset.exchange !== undefined ? {
456
- set: item.asset.exchange
457
- } : undefined,
458
- currency: item.asset.currency !== undefined ? {
459
- set: item.asset.currency
460
- } : undefined,
461
- country: item.asset.country !== undefined ? {
462
- set: item.asset.country
463
- } : undefined,
464
- sector: item.asset.sector !== undefined ? {
465
- set: item.asset.sector
466
- } : undefined,
467
- industry: item.asset.industry !== undefined ? {
468
- set: item.asset.industry
469
- } : undefined,
470
- address: item.asset.address !== undefined ? {
471
- set: item.asset.address
472
- } : undefined,
473
- officialSite: item.asset.officialSite !== undefined ? {
474
- set: item.asset.officialSite
475
- } : undefined,
476
- fiscalYearEnd: item.asset.fiscalYearEnd !== undefined ? {
477
- set: item.asset.fiscalYearEnd
478
- } : undefined,
479
- latestQuarter: item.asset.latestQuarter !== undefined ? {
480
- set: item.asset.latestQuarter
481
- } : undefined,
482
- marketCapitalization: item.asset.marketCapitalization !== undefined ? {
483
- set: item.asset.marketCapitalization
484
- } : undefined,
485
- ebitda: item.asset.ebitda !== undefined ? {
486
- set: item.asset.ebitda
487
- } : undefined,
488
- peRatio: item.asset.peRatio !== undefined ? {
489
- set: item.asset.peRatio
490
- } : undefined,
491
- pegRatio: item.asset.pegRatio !== undefined ? {
492
- set: item.asset.pegRatio
493
- } : undefined,
494
- bookValue: item.asset.bookValue !== undefined ? {
495
- set: item.asset.bookValue
496
- } : undefined,
497
- dividendPerShare: item.asset.dividendPerShare !== undefined ? {
498
- set: item.asset.dividendPerShare
499
- } : undefined,
500
- dividendYield: item.asset.dividendYield !== undefined ? {
501
- set: item.asset.dividendYield
502
- } : undefined,
503
- eps: item.asset.eps !== undefined ? {
504
- set: item.asset.eps
505
- } : undefined,
506
- revenuePerShareTTM: item.asset.revenuePerShareTTM !== undefined ? {
507
- set: item.asset.revenuePerShareTTM
508
- } : undefined,
509
- profitMargin: item.asset.profitMargin !== undefined ? {
510
- set: item.asset.profitMargin
511
- } : undefined,
512
- operatingMarginTTM: item.asset.operatingMarginTTM !== undefined ? {
513
- set: item.asset.operatingMarginTTM
514
- } : undefined,
515
- returnOnAssetsTTM: item.asset.returnOnAssetsTTM !== undefined ? {
516
- set: item.asset.returnOnAssetsTTM
517
- } : undefined,
518
- returnOnEquityTTM: item.asset.returnOnEquityTTM !== undefined ? {
519
- set: item.asset.returnOnEquityTTM
520
- } : undefined,
521
- revenueTTM: item.asset.revenueTTM !== undefined ? {
522
- set: item.asset.revenueTTM
523
- } : undefined,
524
- grossProfitTTM: item.asset.grossProfitTTM !== undefined ? {
525
- set: item.asset.grossProfitTTM
526
- } : undefined,
527
- dilutedEPSTTM: item.asset.dilutedEPSTTM !== undefined ? {
528
- set: item.asset.dilutedEPSTTM
529
- } : undefined,
530
- quarterlyEarningsGrowthYOY: item.asset.quarterlyEarningsGrowthYOY !== undefined ? {
531
- set: item.asset.quarterlyEarningsGrowthYOY
532
- } : undefined,
533
- quarterlyRevenueGrowthYOY: item.asset.quarterlyRevenueGrowthYOY !== undefined ? {
534
- set: item.asset.quarterlyRevenueGrowthYOY
535
- } : undefined,
536
- analystTargetPrice: item.asset.analystTargetPrice !== undefined ? {
537
- set: item.asset.analystTargetPrice
538
- } : undefined,
539
- analystRatingStrongBuy: item.asset.analystRatingStrongBuy !== undefined ? {
540
- set: item.asset.analystRatingStrongBuy
541
- } : undefined,
542
- analystRatingBuy: item.asset.analystRatingBuy !== undefined ? {
543
- set: item.asset.analystRatingBuy
544
- } : undefined,
545
- analystRatingHold: item.asset.analystRatingHold !== undefined ? {
546
- set: item.asset.analystRatingHold
547
- } : undefined,
548
- analystRatingSell: item.asset.analystRatingSell !== undefined ? {
549
- set: item.asset.analystRatingSell
550
- } : undefined,
551
- analystRatingStrongSell: item.asset.analystRatingStrongSell !== undefined ? {
552
- set: item.asset.analystRatingStrongSell
553
- } : undefined,
554
- trailingPE: item.asset.trailingPE !== undefined ? {
555
- set: item.asset.trailingPE
556
- } : undefined,
557
- forwardPE: item.asset.forwardPE !== undefined ? {
558
- set: item.asset.forwardPE
559
- } : undefined,
560
- priceToSalesRatioTTM: item.asset.priceToSalesRatioTTM !== undefined ? {
561
- set: item.asset.priceToSalesRatioTTM
562
- } : undefined,
563
- priceToBookRatio: item.asset.priceToBookRatio !== undefined ? {
564
- set: item.asset.priceToBookRatio
565
- } : undefined,
566
- evToRevenue: item.asset.evToRevenue !== undefined ? {
567
- set: item.asset.evToRevenue
568
- } : undefined,
569
- evToEbitda: item.asset.evToEbitda !== undefined ? {
570
- set: item.asset.evToEbitda
571
- } : undefined,
572
- beta: item.asset.beta !== undefined ? {
573
- set: item.asset.beta
574
- } : undefined,
575
- week52High: item.asset.week52High !== undefined ? {
576
- set: item.asset.week52High
577
- } : undefined,
578
- week52Low: item.asset.week52Low !== undefined ? {
579
- set: item.asset.week52Low
580
- } : undefined,
581
- day50MovingAverage: item.asset.day50MovingAverage !== undefined ? {
582
- set: item.asset.day50MovingAverage
583
- } : undefined,
584
- day200MovingAverage: item.asset.day200MovingAverage !== undefined ? {
585
- set: item.asset.day200MovingAverage
586
- } : undefined,
587
- sharesOutstanding: item.asset.sharesOutstanding !== undefined ? {
588
- set: item.asset.sharesOutstanding
589
- } : undefined,
590
- dividendDate: item.asset.dividendDate !== undefined ? {
591
- set: item.asset.dividendDate
592
- } : undefined,
593
- exDividendDate: item.asset.exDividendDate !== undefined ? {
594
- set: item.asset.exDividendDate
595
- } : undefined,
596
- askPrice: item.asset.askPrice !== undefined ? {
597
- set: item.asset.askPrice
598
- } : undefined,
599
- bidPrice: item.asset.bidPrice !== undefined ? {
600
- set: item.asset.bidPrice
601
- } : undefined,
602
- },
603
- create: {
604
- symbol: item.asset.symbol !== undefined ? item.asset.symbol : undefined,
605
- name: item.asset.name !== undefined ? item.asset.name : undefined,
606
- type: item.asset.type !== undefined ? item.asset.type : undefined,
607
- logoUrl: item.asset.logoUrl !== undefined ? item.asset.logoUrl : undefined,
608
- description: item.asset.description !== undefined ? item.asset.description : undefined,
609
- cik: item.asset.cik !== undefined ? item.asset.cik : undefined,
610
- exchange: item.asset.exchange !== undefined ? item.asset.exchange : undefined,
611
- currency: item.asset.currency !== undefined ? item.asset.currency : undefined,
612
- country: item.asset.country !== undefined ? item.asset.country : undefined,
613
- sector: item.asset.sector !== undefined ? item.asset.sector : undefined,
614
- industry: item.asset.industry !== undefined ? item.asset.industry : undefined,
615
- address: item.asset.address !== undefined ? item.asset.address : undefined,
616
- officialSite: item.asset.officialSite !== undefined ? item.asset.officialSite : undefined,
617
- fiscalYearEnd: item.asset.fiscalYearEnd !== undefined ? item.asset.fiscalYearEnd : undefined,
618
- latestQuarter: item.asset.latestQuarter !== undefined ? item.asset.latestQuarter : undefined,
619
- marketCapitalization: item.asset.marketCapitalization !== undefined ? item.asset.marketCapitalization : undefined,
620
- ebitda: item.asset.ebitda !== undefined ? item.asset.ebitda : undefined,
621
- peRatio: item.asset.peRatio !== undefined ? item.asset.peRatio : undefined,
622
- pegRatio: item.asset.pegRatio !== undefined ? item.asset.pegRatio : undefined,
623
- bookValue: item.asset.bookValue !== undefined ? item.asset.bookValue : undefined,
624
- dividendPerShare: item.asset.dividendPerShare !== undefined ? item.asset.dividendPerShare : undefined,
625
- dividendYield: item.asset.dividendYield !== undefined ? item.asset.dividendYield : undefined,
626
- eps: item.asset.eps !== undefined ? item.asset.eps : undefined,
627
- revenuePerShareTTM: item.asset.revenuePerShareTTM !== undefined ? item.asset.revenuePerShareTTM : undefined,
628
- profitMargin: item.asset.profitMargin !== undefined ? item.asset.profitMargin : undefined,
629
- operatingMarginTTM: item.asset.operatingMarginTTM !== undefined ? item.asset.operatingMarginTTM : undefined,
630
- returnOnAssetsTTM: item.asset.returnOnAssetsTTM !== undefined ? item.asset.returnOnAssetsTTM : undefined,
631
- returnOnEquityTTM: item.asset.returnOnEquityTTM !== undefined ? item.asset.returnOnEquityTTM : undefined,
632
- revenueTTM: item.asset.revenueTTM !== undefined ? item.asset.revenueTTM : undefined,
633
- grossProfitTTM: item.asset.grossProfitTTM !== undefined ? item.asset.grossProfitTTM : undefined,
634
- dilutedEPSTTM: item.asset.dilutedEPSTTM !== undefined ? item.asset.dilutedEPSTTM : undefined,
635
- quarterlyEarningsGrowthYOY: item.asset.quarterlyEarningsGrowthYOY !== undefined ? item.asset.quarterlyEarningsGrowthYOY : undefined,
636
- quarterlyRevenueGrowthYOY: item.asset.quarterlyRevenueGrowthYOY !== undefined ? item.asset.quarterlyRevenueGrowthYOY : undefined,
637
- analystTargetPrice: item.asset.analystTargetPrice !== undefined ? item.asset.analystTargetPrice : undefined,
638
- analystRatingStrongBuy: item.asset.analystRatingStrongBuy !== undefined ? item.asset.analystRatingStrongBuy : undefined,
639
- analystRatingBuy: item.asset.analystRatingBuy !== undefined ? item.asset.analystRatingBuy : undefined,
640
- analystRatingHold: item.asset.analystRatingHold !== undefined ? item.asset.analystRatingHold : undefined,
641
- analystRatingSell: item.asset.analystRatingSell !== undefined ? item.asset.analystRatingSell : undefined,
642
- analystRatingStrongSell: item.asset.analystRatingStrongSell !== undefined ? item.asset.analystRatingStrongSell : undefined,
643
- trailingPE: item.asset.trailingPE !== undefined ? item.asset.trailingPE : undefined,
644
- forwardPE: item.asset.forwardPE !== undefined ? item.asset.forwardPE : undefined,
645
- priceToSalesRatioTTM: item.asset.priceToSalesRatioTTM !== undefined ? item.asset.priceToSalesRatioTTM : undefined,
646
- priceToBookRatio: item.asset.priceToBookRatio !== undefined ? item.asset.priceToBookRatio : undefined,
647
- evToRevenue: item.asset.evToRevenue !== undefined ? item.asset.evToRevenue : undefined,
648
- evToEbitda: item.asset.evToEbitda !== undefined ? item.asset.evToEbitda : undefined,
649
- beta: item.asset.beta !== undefined ? item.asset.beta : undefined,
650
- week52High: item.asset.week52High !== undefined ? item.asset.week52High : undefined,
651
- week52Low: item.asset.week52Low !== undefined ? item.asset.week52Low : undefined,
652
- day50MovingAverage: item.asset.day50MovingAverage !== undefined ? item.asset.day50MovingAverage : undefined,
653
- day200MovingAverage: item.asset.day200MovingAverage !== undefined ? item.asset.day200MovingAverage : undefined,
654
- sharesOutstanding: item.asset.sharesOutstanding !== undefined ? item.asset.sharesOutstanding : undefined,
655
- dividendDate: item.asset.dividendDate !== undefined ? item.asset.dividendDate : undefined,
656
- exDividendDate: item.asset.exDividendDate !== undefined ? item.asset.exDividendDate : undefined,
657
- askPrice: item.asset.askPrice !== undefined ? item.asset.askPrice : undefined,
658
- bidPrice: item.asset.bidPrice !== undefined ? item.asset.bidPrice : undefined,
659
- },
660
- }
661
- } : undefined,
662
- },
663
- create: {
664
- url: item.url !== undefined ? item.url : undefined,
665
- relevancyScore: item.relevancyScore !== undefined ? item.relevancyScore : undefined,
666
- sentimentScore: item.sentimentScore !== undefined ? item.sentimentScore : undefined,
667
- sentimentLabel: item.sentimentLabel !== undefined ? item.sentimentLabel : undefined,
668
- asset: item.asset ?
669
- typeof item.asset === 'object' && Object.keys(item.asset).length === 1 && Object.keys(item.asset)[0] === 'id'
670
- ? { connect: {
671
- id: item.asset.id
672
- }
673
- }
674
- : { connectOrCreate: {
675
- where: {
676
- id: item.asset.id !== undefined ? item.asset.id : undefined,
677
- symbol: item.asset.symbol !== undefined ? item.asset.symbol : undefined,
678
- name: item.asset.name !== undefined ? item.asset.name : undefined,
679
- },
680
- create: {
681
- symbol: item.asset.symbol !== undefined ? item.asset.symbol : undefined,
682
- name: item.asset.name !== undefined ? item.asset.name : undefined,
683
- type: item.asset.type !== undefined ? item.asset.type : undefined,
684
- logoUrl: item.asset.logoUrl !== undefined ? item.asset.logoUrl : undefined,
685
- description: item.asset.description !== undefined ? item.asset.description : undefined,
686
- cik: item.asset.cik !== undefined ? item.asset.cik : undefined,
687
- exchange: item.asset.exchange !== undefined ? item.asset.exchange : undefined,
688
- currency: item.asset.currency !== undefined ? item.asset.currency : undefined,
689
- country: item.asset.country !== undefined ? item.asset.country : undefined,
690
- sector: item.asset.sector !== undefined ? item.asset.sector : undefined,
691
- industry: item.asset.industry !== undefined ? item.asset.industry : undefined,
692
- address: item.asset.address !== undefined ? item.asset.address : undefined,
693
- officialSite: item.asset.officialSite !== undefined ? item.asset.officialSite : undefined,
694
- fiscalYearEnd: item.asset.fiscalYearEnd !== undefined ? item.asset.fiscalYearEnd : undefined,
695
- latestQuarter: item.asset.latestQuarter !== undefined ? item.asset.latestQuarter : undefined,
696
- marketCapitalization: item.asset.marketCapitalization !== undefined ? item.asset.marketCapitalization : undefined,
697
- ebitda: item.asset.ebitda !== undefined ? item.asset.ebitda : undefined,
698
- peRatio: item.asset.peRatio !== undefined ? item.asset.peRatio : undefined,
699
- pegRatio: item.asset.pegRatio !== undefined ? item.asset.pegRatio : undefined,
700
- bookValue: item.asset.bookValue !== undefined ? item.asset.bookValue : undefined,
701
- dividendPerShare: item.asset.dividendPerShare !== undefined ? item.asset.dividendPerShare : undefined,
702
- dividendYield: item.asset.dividendYield !== undefined ? item.asset.dividendYield : undefined,
703
- eps: item.asset.eps !== undefined ? item.asset.eps : undefined,
704
- revenuePerShareTTM: item.asset.revenuePerShareTTM !== undefined ? item.asset.revenuePerShareTTM : undefined,
705
- profitMargin: item.asset.profitMargin !== undefined ? item.asset.profitMargin : undefined,
706
- operatingMarginTTM: item.asset.operatingMarginTTM !== undefined ? item.asset.operatingMarginTTM : undefined,
707
- returnOnAssetsTTM: item.asset.returnOnAssetsTTM !== undefined ? item.asset.returnOnAssetsTTM : undefined,
708
- returnOnEquityTTM: item.asset.returnOnEquityTTM !== undefined ? item.asset.returnOnEquityTTM : undefined,
709
- revenueTTM: item.asset.revenueTTM !== undefined ? item.asset.revenueTTM : undefined,
710
- grossProfitTTM: item.asset.grossProfitTTM !== undefined ? item.asset.grossProfitTTM : undefined,
711
- dilutedEPSTTM: item.asset.dilutedEPSTTM !== undefined ? item.asset.dilutedEPSTTM : undefined,
712
- quarterlyEarningsGrowthYOY: item.asset.quarterlyEarningsGrowthYOY !== undefined ? item.asset.quarterlyEarningsGrowthYOY : undefined,
713
- quarterlyRevenueGrowthYOY: item.asset.quarterlyRevenueGrowthYOY !== undefined ? item.asset.quarterlyRevenueGrowthYOY : undefined,
714
- analystTargetPrice: item.asset.analystTargetPrice !== undefined ? item.asset.analystTargetPrice : undefined,
715
- analystRatingStrongBuy: item.asset.analystRatingStrongBuy !== undefined ? item.asset.analystRatingStrongBuy : undefined,
716
- analystRatingBuy: item.asset.analystRatingBuy !== undefined ? item.asset.analystRatingBuy : undefined,
717
- analystRatingHold: item.asset.analystRatingHold !== undefined ? item.asset.analystRatingHold : undefined,
718
- analystRatingSell: item.asset.analystRatingSell !== undefined ? item.asset.analystRatingSell : undefined,
719
- analystRatingStrongSell: item.asset.analystRatingStrongSell !== undefined ? item.asset.analystRatingStrongSell : undefined,
720
- trailingPE: item.asset.trailingPE !== undefined ? item.asset.trailingPE : undefined,
721
- forwardPE: item.asset.forwardPE !== undefined ? item.asset.forwardPE : undefined,
722
- priceToSalesRatioTTM: item.asset.priceToSalesRatioTTM !== undefined ? item.asset.priceToSalesRatioTTM : undefined,
723
- priceToBookRatio: item.asset.priceToBookRatio !== undefined ? item.asset.priceToBookRatio : undefined,
724
- evToRevenue: item.asset.evToRevenue !== undefined ? item.asset.evToRevenue : undefined,
725
- evToEbitda: item.asset.evToEbitda !== undefined ? item.asset.evToEbitda : undefined,
726
- beta: item.asset.beta !== undefined ? item.asset.beta : undefined,
727
- week52High: item.asset.week52High !== undefined ? item.asset.week52High : undefined,
728
- week52Low: item.asset.week52Low !== undefined ? item.asset.week52Low : undefined,
729
- day50MovingAverage: item.asset.day50MovingAverage !== undefined ? item.asset.day50MovingAverage : undefined,
730
- day200MovingAverage: item.asset.day200MovingAverage !== undefined ? item.asset.day200MovingAverage : undefined,
731
- sharesOutstanding: item.asset.sharesOutstanding !== undefined ? item.asset.sharesOutstanding : undefined,
732
- dividendDate: item.asset.dividendDate !== undefined ? item.asset.dividendDate : undefined,
733
- exDividendDate: item.asset.exDividendDate !== undefined ? item.asset.exDividendDate : undefined,
734
- askPrice: item.asset.askPrice !== undefined ? item.asset.askPrice : undefined,
735
- bidPrice: item.asset.bidPrice !== undefined ? item.asset.bidPrice : undefined,
736
- },
737
- }
738
- } : undefined,
739
- },
740
- }))
741
- } : undefined,
742
- },
743
- };
744
- const filteredVariables = removeUndefinedProps(variables);
745
- try {
746
- const response = await client.mutate({ mutation: UPDATE_ONE_NEWSARTICLE, variables: filteredVariables });
747
- if (response.errors && response.errors.length > 0)
748
- throw new Error(response.errors[0].message);
749
- if (response && response.data && response.data.updateOneNewsArticle) {
750
- return response.data.updateOneNewsArticle;
736
+ },
737
+ create: {
738
+ url: item.url !== undefined ? item.url : undefined,
739
+ relevancyScore: item.relevancyScore !== undefined ? item.relevancyScore : undefined,
740
+ sentimentScore: item.sentimentScore !== undefined ? item.sentimentScore : undefined,
741
+ sentimentLabel: item.sentimentLabel !== undefined ? item.sentimentLabel : undefined,
742
+ asset: item.asset ?
743
+ typeof item.asset === 'object' && Object.keys(item.asset).length === 1 && Object.keys(item.asset)[0] === 'id'
744
+ ? { connect: {
745
+ id: item.asset.id
746
+ }
747
+ }
748
+ : { connectOrCreate: {
749
+ where: {
750
+ id: item.asset.id !== undefined ? item.asset.id : undefined,
751
+ symbol: item.asset.symbol !== undefined ? item.asset.symbol : undefined,
752
+ name: item.asset.name !== undefined ? item.asset.name : undefined,
753
+ },
754
+ create: {
755
+ symbol: item.asset.symbol !== undefined ? item.asset.symbol : undefined,
756
+ name: item.asset.name !== undefined ? item.asset.name : undefined,
757
+ type: item.asset.type !== undefined ? item.asset.type : undefined,
758
+ logoUrl: item.asset.logoUrl !== undefined ? item.asset.logoUrl : undefined,
759
+ description: item.asset.description !== undefined ? item.asset.description : undefined,
760
+ cik: item.asset.cik !== undefined ? item.asset.cik : undefined,
761
+ exchange: item.asset.exchange !== undefined ? item.asset.exchange : undefined,
762
+ currency: item.asset.currency !== undefined ? item.asset.currency : undefined,
763
+ country: item.asset.country !== undefined ? item.asset.country : undefined,
764
+ sector: item.asset.sector !== undefined ? item.asset.sector : undefined,
765
+ industry: item.asset.industry !== undefined ? item.asset.industry : undefined,
766
+ address: item.asset.address !== undefined ? item.asset.address : undefined,
767
+ officialSite: item.asset.officialSite !== undefined ? item.asset.officialSite : undefined,
768
+ fiscalYearEnd: item.asset.fiscalYearEnd !== undefined ? item.asset.fiscalYearEnd : undefined,
769
+ latestQuarter: item.asset.latestQuarter !== undefined ? item.asset.latestQuarter : undefined,
770
+ marketCapitalization: item.asset.marketCapitalization !== undefined ? item.asset.marketCapitalization : undefined,
771
+ ebitda: item.asset.ebitda !== undefined ? item.asset.ebitda : undefined,
772
+ peRatio: item.asset.peRatio !== undefined ? item.asset.peRatio : undefined,
773
+ pegRatio: item.asset.pegRatio !== undefined ? item.asset.pegRatio : undefined,
774
+ bookValue: item.asset.bookValue !== undefined ? item.asset.bookValue : undefined,
775
+ dividendPerShare: item.asset.dividendPerShare !== undefined ? item.asset.dividendPerShare : undefined,
776
+ dividendYield: item.asset.dividendYield !== undefined ? item.asset.dividendYield : undefined,
777
+ eps: item.asset.eps !== undefined ? item.asset.eps : undefined,
778
+ revenuePerShareTTM: item.asset.revenuePerShareTTM !== undefined ? item.asset.revenuePerShareTTM : undefined,
779
+ profitMargin: item.asset.profitMargin !== undefined ? item.asset.profitMargin : undefined,
780
+ operatingMarginTTM: item.asset.operatingMarginTTM !== undefined ? item.asset.operatingMarginTTM : undefined,
781
+ returnOnAssetsTTM: item.asset.returnOnAssetsTTM !== undefined ? item.asset.returnOnAssetsTTM : undefined,
782
+ returnOnEquityTTM: item.asset.returnOnEquityTTM !== undefined ? item.asset.returnOnEquityTTM : undefined,
783
+ revenueTTM: item.asset.revenueTTM !== undefined ? item.asset.revenueTTM : undefined,
784
+ grossProfitTTM: item.asset.grossProfitTTM !== undefined ? item.asset.grossProfitTTM : undefined,
785
+ dilutedEPSTTM: item.asset.dilutedEPSTTM !== undefined ? item.asset.dilutedEPSTTM : undefined,
786
+ quarterlyEarningsGrowthYOY: item.asset.quarterlyEarningsGrowthYOY !== undefined ? item.asset.quarterlyEarningsGrowthYOY : undefined,
787
+ quarterlyRevenueGrowthYOY: item.asset.quarterlyRevenueGrowthYOY !== undefined ? item.asset.quarterlyRevenueGrowthYOY : undefined,
788
+ analystTargetPrice: item.asset.analystTargetPrice !== undefined ? item.asset.analystTargetPrice : undefined,
789
+ analystRatingStrongBuy: item.asset.analystRatingStrongBuy !== undefined ? item.asset.analystRatingStrongBuy : undefined,
790
+ analystRatingBuy: item.asset.analystRatingBuy !== undefined ? item.asset.analystRatingBuy : undefined,
791
+ analystRatingHold: item.asset.analystRatingHold !== undefined ? item.asset.analystRatingHold : undefined,
792
+ analystRatingSell: item.asset.analystRatingSell !== undefined ? item.asset.analystRatingSell : undefined,
793
+ analystRatingStrongSell: item.asset.analystRatingStrongSell !== undefined ? item.asset.analystRatingStrongSell : undefined,
794
+ trailingPE: item.asset.trailingPE !== undefined ? item.asset.trailingPE : undefined,
795
+ forwardPE: item.asset.forwardPE !== undefined ? item.asset.forwardPE : undefined,
796
+ priceToSalesRatioTTM: item.asset.priceToSalesRatioTTM !== undefined ? item.asset.priceToSalesRatioTTM : undefined,
797
+ priceToBookRatio: item.asset.priceToBookRatio !== undefined ? item.asset.priceToBookRatio : undefined,
798
+ evToRevenue: item.asset.evToRevenue !== undefined ? item.asset.evToRevenue : undefined,
799
+ evToEbitda: item.asset.evToEbitda !== undefined ? item.asset.evToEbitda : undefined,
800
+ beta: item.asset.beta !== undefined ? item.asset.beta : undefined,
801
+ week52High: item.asset.week52High !== undefined ? item.asset.week52High : undefined,
802
+ week52Low: item.asset.week52Low !== undefined ? item.asset.week52Low : undefined,
803
+ day50MovingAverage: item.asset.day50MovingAverage !== undefined ? item.asset.day50MovingAverage : undefined,
804
+ day200MovingAverage: item.asset.day200MovingAverage !== undefined ? item.asset.day200MovingAverage : undefined,
805
+ sharesOutstanding: item.asset.sharesOutstanding !== undefined ? item.asset.sharesOutstanding : undefined,
806
+ dividendDate: item.asset.dividendDate !== undefined ? item.asset.dividendDate : undefined,
807
+ exDividendDate: item.asset.exDividendDate !== undefined ? item.asset.exDividendDate : undefined,
808
+ askPrice: item.asset.askPrice !== undefined ? item.asset.askPrice : undefined,
809
+ bidPrice: item.asset.bidPrice !== undefined ? item.asset.bidPrice : undefined,
810
+ },
811
+ }
812
+ } : undefined,
813
+ },
814
+ }))
815
+ } : undefined,
816
+ },
817
+ };
818
+ const filteredVariables = removeUndefinedProps(variables);
819
+ const response = await client.mutate({
820
+ mutation: UPDATE_ONE_NEWSARTICLE,
821
+ variables: filteredVariables,
822
+ // Don't cache mutations, but ensure we're using the freshest context
823
+ fetchPolicy: 'no-cache'
824
+ });
825
+ if (response.errors && response.errors.length > 0)
826
+ throw new Error(response.errors[0].message);
827
+ if (response && response.data && response.data.updateOneNewsArticle) {
828
+ return response.data.updateOneNewsArticle;
829
+ }
830
+ else {
831
+ return null;
832
+ }
751
833
  }
752
- else {
753
- return null;
834
+ catch (error) {
835
+ lastError = error;
836
+ // Check if this is a database connection error that we should retry
837
+ const isConnectionError = error.message?.includes('Server has closed the connection') ||
838
+ error.message?.includes('Cannot reach database server') ||
839
+ error.message?.includes('Connection timed out') ||
840
+ error.message?.includes('Accelerate') || // Prisma Accelerate proxy errors
841
+ (error.networkError && error.networkError.message?.includes('Failed to fetch'));
842
+ if (isConnectionError && retryCount < MAX_RETRIES - 1) {
843
+ retryCount++;
844
+ const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
845
+ console.warn("Database connection error, retrying...");
846
+ await new Promise(resolve => setTimeout(resolve, delay));
847
+ continue;
848
+ }
849
+ // Log the error and rethrow
850
+ console.error("Database error occurred:", error);
851
+ throw error;
754
852
  }
755
853
  }
756
- catch (error) {
757
- console.error('Error in updateOneNewsArticle:', error);
758
- throw error;
759
- }
854
+ // If we exhausted retries, throw the last error
855
+ throw lastError;
760
856
  },
761
857
  /**
762
858
  * Upsert a single NewsArticle record.
859
+ * Enhanced with connection resilience against Prisma connection errors.
763
860
  * @param props - Properties to update.
764
861
  * @param globalClient - Apollo Client instance.
765
862
  * @returns The updated NewsArticle or null.
766
863
  */
767
864
  async upsert(props, globalClient) {
768
- const [modules, client] = await Promise.all([
769
- getApolloModules(),
770
- globalClient
771
- ? Promise.resolve(globalClient)
772
- : importedClient
773
- ]);
774
- const { gql, ApolloError } = modules;
775
- const UPSERT_ONE_NEWSARTICLE = gql `
776
- mutation upsertOneNewsArticle($where: NewsArticleWhereUniqueInput!, $create: NewsArticleCreateInput!, $update: NewsArticleUpdateInput!) {
777
- upsertOneNewsArticle(where: $where, create: $create, update: $update) {
778
- ${selectionSet}
779
- }
780
- }`;
781
- const variables = {
782
- where: {
783
- id: props.id !== undefined ? props.id : undefined,
784
- url: props.url !== undefined ? props.url : undefined,
785
- title: props.title !== undefined ? {
786
- equals: props.title
787
- } : undefined,
788
- },
789
- create: {
790
- title: props.title !== undefined ? props.title : undefined,
791
- content: props.content !== undefined ? props.content : undefined,
792
- source: props.source !== undefined ? props.source : undefined,
793
- sourceDomain: props.sourceDomain !== undefined ? props.sourceDomain : undefined,
794
- url: props.url !== undefined ? props.url : undefined,
795
- sentiment: props.sentiment !== undefined ? props.sentiment : undefined,
796
- authors: props.authors !== undefined ? {
797
- set: props.authors
798
- } : undefined,
799
- summary: props.summary !== undefined ? props.summary : undefined,
800
- bannerImage: props.bannerImage !== undefined ? props.bannerImage : undefined,
801
- timePublished: props.timePublished !== undefined ? props.timePublished : undefined,
802
- category: props.category !== undefined ? props.category : undefined,
803
- topics: props.topics !== undefined ? {
804
- set: props.topics
805
- } : undefined,
806
- logo: props.logo !== undefined ? props.logo : undefined,
807
- assets: props.assets ?
808
- Array.isArray(props.assets) && props.assets.length > 0 && props.assets.every((item) => typeof item === 'object' && 'id' in item && Object.keys(item).length === 1) ? {
809
- connect: props.assets.map((item) => ({
810
- id: item.id
811
- }))
812
- }
813
- : { connectOrCreate: props.assets.map((item) => ({
814
- where: {
815
- id: item.id !== undefined ? item.id : undefined,
816
- url: item.url !== undefined ? item.url : undefined,
817
- newsArticleId: item.newsArticleId !== undefined ? {
818
- equals: item.newsArticleId
819
- } : undefined,
820
- },
821
- create: {
822
- url: item.url !== undefined ? item.url : undefined,
823
- relevancyScore: item.relevancyScore !== undefined ? item.relevancyScore : undefined,
824
- sentimentScore: item.sentimentScore !== undefined ? item.sentimentScore : undefined,
825
- sentimentLabel: item.sentimentLabel !== undefined ? item.sentimentLabel : undefined,
826
- asset: item.asset ?
827
- typeof item.asset === 'object' && Object.keys(item.asset).length === 1 && Object.keys(item.asset)[0] === 'id'
828
- ? { connect: {
829
- id: item.asset.id
830
- }
831
- }
832
- : { connectOrCreate: {
865
+ // Maximum number of retries for database connection issues
866
+ const MAX_RETRIES = 3;
867
+ let retryCount = 0;
868
+ let lastError = null;
869
+ // Retry loop to handle potential database connection issues
870
+ while (retryCount < MAX_RETRIES) {
871
+ try {
872
+ const [modules, client] = await Promise.all([
873
+ getApolloModules(),
874
+ globalClient
875
+ ? Promise.resolve(globalClient)
876
+ : importedClient
877
+ ]);
878
+ const { gql, ApolloError } = modules;
879
+ const UPSERT_ONE_NEWSARTICLE = gql `
880
+ mutation upsertOneNewsArticle($where: NewsArticleWhereUniqueInput!, $create: NewsArticleCreateInput!, $update: NewsArticleUpdateInput!) {
881
+ upsertOneNewsArticle(where: $where, create: $create, update: $update) {
882
+ ${selectionSet}
883
+ }
884
+ }`;
885
+ const variables = {
886
+ where: {
887
+ id: props.id !== undefined ? props.id : undefined,
888
+ url: props.url !== undefined ? props.url : undefined,
889
+ title: props.title !== undefined ? {
890
+ equals: props.title
891
+ } : undefined,
892
+ },
893
+ create: {
894
+ title: props.title !== undefined ? props.title : undefined,
895
+ content: props.content !== undefined ? props.content : undefined,
896
+ source: props.source !== undefined ? props.source : undefined,
897
+ sourceDomain: props.sourceDomain !== undefined ? props.sourceDomain : undefined,
898
+ url: props.url !== undefined ? props.url : undefined,
899
+ sentiment: props.sentiment !== undefined ? props.sentiment : undefined,
900
+ authors: props.authors !== undefined ? {
901
+ set: props.authors
902
+ } : undefined,
903
+ summary: props.summary !== undefined ? props.summary : undefined,
904
+ bannerImage: props.bannerImage !== undefined ? props.bannerImage : undefined,
905
+ timePublished: props.timePublished !== undefined ? props.timePublished : undefined,
906
+ category: props.category !== undefined ? props.category : undefined,
907
+ topics: props.topics !== undefined ? {
908
+ set: props.topics
909
+ } : undefined,
910
+ logo: props.logo !== undefined ? props.logo : undefined,
911
+ assets: props.assets ?
912
+ Array.isArray(props.assets) && props.assets.length > 0 && props.assets.every((item) => typeof item === 'object' && 'id' in item && Object.keys(item).length === 1) ? {
913
+ connect: props.assets.map((item) => ({
914
+ id: item.id
915
+ }))
916
+ }
917
+ : { connectOrCreate: props.assets.map((item) => ({
918
+ where: {
919
+ id: item.id !== undefined ? item.id : undefined,
920
+ url: item.url !== undefined ? item.url : undefined,
921
+ newsArticleId: item.newsArticleId !== undefined ? {
922
+ equals: item.newsArticleId
923
+ } : undefined,
924
+ },
925
+ create: {
926
+ url: item.url !== undefined ? item.url : undefined,
927
+ relevancyScore: item.relevancyScore !== undefined ? item.relevancyScore : undefined,
928
+ sentimentScore: item.sentimentScore !== undefined ? item.sentimentScore : undefined,
929
+ sentimentLabel: item.sentimentLabel !== undefined ? item.sentimentLabel : undefined,
930
+ asset: item.asset ?
931
+ typeof item.asset === 'object' && Object.keys(item.asset).length === 1 && Object.keys(item.asset)[0] === 'id'
932
+ ? { connect: {
933
+ id: item.asset.id
934
+ }
935
+ }
936
+ : { connectOrCreate: {
937
+ where: {
938
+ id: item.asset.id !== undefined ? item.asset.id : undefined,
939
+ symbol: item.asset.symbol !== undefined ? item.asset.symbol : undefined,
940
+ name: item.asset.name !== undefined ? item.asset.name : undefined,
941
+ },
942
+ create: {
943
+ symbol: item.asset.symbol !== undefined ? item.asset.symbol : undefined,
944
+ name: item.asset.name !== undefined ? item.asset.name : undefined,
945
+ type: item.asset.type !== undefined ? item.asset.type : undefined,
946
+ logoUrl: item.asset.logoUrl !== undefined ? item.asset.logoUrl : undefined,
947
+ description: item.asset.description !== undefined ? item.asset.description : undefined,
948
+ cik: item.asset.cik !== undefined ? item.asset.cik : undefined,
949
+ exchange: item.asset.exchange !== undefined ? item.asset.exchange : undefined,
950
+ currency: item.asset.currency !== undefined ? item.asset.currency : undefined,
951
+ country: item.asset.country !== undefined ? item.asset.country : undefined,
952
+ sector: item.asset.sector !== undefined ? item.asset.sector : undefined,
953
+ industry: item.asset.industry !== undefined ? item.asset.industry : undefined,
954
+ address: item.asset.address !== undefined ? item.asset.address : undefined,
955
+ officialSite: item.asset.officialSite !== undefined ? item.asset.officialSite : undefined,
956
+ fiscalYearEnd: item.asset.fiscalYearEnd !== undefined ? item.asset.fiscalYearEnd : undefined,
957
+ latestQuarter: item.asset.latestQuarter !== undefined ? item.asset.latestQuarter : undefined,
958
+ marketCapitalization: item.asset.marketCapitalization !== undefined ? item.asset.marketCapitalization : undefined,
959
+ ebitda: item.asset.ebitda !== undefined ? item.asset.ebitda : undefined,
960
+ peRatio: item.asset.peRatio !== undefined ? item.asset.peRatio : undefined,
961
+ pegRatio: item.asset.pegRatio !== undefined ? item.asset.pegRatio : undefined,
962
+ bookValue: item.asset.bookValue !== undefined ? item.asset.bookValue : undefined,
963
+ dividendPerShare: item.asset.dividendPerShare !== undefined ? item.asset.dividendPerShare : undefined,
964
+ dividendYield: item.asset.dividendYield !== undefined ? item.asset.dividendYield : undefined,
965
+ eps: item.asset.eps !== undefined ? item.asset.eps : undefined,
966
+ revenuePerShareTTM: item.asset.revenuePerShareTTM !== undefined ? item.asset.revenuePerShareTTM : undefined,
967
+ profitMargin: item.asset.profitMargin !== undefined ? item.asset.profitMargin : undefined,
968
+ operatingMarginTTM: item.asset.operatingMarginTTM !== undefined ? item.asset.operatingMarginTTM : undefined,
969
+ returnOnAssetsTTM: item.asset.returnOnAssetsTTM !== undefined ? item.asset.returnOnAssetsTTM : undefined,
970
+ returnOnEquityTTM: item.asset.returnOnEquityTTM !== undefined ? item.asset.returnOnEquityTTM : undefined,
971
+ revenueTTM: item.asset.revenueTTM !== undefined ? item.asset.revenueTTM : undefined,
972
+ grossProfitTTM: item.asset.grossProfitTTM !== undefined ? item.asset.grossProfitTTM : undefined,
973
+ dilutedEPSTTM: item.asset.dilutedEPSTTM !== undefined ? item.asset.dilutedEPSTTM : undefined,
974
+ quarterlyEarningsGrowthYOY: item.asset.quarterlyEarningsGrowthYOY !== undefined ? item.asset.quarterlyEarningsGrowthYOY : undefined,
975
+ quarterlyRevenueGrowthYOY: item.asset.quarterlyRevenueGrowthYOY !== undefined ? item.asset.quarterlyRevenueGrowthYOY : undefined,
976
+ analystTargetPrice: item.asset.analystTargetPrice !== undefined ? item.asset.analystTargetPrice : undefined,
977
+ analystRatingStrongBuy: item.asset.analystRatingStrongBuy !== undefined ? item.asset.analystRatingStrongBuy : undefined,
978
+ analystRatingBuy: item.asset.analystRatingBuy !== undefined ? item.asset.analystRatingBuy : undefined,
979
+ analystRatingHold: item.asset.analystRatingHold !== undefined ? item.asset.analystRatingHold : undefined,
980
+ analystRatingSell: item.asset.analystRatingSell !== undefined ? item.asset.analystRatingSell : undefined,
981
+ analystRatingStrongSell: item.asset.analystRatingStrongSell !== undefined ? item.asset.analystRatingStrongSell : undefined,
982
+ trailingPE: item.asset.trailingPE !== undefined ? item.asset.trailingPE : undefined,
983
+ forwardPE: item.asset.forwardPE !== undefined ? item.asset.forwardPE : undefined,
984
+ priceToSalesRatioTTM: item.asset.priceToSalesRatioTTM !== undefined ? item.asset.priceToSalesRatioTTM : undefined,
985
+ priceToBookRatio: item.asset.priceToBookRatio !== undefined ? item.asset.priceToBookRatio : undefined,
986
+ evToRevenue: item.asset.evToRevenue !== undefined ? item.asset.evToRevenue : undefined,
987
+ evToEbitda: item.asset.evToEbitda !== undefined ? item.asset.evToEbitda : undefined,
988
+ beta: item.asset.beta !== undefined ? item.asset.beta : undefined,
989
+ week52High: item.asset.week52High !== undefined ? item.asset.week52High : undefined,
990
+ week52Low: item.asset.week52Low !== undefined ? item.asset.week52Low : undefined,
991
+ day50MovingAverage: item.asset.day50MovingAverage !== undefined ? item.asset.day50MovingAverage : undefined,
992
+ day200MovingAverage: item.asset.day200MovingAverage !== undefined ? item.asset.day200MovingAverage : undefined,
993
+ sharesOutstanding: item.asset.sharesOutstanding !== undefined ? item.asset.sharesOutstanding : undefined,
994
+ dividendDate: item.asset.dividendDate !== undefined ? item.asset.dividendDate : undefined,
995
+ exDividendDate: item.asset.exDividendDate !== undefined ? item.asset.exDividendDate : undefined,
996
+ askPrice: item.asset.askPrice !== undefined ? item.asset.askPrice : undefined,
997
+ bidPrice: item.asset.bidPrice !== undefined ? item.asset.bidPrice : undefined,
998
+ },
999
+ }
1000
+ } : undefined,
1001
+ },
1002
+ }))
1003
+ } : undefined,
1004
+ },
1005
+ update: {
1006
+ title: props.title !== undefined ? {
1007
+ set: props.title
1008
+ } : undefined,
1009
+ content: props.content !== undefined ? {
1010
+ set: props.content
1011
+ } : undefined,
1012
+ source: props.source !== undefined ? {
1013
+ set: props.source
1014
+ } : undefined,
1015
+ sourceDomain: props.sourceDomain !== undefined ? {
1016
+ set: props.sourceDomain
1017
+ } : undefined,
1018
+ url: props.url !== undefined ? {
1019
+ set: props.url
1020
+ } : undefined,
1021
+ sentiment: props.sentiment !== undefined ? {
1022
+ set: props.sentiment
1023
+ } : undefined,
1024
+ authors: props.authors !== undefined ? {
1025
+ set: props.authors
1026
+ } : undefined,
1027
+ summary: props.summary !== undefined ? {
1028
+ set: props.summary
1029
+ } : undefined,
1030
+ bannerImage: props.bannerImage !== undefined ? {
1031
+ set: props.bannerImage
1032
+ } : undefined,
1033
+ timePublished: props.timePublished !== undefined ? {
1034
+ set: props.timePublished
1035
+ } : undefined,
1036
+ category: props.category !== undefined ? {
1037
+ set: props.category
1038
+ } : undefined,
1039
+ topics: props.topics !== undefined ? {
1040
+ set: props.topics
1041
+ } : undefined,
1042
+ logo: props.logo !== undefined ? {
1043
+ set: props.logo
1044
+ } : undefined,
1045
+ assets: props.assets ?
1046
+ Array.isArray(props.assets) && props.assets.length > 0 && props.assets.every((item) => typeof item === 'object' && ('id' in item || 'symbol' in item) && Object.keys(item).length === 1) ? {
1047
+ connect: props.assets.map((item) => ({
1048
+ id: item.id
1049
+ }))
1050
+ } : { upsert: props.assets.map((item) => ({
1051
+ where: {
1052
+ id: item.id !== undefined ? item.id : undefined,
1053
+ url: item.url !== undefined ? item.url : undefined,
1054
+ assetId: item.assetId !== undefined ? {
1055
+ equals: item.assetId
1056
+ } : undefined,
1057
+ newsArticleId: item.newsArticleId !== undefined ? {
1058
+ equals: item.newsArticleId
1059
+ } : undefined,
1060
+ },
1061
+ update: {
1062
+ id: item.id !== undefined ? {
1063
+ set: item.id
1064
+ } : undefined,
1065
+ url: item.url !== undefined ? {
1066
+ set: item.url
1067
+ } : undefined,
1068
+ relevancyScore: item.relevancyScore !== undefined ? {
1069
+ set: item.relevancyScore
1070
+ } : undefined,
1071
+ sentimentScore: item.sentimentScore !== undefined ? {
1072
+ set: item.sentimentScore
1073
+ } : undefined,
1074
+ sentimentLabel: item.sentimentLabel !== undefined ? {
1075
+ set: item.sentimentLabel
1076
+ } : undefined,
1077
+ asset: item.asset ?
1078
+ typeof item.asset === 'object' && Object.keys(item.asset).length === 1 && (Object.keys(item.asset)[0] === 'id' || Object.keys(item.asset)[0] === 'symbol')
1079
+ ? {
1080
+ connect: {
1081
+ id: item.asset.id
1082
+ }
1083
+ } : { upsert: {
833
1084
  where: {
834
- id: item.asset.id !== undefined ? item.asset.id : undefined,
835
- symbol: item.asset.symbol !== undefined ? item.asset.symbol : undefined,
836
- name: item.asset.name !== undefined ? item.asset.name : undefined,
1085
+ id: item.asset.id !== undefined ? {
1086
+ equals: item.asset.id
1087
+ } : undefined,
1088
+ symbol: item.asset.symbol !== undefined ? {
1089
+ equals: item.asset.symbol
1090
+ } : undefined,
1091
+ name: item.asset.name !== undefined ? {
1092
+ equals: item.asset.name
1093
+ } : undefined,
1094
+ },
1095
+ update: {
1096
+ id: item.asset.id !== undefined ? {
1097
+ set: item.asset.id
1098
+ } : undefined,
1099
+ symbol: item.asset.symbol !== undefined ? {
1100
+ set: item.asset.symbol
1101
+ } : undefined,
1102
+ name: item.asset.name !== undefined ? {
1103
+ set: item.asset.name
1104
+ } : undefined,
1105
+ type: item.asset.type !== undefined ? {
1106
+ set: item.asset.type
1107
+ } : undefined,
1108
+ logoUrl: item.asset.logoUrl !== undefined ? {
1109
+ set: item.asset.logoUrl
1110
+ } : undefined,
1111
+ description: item.asset.description !== undefined ? {
1112
+ set: item.asset.description
1113
+ } : undefined,
1114
+ cik: item.asset.cik !== undefined ? {
1115
+ set: item.asset.cik
1116
+ } : undefined,
1117
+ exchange: item.asset.exchange !== undefined ? {
1118
+ set: item.asset.exchange
1119
+ } : undefined,
1120
+ currency: item.asset.currency !== undefined ? {
1121
+ set: item.asset.currency
1122
+ } : undefined,
1123
+ country: item.asset.country !== undefined ? {
1124
+ set: item.asset.country
1125
+ } : undefined,
1126
+ sector: item.asset.sector !== undefined ? {
1127
+ set: item.asset.sector
1128
+ } : undefined,
1129
+ industry: item.asset.industry !== undefined ? {
1130
+ set: item.asset.industry
1131
+ } : undefined,
1132
+ address: item.asset.address !== undefined ? {
1133
+ set: item.asset.address
1134
+ } : undefined,
1135
+ officialSite: item.asset.officialSite !== undefined ? {
1136
+ set: item.asset.officialSite
1137
+ } : undefined,
1138
+ fiscalYearEnd: item.asset.fiscalYearEnd !== undefined ? {
1139
+ set: item.asset.fiscalYearEnd
1140
+ } : undefined,
1141
+ latestQuarter: item.asset.latestQuarter !== undefined ? {
1142
+ set: item.asset.latestQuarter
1143
+ } : undefined,
1144
+ marketCapitalization: item.asset.marketCapitalization !== undefined ? {
1145
+ set: item.asset.marketCapitalization
1146
+ } : undefined,
1147
+ ebitda: item.asset.ebitda !== undefined ? {
1148
+ set: item.asset.ebitda
1149
+ } : undefined,
1150
+ peRatio: item.asset.peRatio !== undefined ? {
1151
+ set: item.asset.peRatio
1152
+ } : undefined,
1153
+ pegRatio: item.asset.pegRatio !== undefined ? {
1154
+ set: item.asset.pegRatio
1155
+ } : undefined,
1156
+ bookValue: item.asset.bookValue !== undefined ? {
1157
+ set: item.asset.bookValue
1158
+ } : undefined,
1159
+ dividendPerShare: item.asset.dividendPerShare !== undefined ? {
1160
+ set: item.asset.dividendPerShare
1161
+ } : undefined,
1162
+ dividendYield: item.asset.dividendYield !== undefined ? {
1163
+ set: item.asset.dividendYield
1164
+ } : undefined,
1165
+ eps: item.asset.eps !== undefined ? {
1166
+ set: item.asset.eps
1167
+ } : undefined,
1168
+ revenuePerShareTTM: item.asset.revenuePerShareTTM !== undefined ? {
1169
+ set: item.asset.revenuePerShareTTM
1170
+ } : undefined,
1171
+ profitMargin: item.asset.profitMargin !== undefined ? {
1172
+ set: item.asset.profitMargin
1173
+ } : undefined,
1174
+ operatingMarginTTM: item.asset.operatingMarginTTM !== undefined ? {
1175
+ set: item.asset.operatingMarginTTM
1176
+ } : undefined,
1177
+ returnOnAssetsTTM: item.asset.returnOnAssetsTTM !== undefined ? {
1178
+ set: item.asset.returnOnAssetsTTM
1179
+ } : undefined,
1180
+ returnOnEquityTTM: item.asset.returnOnEquityTTM !== undefined ? {
1181
+ set: item.asset.returnOnEquityTTM
1182
+ } : undefined,
1183
+ revenueTTM: item.asset.revenueTTM !== undefined ? {
1184
+ set: item.asset.revenueTTM
1185
+ } : undefined,
1186
+ grossProfitTTM: item.asset.grossProfitTTM !== undefined ? {
1187
+ set: item.asset.grossProfitTTM
1188
+ } : undefined,
1189
+ dilutedEPSTTM: item.asset.dilutedEPSTTM !== undefined ? {
1190
+ set: item.asset.dilutedEPSTTM
1191
+ } : undefined,
1192
+ quarterlyEarningsGrowthYOY: item.asset.quarterlyEarningsGrowthYOY !== undefined ? {
1193
+ set: item.asset.quarterlyEarningsGrowthYOY
1194
+ } : undefined,
1195
+ quarterlyRevenueGrowthYOY: item.asset.quarterlyRevenueGrowthYOY !== undefined ? {
1196
+ set: item.asset.quarterlyRevenueGrowthYOY
1197
+ } : undefined,
1198
+ analystTargetPrice: item.asset.analystTargetPrice !== undefined ? {
1199
+ set: item.asset.analystTargetPrice
1200
+ } : undefined,
1201
+ analystRatingStrongBuy: item.asset.analystRatingStrongBuy !== undefined ? {
1202
+ set: item.asset.analystRatingStrongBuy
1203
+ } : undefined,
1204
+ analystRatingBuy: item.asset.analystRatingBuy !== undefined ? {
1205
+ set: item.asset.analystRatingBuy
1206
+ } : undefined,
1207
+ analystRatingHold: item.asset.analystRatingHold !== undefined ? {
1208
+ set: item.asset.analystRatingHold
1209
+ } : undefined,
1210
+ analystRatingSell: item.asset.analystRatingSell !== undefined ? {
1211
+ set: item.asset.analystRatingSell
1212
+ } : undefined,
1213
+ analystRatingStrongSell: item.asset.analystRatingStrongSell !== undefined ? {
1214
+ set: item.asset.analystRatingStrongSell
1215
+ } : undefined,
1216
+ trailingPE: item.asset.trailingPE !== undefined ? {
1217
+ set: item.asset.trailingPE
1218
+ } : undefined,
1219
+ forwardPE: item.asset.forwardPE !== undefined ? {
1220
+ set: item.asset.forwardPE
1221
+ } : undefined,
1222
+ priceToSalesRatioTTM: item.asset.priceToSalesRatioTTM !== undefined ? {
1223
+ set: item.asset.priceToSalesRatioTTM
1224
+ } : undefined,
1225
+ priceToBookRatio: item.asset.priceToBookRatio !== undefined ? {
1226
+ set: item.asset.priceToBookRatio
1227
+ } : undefined,
1228
+ evToRevenue: item.asset.evToRevenue !== undefined ? {
1229
+ set: item.asset.evToRevenue
1230
+ } : undefined,
1231
+ evToEbitda: item.asset.evToEbitda !== undefined ? {
1232
+ set: item.asset.evToEbitda
1233
+ } : undefined,
1234
+ beta: item.asset.beta !== undefined ? {
1235
+ set: item.asset.beta
1236
+ } : undefined,
1237
+ week52High: item.asset.week52High !== undefined ? {
1238
+ set: item.asset.week52High
1239
+ } : undefined,
1240
+ week52Low: item.asset.week52Low !== undefined ? {
1241
+ set: item.asset.week52Low
1242
+ } : undefined,
1243
+ day50MovingAverage: item.asset.day50MovingAverage !== undefined ? {
1244
+ set: item.asset.day50MovingAverage
1245
+ } : undefined,
1246
+ day200MovingAverage: item.asset.day200MovingAverage !== undefined ? {
1247
+ set: item.asset.day200MovingAverage
1248
+ } : undefined,
1249
+ sharesOutstanding: item.asset.sharesOutstanding !== undefined ? {
1250
+ set: item.asset.sharesOutstanding
1251
+ } : undefined,
1252
+ dividendDate: item.asset.dividendDate !== undefined ? {
1253
+ set: item.asset.dividendDate
1254
+ } : undefined,
1255
+ exDividendDate: item.asset.exDividendDate !== undefined ? {
1256
+ set: item.asset.exDividendDate
1257
+ } : undefined,
1258
+ askPrice: item.asset.askPrice !== undefined ? {
1259
+ set: item.asset.askPrice
1260
+ } : undefined,
1261
+ bidPrice: item.asset.bidPrice !== undefined ? {
1262
+ set: item.asset.bidPrice
1263
+ } : undefined,
837
1264
  },
838
1265
  create: {
839
1266
  symbol: item.asset.symbol !== undefined ? item.asset.symbol : undefined,
@@ -894,1060 +1321,904 @@ export const NewsArticle = {
894
1321
  },
895
1322
  }
896
1323
  } : undefined,
897
- },
898
- }))
899
- } : undefined,
900
- },
901
- update: {
902
- title: props.title !== undefined ? {
903
- set: props.title
904
- } : undefined,
905
- content: props.content !== undefined ? {
906
- set: props.content
907
- } : undefined,
908
- source: props.source !== undefined ? {
909
- set: props.source
910
- } : undefined,
911
- sourceDomain: props.sourceDomain !== undefined ? {
912
- set: props.sourceDomain
913
- } : undefined,
914
- url: props.url !== undefined ? {
915
- set: props.url
916
- } : undefined,
917
- sentiment: props.sentiment !== undefined ? {
918
- set: props.sentiment
919
- } : undefined,
920
- authors: props.authors !== undefined ? {
921
- set: props.authors
922
- } : undefined,
923
- summary: props.summary !== undefined ? {
924
- set: props.summary
925
- } : undefined,
926
- bannerImage: props.bannerImage !== undefined ? {
927
- set: props.bannerImage
928
- } : undefined,
929
- timePublished: props.timePublished !== undefined ? {
930
- set: props.timePublished
931
- } : undefined,
932
- category: props.category !== undefined ? {
933
- set: props.category
934
- } : undefined,
935
- topics: props.topics !== undefined ? {
936
- set: props.topics
937
- } : undefined,
938
- logo: props.logo !== undefined ? {
939
- set: props.logo
940
- } : undefined,
941
- assets: props.assets ?
942
- Array.isArray(props.assets) && props.assets.length > 0 && props.assets.every((item) => typeof item === 'object' && ('id' in item || 'symbol' in item) && Object.keys(item).length === 1) ? {
943
- connect: props.assets.map((item) => ({
944
- id: item.id
945
- }))
946
- } : { upsert: props.assets.map((item) => ({
947
- where: {
948
- id: item.id !== undefined ? item.id : undefined,
949
- url: item.url !== undefined ? item.url : undefined,
950
- assetId: item.assetId !== undefined ? {
951
- equals: item.assetId
952
- } : undefined,
953
- newsArticleId: item.newsArticleId !== undefined ? {
954
- equals: item.newsArticleId
955
- } : undefined,
956
- },
957
- update: {
958
- id: item.id !== undefined ? {
959
- set: item.id
960
- } : undefined,
961
- url: item.url !== undefined ? {
962
- set: item.url
963
- } : undefined,
964
- relevancyScore: item.relevancyScore !== undefined ? {
965
- set: item.relevancyScore
966
- } : undefined,
967
- sentimentScore: item.sentimentScore !== undefined ? {
968
- set: item.sentimentScore
969
- } : undefined,
970
- sentimentLabel: item.sentimentLabel !== undefined ? {
971
- set: item.sentimentLabel
972
- } : undefined,
973
- asset: item.asset ?
974
- typeof item.asset === 'object' && Object.keys(item.asset).length === 1 && (Object.keys(item.asset)[0] === 'id' || Object.keys(item.asset)[0] === 'symbol')
975
- ? {
976
- connect: {
977
- id: item.asset.id
978
- }
979
- } : { upsert: {
980
- where: {
981
- id: item.asset.id !== undefined ? {
982
- equals: item.asset.id
983
- } : undefined,
984
- symbol: item.asset.symbol !== undefined ? {
985
- equals: item.asset.symbol
986
- } : undefined,
987
- name: item.asset.name !== undefined ? {
988
- equals: item.asset.name
989
- } : undefined,
990
- },
991
- update: {
992
- id: item.asset.id !== undefined ? {
993
- set: item.asset.id
994
- } : undefined,
995
- symbol: item.asset.symbol !== undefined ? {
996
- set: item.asset.symbol
997
- } : undefined,
998
- name: item.asset.name !== undefined ? {
999
- set: item.asset.name
1000
- } : undefined,
1001
- type: item.asset.type !== undefined ? {
1002
- set: item.asset.type
1003
- } : undefined,
1004
- logoUrl: item.asset.logoUrl !== undefined ? {
1005
- set: item.asset.logoUrl
1006
- } : undefined,
1007
- description: item.asset.description !== undefined ? {
1008
- set: item.asset.description
1009
- } : undefined,
1010
- cik: item.asset.cik !== undefined ? {
1011
- set: item.asset.cik
1012
- } : undefined,
1013
- exchange: item.asset.exchange !== undefined ? {
1014
- set: item.asset.exchange
1015
- } : undefined,
1016
- currency: item.asset.currency !== undefined ? {
1017
- set: item.asset.currency
1018
- } : undefined,
1019
- country: item.asset.country !== undefined ? {
1020
- set: item.asset.country
1021
- } : undefined,
1022
- sector: item.asset.sector !== undefined ? {
1023
- set: item.asset.sector
1024
- } : undefined,
1025
- industry: item.asset.industry !== undefined ? {
1026
- set: item.asset.industry
1027
- } : undefined,
1028
- address: item.asset.address !== undefined ? {
1029
- set: item.asset.address
1030
- } : undefined,
1031
- officialSite: item.asset.officialSite !== undefined ? {
1032
- set: item.asset.officialSite
1033
- } : undefined,
1034
- fiscalYearEnd: item.asset.fiscalYearEnd !== undefined ? {
1035
- set: item.asset.fiscalYearEnd
1036
- } : undefined,
1037
- latestQuarter: item.asset.latestQuarter !== undefined ? {
1038
- set: item.asset.latestQuarter
1039
- } : undefined,
1040
- marketCapitalization: item.asset.marketCapitalization !== undefined ? {
1041
- set: item.asset.marketCapitalization
1042
- } : undefined,
1043
- ebitda: item.asset.ebitda !== undefined ? {
1044
- set: item.asset.ebitda
1045
- } : undefined,
1046
- peRatio: item.asset.peRatio !== undefined ? {
1047
- set: item.asset.peRatio
1048
- } : undefined,
1049
- pegRatio: item.asset.pegRatio !== undefined ? {
1050
- set: item.asset.pegRatio
1051
- } : undefined,
1052
- bookValue: item.asset.bookValue !== undefined ? {
1053
- set: item.asset.bookValue
1054
- } : undefined,
1055
- dividendPerShare: item.asset.dividendPerShare !== undefined ? {
1056
- set: item.asset.dividendPerShare
1057
- } : undefined,
1058
- dividendYield: item.asset.dividendYield !== undefined ? {
1059
- set: item.asset.dividendYield
1060
- } : undefined,
1061
- eps: item.asset.eps !== undefined ? {
1062
- set: item.asset.eps
1063
- } : undefined,
1064
- revenuePerShareTTM: item.asset.revenuePerShareTTM !== undefined ? {
1065
- set: item.asset.revenuePerShareTTM
1066
- } : undefined,
1067
- profitMargin: item.asset.profitMargin !== undefined ? {
1068
- set: item.asset.profitMargin
1069
- } : undefined,
1070
- operatingMarginTTM: item.asset.operatingMarginTTM !== undefined ? {
1071
- set: item.asset.operatingMarginTTM
1072
- } : undefined,
1073
- returnOnAssetsTTM: item.asset.returnOnAssetsTTM !== undefined ? {
1074
- set: item.asset.returnOnAssetsTTM
1075
- } : undefined,
1076
- returnOnEquityTTM: item.asset.returnOnEquityTTM !== undefined ? {
1077
- set: item.asset.returnOnEquityTTM
1078
- } : undefined,
1079
- revenueTTM: item.asset.revenueTTM !== undefined ? {
1080
- set: item.asset.revenueTTM
1081
- } : undefined,
1082
- grossProfitTTM: item.asset.grossProfitTTM !== undefined ? {
1083
- set: item.asset.grossProfitTTM
1084
- } : undefined,
1085
- dilutedEPSTTM: item.asset.dilutedEPSTTM !== undefined ? {
1086
- set: item.asset.dilutedEPSTTM
1087
- } : undefined,
1088
- quarterlyEarningsGrowthYOY: item.asset.quarterlyEarningsGrowthYOY !== undefined ? {
1089
- set: item.asset.quarterlyEarningsGrowthYOY
1090
- } : undefined,
1091
- quarterlyRevenueGrowthYOY: item.asset.quarterlyRevenueGrowthYOY !== undefined ? {
1092
- set: item.asset.quarterlyRevenueGrowthYOY
1093
- } : undefined,
1094
- analystTargetPrice: item.asset.analystTargetPrice !== undefined ? {
1095
- set: item.asset.analystTargetPrice
1096
- } : undefined,
1097
- analystRatingStrongBuy: item.asset.analystRatingStrongBuy !== undefined ? {
1098
- set: item.asset.analystRatingStrongBuy
1099
- } : undefined,
1100
- analystRatingBuy: item.asset.analystRatingBuy !== undefined ? {
1101
- set: item.asset.analystRatingBuy
1102
- } : undefined,
1103
- analystRatingHold: item.asset.analystRatingHold !== undefined ? {
1104
- set: item.asset.analystRatingHold
1105
- } : undefined,
1106
- analystRatingSell: item.asset.analystRatingSell !== undefined ? {
1107
- set: item.asset.analystRatingSell
1108
- } : undefined,
1109
- analystRatingStrongSell: item.asset.analystRatingStrongSell !== undefined ? {
1110
- set: item.asset.analystRatingStrongSell
1111
- } : undefined,
1112
- trailingPE: item.asset.trailingPE !== undefined ? {
1113
- set: item.asset.trailingPE
1114
- } : undefined,
1115
- forwardPE: item.asset.forwardPE !== undefined ? {
1116
- set: item.asset.forwardPE
1117
- } : undefined,
1118
- priceToSalesRatioTTM: item.asset.priceToSalesRatioTTM !== undefined ? {
1119
- set: item.asset.priceToSalesRatioTTM
1120
- } : undefined,
1121
- priceToBookRatio: item.asset.priceToBookRatio !== undefined ? {
1122
- set: item.asset.priceToBookRatio
1123
- } : undefined,
1124
- evToRevenue: item.asset.evToRevenue !== undefined ? {
1125
- set: item.asset.evToRevenue
1126
- } : undefined,
1127
- evToEbitda: item.asset.evToEbitda !== undefined ? {
1128
- set: item.asset.evToEbitda
1129
- } : undefined,
1130
- beta: item.asset.beta !== undefined ? {
1131
- set: item.asset.beta
1132
- } : undefined,
1133
- week52High: item.asset.week52High !== undefined ? {
1134
- set: item.asset.week52High
1135
- } : undefined,
1136
- week52Low: item.asset.week52Low !== undefined ? {
1137
- set: item.asset.week52Low
1138
- } : undefined,
1139
- day50MovingAverage: item.asset.day50MovingAverage !== undefined ? {
1140
- set: item.asset.day50MovingAverage
1141
- } : undefined,
1142
- day200MovingAverage: item.asset.day200MovingAverage !== undefined ? {
1143
- set: item.asset.day200MovingAverage
1144
- } : undefined,
1145
- sharesOutstanding: item.asset.sharesOutstanding !== undefined ? {
1146
- set: item.asset.sharesOutstanding
1147
- } : undefined,
1148
- dividendDate: item.asset.dividendDate !== undefined ? {
1149
- set: item.asset.dividendDate
1150
- } : undefined,
1151
- exDividendDate: item.asset.exDividendDate !== undefined ? {
1152
- set: item.asset.exDividendDate
1153
- } : undefined,
1154
- askPrice: item.asset.askPrice !== undefined ? {
1155
- set: item.asset.askPrice
1156
- } : undefined,
1157
- bidPrice: item.asset.bidPrice !== undefined ? {
1158
- set: item.asset.bidPrice
1159
- } : undefined,
1160
- },
1161
- create: {
1162
- symbol: item.asset.symbol !== undefined ? item.asset.symbol : undefined,
1163
- name: item.asset.name !== undefined ? item.asset.name : undefined,
1164
- type: item.asset.type !== undefined ? item.asset.type : undefined,
1165
- logoUrl: item.asset.logoUrl !== undefined ? item.asset.logoUrl : undefined,
1166
- description: item.asset.description !== undefined ? item.asset.description : undefined,
1167
- cik: item.asset.cik !== undefined ? item.asset.cik : undefined,
1168
- exchange: item.asset.exchange !== undefined ? item.asset.exchange : undefined,
1169
- currency: item.asset.currency !== undefined ? item.asset.currency : undefined,
1170
- country: item.asset.country !== undefined ? item.asset.country : undefined,
1171
- sector: item.asset.sector !== undefined ? item.asset.sector : undefined,
1172
- industry: item.asset.industry !== undefined ? item.asset.industry : undefined,
1173
- address: item.asset.address !== undefined ? item.asset.address : undefined,
1174
- officialSite: item.asset.officialSite !== undefined ? item.asset.officialSite : undefined,
1175
- fiscalYearEnd: item.asset.fiscalYearEnd !== undefined ? item.asset.fiscalYearEnd : undefined,
1176
- latestQuarter: item.asset.latestQuarter !== undefined ? item.asset.latestQuarter : undefined,
1177
- marketCapitalization: item.asset.marketCapitalization !== undefined ? item.asset.marketCapitalization : undefined,
1178
- ebitda: item.asset.ebitda !== undefined ? item.asset.ebitda : undefined,
1179
- peRatio: item.asset.peRatio !== undefined ? item.asset.peRatio : undefined,
1180
- pegRatio: item.asset.pegRatio !== undefined ? item.asset.pegRatio : undefined,
1181
- bookValue: item.asset.bookValue !== undefined ? item.asset.bookValue : undefined,
1182
- dividendPerShare: item.asset.dividendPerShare !== undefined ? item.asset.dividendPerShare : undefined,
1183
- dividendYield: item.asset.dividendYield !== undefined ? item.asset.dividendYield : undefined,
1184
- eps: item.asset.eps !== undefined ? item.asset.eps : undefined,
1185
- revenuePerShareTTM: item.asset.revenuePerShareTTM !== undefined ? item.asset.revenuePerShareTTM : undefined,
1186
- profitMargin: item.asset.profitMargin !== undefined ? item.asset.profitMargin : undefined,
1187
- operatingMarginTTM: item.asset.operatingMarginTTM !== undefined ? item.asset.operatingMarginTTM : undefined,
1188
- returnOnAssetsTTM: item.asset.returnOnAssetsTTM !== undefined ? item.asset.returnOnAssetsTTM : undefined,
1189
- returnOnEquityTTM: item.asset.returnOnEquityTTM !== undefined ? item.asset.returnOnEquityTTM : undefined,
1190
- revenueTTM: item.asset.revenueTTM !== undefined ? item.asset.revenueTTM : undefined,
1191
- grossProfitTTM: item.asset.grossProfitTTM !== undefined ? item.asset.grossProfitTTM : undefined,
1192
- dilutedEPSTTM: item.asset.dilutedEPSTTM !== undefined ? item.asset.dilutedEPSTTM : undefined,
1193
- quarterlyEarningsGrowthYOY: item.asset.quarterlyEarningsGrowthYOY !== undefined ? item.asset.quarterlyEarningsGrowthYOY : undefined,
1194
- quarterlyRevenueGrowthYOY: item.asset.quarterlyRevenueGrowthYOY !== undefined ? item.asset.quarterlyRevenueGrowthYOY : undefined,
1195
- analystTargetPrice: item.asset.analystTargetPrice !== undefined ? item.asset.analystTargetPrice : undefined,
1196
- analystRatingStrongBuy: item.asset.analystRatingStrongBuy !== undefined ? item.asset.analystRatingStrongBuy : undefined,
1197
- analystRatingBuy: item.asset.analystRatingBuy !== undefined ? item.asset.analystRatingBuy : undefined,
1198
- analystRatingHold: item.asset.analystRatingHold !== undefined ? item.asset.analystRatingHold : undefined,
1199
- analystRatingSell: item.asset.analystRatingSell !== undefined ? item.asset.analystRatingSell : undefined,
1200
- analystRatingStrongSell: item.asset.analystRatingStrongSell !== undefined ? item.asset.analystRatingStrongSell : undefined,
1201
- trailingPE: item.asset.trailingPE !== undefined ? item.asset.trailingPE : undefined,
1202
- forwardPE: item.asset.forwardPE !== undefined ? item.asset.forwardPE : undefined,
1203
- priceToSalesRatioTTM: item.asset.priceToSalesRatioTTM !== undefined ? item.asset.priceToSalesRatioTTM : undefined,
1204
- priceToBookRatio: item.asset.priceToBookRatio !== undefined ? item.asset.priceToBookRatio : undefined,
1205
- evToRevenue: item.asset.evToRevenue !== undefined ? item.asset.evToRevenue : undefined,
1206
- evToEbitda: item.asset.evToEbitda !== undefined ? item.asset.evToEbitda : undefined,
1207
- beta: item.asset.beta !== undefined ? item.asset.beta : undefined,
1208
- week52High: item.asset.week52High !== undefined ? item.asset.week52High : undefined,
1209
- week52Low: item.asset.week52Low !== undefined ? item.asset.week52Low : undefined,
1210
- day50MovingAverage: item.asset.day50MovingAverage !== undefined ? item.asset.day50MovingAverage : undefined,
1211
- day200MovingAverage: item.asset.day200MovingAverage !== undefined ? item.asset.day200MovingAverage : undefined,
1212
- sharesOutstanding: item.asset.sharesOutstanding !== undefined ? item.asset.sharesOutstanding : undefined,
1213
- dividendDate: item.asset.dividendDate !== undefined ? item.asset.dividendDate : undefined,
1214
- exDividendDate: item.asset.exDividendDate !== undefined ? item.asset.exDividendDate : undefined,
1215
- askPrice: item.asset.askPrice !== undefined ? item.asset.askPrice : undefined,
1216
- bidPrice: item.asset.bidPrice !== undefined ? item.asset.bidPrice : undefined,
1217
- },
1218
- }
1219
- } : undefined,
1220
- },
1221
- create: {
1222
- url: item.url !== undefined ? item.url : undefined,
1223
- relevancyScore: item.relevancyScore !== undefined ? item.relevancyScore : undefined,
1224
- sentimentScore: item.sentimentScore !== undefined ? item.sentimentScore : undefined,
1225
- sentimentLabel: item.sentimentLabel !== undefined ? item.sentimentLabel : undefined,
1226
- asset: item.asset ?
1227
- typeof item.asset === 'object' && Object.keys(item.asset).length === 1 && Object.keys(item.asset)[0] === 'id'
1228
- ? { connect: {
1229
- id: item.asset.id
1230
- }
1231
- }
1232
- : { connectOrCreate: {
1233
- where: {
1234
- id: item.asset.id !== undefined ? item.asset.id : undefined,
1235
- symbol: item.asset.symbol !== undefined ? item.asset.symbol : undefined,
1236
- name: item.asset.name !== undefined ? item.asset.name : undefined,
1237
- },
1238
- create: {
1239
- symbol: item.asset.symbol !== undefined ? item.asset.symbol : undefined,
1240
- name: item.asset.name !== undefined ? item.asset.name : undefined,
1241
- type: item.asset.type !== undefined ? item.asset.type : undefined,
1242
- logoUrl: item.asset.logoUrl !== undefined ? item.asset.logoUrl : undefined,
1243
- description: item.asset.description !== undefined ? item.asset.description : undefined,
1244
- cik: item.asset.cik !== undefined ? item.asset.cik : undefined,
1245
- exchange: item.asset.exchange !== undefined ? item.asset.exchange : undefined,
1246
- currency: item.asset.currency !== undefined ? item.asset.currency : undefined,
1247
- country: item.asset.country !== undefined ? item.asset.country : undefined,
1248
- sector: item.asset.sector !== undefined ? item.asset.sector : undefined,
1249
- industry: item.asset.industry !== undefined ? item.asset.industry : undefined,
1250
- address: item.asset.address !== undefined ? item.asset.address : undefined,
1251
- officialSite: item.asset.officialSite !== undefined ? item.asset.officialSite : undefined,
1252
- fiscalYearEnd: item.asset.fiscalYearEnd !== undefined ? item.asset.fiscalYearEnd : undefined,
1253
- latestQuarter: item.asset.latestQuarter !== undefined ? item.asset.latestQuarter : undefined,
1254
- marketCapitalization: item.asset.marketCapitalization !== undefined ? item.asset.marketCapitalization : undefined,
1255
- ebitda: item.asset.ebitda !== undefined ? item.asset.ebitda : undefined,
1256
- peRatio: item.asset.peRatio !== undefined ? item.asset.peRatio : undefined,
1257
- pegRatio: item.asset.pegRatio !== undefined ? item.asset.pegRatio : undefined,
1258
- bookValue: item.asset.bookValue !== undefined ? item.asset.bookValue : undefined,
1259
- dividendPerShare: item.asset.dividendPerShare !== undefined ? item.asset.dividendPerShare : undefined,
1260
- dividendYield: item.asset.dividendYield !== undefined ? item.asset.dividendYield : undefined,
1261
- eps: item.asset.eps !== undefined ? item.asset.eps : undefined,
1262
- revenuePerShareTTM: item.asset.revenuePerShareTTM !== undefined ? item.asset.revenuePerShareTTM : undefined,
1263
- profitMargin: item.asset.profitMargin !== undefined ? item.asset.profitMargin : undefined,
1264
- operatingMarginTTM: item.asset.operatingMarginTTM !== undefined ? item.asset.operatingMarginTTM : undefined,
1265
- returnOnAssetsTTM: item.asset.returnOnAssetsTTM !== undefined ? item.asset.returnOnAssetsTTM : undefined,
1266
- returnOnEquityTTM: item.asset.returnOnEquityTTM !== undefined ? item.asset.returnOnEquityTTM : undefined,
1267
- revenueTTM: item.asset.revenueTTM !== undefined ? item.asset.revenueTTM : undefined,
1268
- grossProfitTTM: item.asset.grossProfitTTM !== undefined ? item.asset.grossProfitTTM : undefined,
1269
- dilutedEPSTTM: item.asset.dilutedEPSTTM !== undefined ? item.asset.dilutedEPSTTM : undefined,
1270
- quarterlyEarningsGrowthYOY: item.asset.quarterlyEarningsGrowthYOY !== undefined ? item.asset.quarterlyEarningsGrowthYOY : undefined,
1271
- quarterlyRevenueGrowthYOY: item.asset.quarterlyRevenueGrowthYOY !== undefined ? item.asset.quarterlyRevenueGrowthYOY : undefined,
1272
- analystTargetPrice: item.asset.analystTargetPrice !== undefined ? item.asset.analystTargetPrice : undefined,
1273
- analystRatingStrongBuy: item.asset.analystRatingStrongBuy !== undefined ? item.asset.analystRatingStrongBuy : undefined,
1274
- analystRatingBuy: item.asset.analystRatingBuy !== undefined ? item.asset.analystRatingBuy : undefined,
1275
- analystRatingHold: item.asset.analystRatingHold !== undefined ? item.asset.analystRatingHold : undefined,
1276
- analystRatingSell: item.asset.analystRatingSell !== undefined ? item.asset.analystRatingSell : undefined,
1277
- analystRatingStrongSell: item.asset.analystRatingStrongSell !== undefined ? item.asset.analystRatingStrongSell : undefined,
1278
- trailingPE: item.asset.trailingPE !== undefined ? item.asset.trailingPE : undefined,
1279
- forwardPE: item.asset.forwardPE !== undefined ? item.asset.forwardPE : undefined,
1280
- priceToSalesRatioTTM: item.asset.priceToSalesRatioTTM !== undefined ? item.asset.priceToSalesRatioTTM : undefined,
1281
- priceToBookRatio: item.asset.priceToBookRatio !== undefined ? item.asset.priceToBookRatio : undefined,
1282
- evToRevenue: item.asset.evToRevenue !== undefined ? item.asset.evToRevenue : undefined,
1283
- evToEbitda: item.asset.evToEbitda !== undefined ? item.asset.evToEbitda : undefined,
1284
- beta: item.asset.beta !== undefined ? item.asset.beta : undefined,
1285
- week52High: item.asset.week52High !== undefined ? item.asset.week52High : undefined,
1286
- week52Low: item.asset.week52Low !== undefined ? item.asset.week52Low : undefined,
1287
- day50MovingAverage: item.asset.day50MovingAverage !== undefined ? item.asset.day50MovingAverage : undefined,
1288
- day200MovingAverage: item.asset.day200MovingAverage !== undefined ? item.asset.day200MovingAverage : undefined,
1289
- sharesOutstanding: item.asset.sharesOutstanding !== undefined ? item.asset.sharesOutstanding : undefined,
1290
- dividendDate: item.asset.dividendDate !== undefined ? item.asset.dividendDate : undefined,
1291
- exDividendDate: item.asset.exDividendDate !== undefined ? item.asset.exDividendDate : undefined,
1292
- askPrice: item.asset.askPrice !== undefined ? item.asset.askPrice : undefined,
1293
- bidPrice: item.asset.bidPrice !== undefined ? item.asset.bidPrice : undefined,
1294
- },
1295
- }
1296
- } : undefined,
1297
- },
1298
- }))
1299
- } : undefined,
1300
- },
1301
- };
1302
- const filteredVariables = removeUndefinedProps(variables);
1303
- try {
1304
- const response = await client.mutate({ mutation: UPSERT_ONE_NEWSARTICLE, variables: filteredVariables });
1305
- if (response.errors && response.errors.length > 0)
1306
- throw new Error(response.errors[0].message);
1307
- if (response && response.data && response.data.upsertOneNewsArticle) {
1308
- return response.data.upsertOneNewsArticle;
1324
+ },
1325
+ create: {
1326
+ url: item.url !== undefined ? item.url : undefined,
1327
+ relevancyScore: item.relevancyScore !== undefined ? item.relevancyScore : undefined,
1328
+ sentimentScore: item.sentimentScore !== undefined ? item.sentimentScore : undefined,
1329
+ sentimentLabel: item.sentimentLabel !== undefined ? item.sentimentLabel : undefined,
1330
+ asset: item.asset ?
1331
+ typeof item.asset === 'object' && Object.keys(item.asset).length === 1 && Object.keys(item.asset)[0] === 'id'
1332
+ ? { connect: {
1333
+ id: item.asset.id
1334
+ }
1335
+ }
1336
+ : { connectOrCreate: {
1337
+ where: {
1338
+ id: item.asset.id !== undefined ? item.asset.id : undefined,
1339
+ symbol: item.asset.symbol !== undefined ? item.asset.symbol : undefined,
1340
+ name: item.asset.name !== undefined ? item.asset.name : undefined,
1341
+ },
1342
+ create: {
1343
+ symbol: item.asset.symbol !== undefined ? item.asset.symbol : undefined,
1344
+ name: item.asset.name !== undefined ? item.asset.name : undefined,
1345
+ type: item.asset.type !== undefined ? item.asset.type : undefined,
1346
+ logoUrl: item.asset.logoUrl !== undefined ? item.asset.logoUrl : undefined,
1347
+ description: item.asset.description !== undefined ? item.asset.description : undefined,
1348
+ cik: item.asset.cik !== undefined ? item.asset.cik : undefined,
1349
+ exchange: item.asset.exchange !== undefined ? item.asset.exchange : undefined,
1350
+ currency: item.asset.currency !== undefined ? item.asset.currency : undefined,
1351
+ country: item.asset.country !== undefined ? item.asset.country : undefined,
1352
+ sector: item.asset.sector !== undefined ? item.asset.sector : undefined,
1353
+ industry: item.asset.industry !== undefined ? item.asset.industry : undefined,
1354
+ address: item.asset.address !== undefined ? item.asset.address : undefined,
1355
+ officialSite: item.asset.officialSite !== undefined ? item.asset.officialSite : undefined,
1356
+ fiscalYearEnd: item.asset.fiscalYearEnd !== undefined ? item.asset.fiscalYearEnd : undefined,
1357
+ latestQuarter: item.asset.latestQuarter !== undefined ? item.asset.latestQuarter : undefined,
1358
+ marketCapitalization: item.asset.marketCapitalization !== undefined ? item.asset.marketCapitalization : undefined,
1359
+ ebitda: item.asset.ebitda !== undefined ? item.asset.ebitda : undefined,
1360
+ peRatio: item.asset.peRatio !== undefined ? item.asset.peRatio : undefined,
1361
+ pegRatio: item.asset.pegRatio !== undefined ? item.asset.pegRatio : undefined,
1362
+ bookValue: item.asset.bookValue !== undefined ? item.asset.bookValue : undefined,
1363
+ dividendPerShare: item.asset.dividendPerShare !== undefined ? item.asset.dividendPerShare : undefined,
1364
+ dividendYield: item.asset.dividendYield !== undefined ? item.asset.dividendYield : undefined,
1365
+ eps: item.asset.eps !== undefined ? item.asset.eps : undefined,
1366
+ revenuePerShareTTM: item.asset.revenuePerShareTTM !== undefined ? item.asset.revenuePerShareTTM : undefined,
1367
+ profitMargin: item.asset.profitMargin !== undefined ? item.asset.profitMargin : undefined,
1368
+ operatingMarginTTM: item.asset.operatingMarginTTM !== undefined ? item.asset.operatingMarginTTM : undefined,
1369
+ returnOnAssetsTTM: item.asset.returnOnAssetsTTM !== undefined ? item.asset.returnOnAssetsTTM : undefined,
1370
+ returnOnEquityTTM: item.asset.returnOnEquityTTM !== undefined ? item.asset.returnOnEquityTTM : undefined,
1371
+ revenueTTM: item.asset.revenueTTM !== undefined ? item.asset.revenueTTM : undefined,
1372
+ grossProfitTTM: item.asset.grossProfitTTM !== undefined ? item.asset.grossProfitTTM : undefined,
1373
+ dilutedEPSTTM: item.asset.dilutedEPSTTM !== undefined ? item.asset.dilutedEPSTTM : undefined,
1374
+ quarterlyEarningsGrowthYOY: item.asset.quarterlyEarningsGrowthYOY !== undefined ? item.asset.quarterlyEarningsGrowthYOY : undefined,
1375
+ quarterlyRevenueGrowthYOY: item.asset.quarterlyRevenueGrowthYOY !== undefined ? item.asset.quarterlyRevenueGrowthYOY : undefined,
1376
+ analystTargetPrice: item.asset.analystTargetPrice !== undefined ? item.asset.analystTargetPrice : undefined,
1377
+ analystRatingStrongBuy: item.asset.analystRatingStrongBuy !== undefined ? item.asset.analystRatingStrongBuy : undefined,
1378
+ analystRatingBuy: item.asset.analystRatingBuy !== undefined ? item.asset.analystRatingBuy : undefined,
1379
+ analystRatingHold: item.asset.analystRatingHold !== undefined ? item.asset.analystRatingHold : undefined,
1380
+ analystRatingSell: item.asset.analystRatingSell !== undefined ? item.asset.analystRatingSell : undefined,
1381
+ analystRatingStrongSell: item.asset.analystRatingStrongSell !== undefined ? item.asset.analystRatingStrongSell : undefined,
1382
+ trailingPE: item.asset.trailingPE !== undefined ? item.asset.trailingPE : undefined,
1383
+ forwardPE: item.asset.forwardPE !== undefined ? item.asset.forwardPE : undefined,
1384
+ priceToSalesRatioTTM: item.asset.priceToSalesRatioTTM !== undefined ? item.asset.priceToSalesRatioTTM : undefined,
1385
+ priceToBookRatio: item.asset.priceToBookRatio !== undefined ? item.asset.priceToBookRatio : undefined,
1386
+ evToRevenue: item.asset.evToRevenue !== undefined ? item.asset.evToRevenue : undefined,
1387
+ evToEbitda: item.asset.evToEbitda !== undefined ? item.asset.evToEbitda : undefined,
1388
+ beta: item.asset.beta !== undefined ? item.asset.beta : undefined,
1389
+ week52High: item.asset.week52High !== undefined ? item.asset.week52High : undefined,
1390
+ week52Low: item.asset.week52Low !== undefined ? item.asset.week52Low : undefined,
1391
+ day50MovingAverage: item.asset.day50MovingAverage !== undefined ? item.asset.day50MovingAverage : undefined,
1392
+ day200MovingAverage: item.asset.day200MovingAverage !== undefined ? item.asset.day200MovingAverage : undefined,
1393
+ sharesOutstanding: item.asset.sharesOutstanding !== undefined ? item.asset.sharesOutstanding : undefined,
1394
+ dividendDate: item.asset.dividendDate !== undefined ? item.asset.dividendDate : undefined,
1395
+ exDividendDate: item.asset.exDividendDate !== undefined ? item.asset.exDividendDate : undefined,
1396
+ askPrice: item.asset.askPrice !== undefined ? item.asset.askPrice : undefined,
1397
+ bidPrice: item.asset.bidPrice !== undefined ? item.asset.bidPrice : undefined,
1398
+ },
1399
+ }
1400
+ } : undefined,
1401
+ },
1402
+ }))
1403
+ } : undefined,
1404
+ },
1405
+ };
1406
+ const filteredVariables = removeUndefinedProps(variables);
1407
+ const response = await client.mutate({
1408
+ mutation: UPSERT_ONE_NEWSARTICLE,
1409
+ variables: filteredVariables,
1410
+ // Don't cache mutations, but ensure we're using the freshest context
1411
+ fetchPolicy: 'no-cache'
1412
+ });
1413
+ if (response.errors && response.errors.length > 0)
1414
+ throw new Error(response.errors[0].message);
1415
+ if (response && response.data && response.data.upsertOneNewsArticle) {
1416
+ return response.data.upsertOneNewsArticle;
1417
+ }
1418
+ else {
1419
+ return null;
1420
+ }
1309
1421
  }
1310
- else {
1311
- return null;
1422
+ catch (error) {
1423
+ lastError = error;
1424
+ // Check if this is a database connection error that we should retry
1425
+ const isConnectionError = error.message?.includes('Server has closed the connection') ||
1426
+ error.message?.includes('Cannot reach database server') ||
1427
+ error.message?.includes('Connection timed out') ||
1428
+ error.message?.includes('Accelerate') || // Prisma Accelerate proxy errors
1429
+ (error.networkError && error.networkError.message?.includes('Failed to fetch'));
1430
+ if (isConnectionError && retryCount < MAX_RETRIES - 1) {
1431
+ retryCount++;
1432
+ const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
1433
+ console.warn("Database connection error, retrying...");
1434
+ await new Promise(resolve => setTimeout(resolve, delay));
1435
+ continue;
1436
+ }
1437
+ // Log the error and rethrow
1438
+ console.error("Database error occurred:", error);
1439
+ throw error;
1312
1440
  }
1313
1441
  }
1314
- catch (error) {
1315
- console.error('Error in upsertOneNewsArticle:', error);
1316
- throw error;
1317
- }
1442
+ // If we exhausted retries, throw the last error
1443
+ throw lastError;
1318
1444
  },
1319
1445
  /**
1320
1446
  * Update multiple NewsArticle records.
1447
+ * Enhanced with connection resilience against Prisma connection errors.
1321
1448
  * @param props - Array of NewsArticle objects for the updated records.
1322
1449
  * @param globalClient - Apollo Client instance.
1323
1450
  * @returns The count of created records or null.
1324
1451
  */
1325
1452
  async updateMany(props, globalClient) {
1326
- const [modules, client] = await Promise.all([
1327
- getApolloModules(),
1328
- globalClient
1329
- ? Promise.resolve(globalClient)
1330
- : importedClient
1331
- ]);
1332
- const { gql, ApolloError } = modules;
1333
- const UPDATE_MANY_NEWSARTICLE = gql `
1334
- mutation updateManyNewsArticle($data: [NewsArticleCreateManyInput!]!) {
1335
- updateManyNewsArticle(data: $data) {
1336
- count
1337
- }
1338
- }`;
1339
- const variables = props.map(prop => ({
1340
- where: {
1341
- id: prop.id !== undefined ? prop.id : undefined,
1342
- url: prop.url !== undefined ? prop.url : undefined,
1343
- title: prop.title !== undefined ? {
1344
- equals: prop.title
1345
- } : undefined,
1346
- },
1347
- data: {
1348
- id: prop.id !== undefined ? {
1349
- set: prop.id
1350
- } : undefined,
1351
- title: prop.title !== undefined ? {
1352
- set: prop.title
1353
- } : undefined,
1354
- content: prop.content !== undefined ? {
1355
- set: prop.content
1356
- } : undefined,
1357
- source: prop.source !== undefined ? {
1358
- set: prop.source
1359
- } : undefined,
1360
- sourceDomain: prop.sourceDomain !== undefined ? {
1361
- set: prop.sourceDomain
1362
- } : undefined,
1363
- url: prop.url !== undefined ? {
1364
- set: prop.url
1365
- } : undefined,
1366
- sentiment: prop.sentiment !== undefined ? {
1367
- set: prop.sentiment
1368
- } : undefined,
1369
- authors: prop.authors !== undefined ? {
1370
- set: prop.authors
1371
- } : undefined,
1372
- summary: prop.summary !== undefined ? {
1373
- set: prop.summary
1374
- } : undefined,
1375
- bannerImage: prop.bannerImage !== undefined ? {
1376
- set: prop.bannerImage
1377
- } : undefined,
1378
- timePublished: prop.timePublished !== undefined ? {
1379
- set: prop.timePublished
1380
- } : undefined,
1381
- category: prop.category !== undefined ? {
1382
- set: prop.category
1383
- } : undefined,
1384
- topics: prop.topics !== undefined ? {
1385
- set: prop.topics
1386
- } : undefined,
1387
- logo: prop.logo !== undefined ? {
1388
- set: prop.logo
1389
- } : undefined,
1390
- createdAt: prop.createdAt !== undefined ? {
1391
- set: prop.createdAt
1392
- } : undefined,
1393
- updatedAt: prop.updatedAt !== undefined ? {
1394
- set: prop.updatedAt
1395
- } : undefined,
1396
- assets: prop.assets ?
1397
- Array.isArray(prop.assets) && prop.assets.length > 0 && prop.assets.every((item) => typeof item === 'object' && ('id' in item || 'symbol' in item) && Object.keys(item).length === 1) ? {
1398
- connect: prop.assets.map((item) => ({
1399
- id: item.id
1400
- }))
1401
- } : { upsert: prop.assets.map((item) => ({
1402
- where: {
1403
- id: item.id !== undefined ? item.id : undefined,
1404
- url: item.url !== undefined ? item.url : undefined,
1405
- assetId: item.assetId !== undefined ? {
1406
- equals: item.assetId
1407
- } : undefined,
1408
- newsArticleId: item.newsArticleId !== undefined ? {
1409
- equals: item.newsArticleId
1410
- } : undefined,
1411
- },
1412
- update: {
1413
- id: item.id !== undefined ? {
1414
- set: item.id
1415
- } : undefined,
1416
- url: item.url !== undefined ? {
1417
- set: item.url
1418
- } : undefined,
1419
- relevancyScore: item.relevancyScore !== undefined ? {
1420
- set: item.relevancyScore
1421
- } : undefined,
1422
- sentimentScore: item.sentimentScore !== undefined ? {
1423
- set: item.sentimentScore
1424
- } : undefined,
1425
- sentimentLabel: item.sentimentLabel !== undefined ? {
1426
- set: item.sentimentLabel
1427
- } : undefined,
1428
- asset: item.asset ?
1429
- typeof item.asset === 'object' && Object.keys(item.asset).length === 1 && (Object.keys(item.asset)[0] === 'id' || Object.keys(item.asset)[0] === 'symbol')
1430
- ? {
1431
- connect: {
1432
- id: item.asset.id
1433
- }
1434
- } : { upsert: {
1435
- where: {
1436
- id: item.asset.id !== undefined ? {
1437
- equals: item.asset.id
1438
- } : undefined,
1439
- symbol: item.asset.symbol !== undefined ? {
1440
- equals: item.asset.symbol
1441
- } : undefined,
1442
- name: item.asset.name !== undefined ? {
1443
- equals: item.asset.name
1444
- } : undefined,
1445
- },
1446
- update: {
1447
- id: item.asset.id !== undefined ? {
1448
- set: item.asset.id
1449
- } : undefined,
1450
- symbol: item.asset.symbol !== undefined ? {
1451
- set: item.asset.symbol
1452
- } : undefined,
1453
- name: item.asset.name !== undefined ? {
1454
- set: item.asset.name
1455
- } : undefined,
1456
- type: item.asset.type !== undefined ? {
1457
- set: item.asset.type
1458
- } : undefined,
1459
- logoUrl: item.asset.logoUrl !== undefined ? {
1460
- set: item.asset.logoUrl
1461
- } : undefined,
1462
- description: item.asset.description !== undefined ? {
1463
- set: item.asset.description
1464
- } : undefined,
1465
- cik: item.asset.cik !== undefined ? {
1466
- set: item.asset.cik
1467
- } : undefined,
1468
- exchange: item.asset.exchange !== undefined ? {
1469
- set: item.asset.exchange
1470
- } : undefined,
1471
- currency: item.asset.currency !== undefined ? {
1472
- set: item.asset.currency
1473
- } : undefined,
1474
- country: item.asset.country !== undefined ? {
1475
- set: item.asset.country
1476
- } : undefined,
1477
- sector: item.asset.sector !== undefined ? {
1478
- set: item.asset.sector
1479
- } : undefined,
1480
- industry: item.asset.industry !== undefined ? {
1481
- set: item.asset.industry
1482
- } : undefined,
1483
- address: item.asset.address !== undefined ? {
1484
- set: item.asset.address
1485
- } : undefined,
1486
- officialSite: item.asset.officialSite !== undefined ? {
1487
- set: item.asset.officialSite
1488
- } : undefined,
1489
- fiscalYearEnd: item.asset.fiscalYearEnd !== undefined ? {
1490
- set: item.asset.fiscalYearEnd
1491
- } : undefined,
1492
- latestQuarter: item.asset.latestQuarter !== undefined ? {
1493
- set: item.asset.latestQuarter
1494
- } : undefined,
1495
- marketCapitalization: item.asset.marketCapitalization !== undefined ? {
1496
- set: item.asset.marketCapitalization
1497
- } : undefined,
1498
- ebitda: item.asset.ebitda !== undefined ? {
1499
- set: item.asset.ebitda
1500
- } : undefined,
1501
- peRatio: item.asset.peRatio !== undefined ? {
1502
- set: item.asset.peRatio
1503
- } : undefined,
1504
- pegRatio: item.asset.pegRatio !== undefined ? {
1505
- set: item.asset.pegRatio
1506
- } : undefined,
1507
- bookValue: item.asset.bookValue !== undefined ? {
1508
- set: item.asset.bookValue
1509
- } : undefined,
1510
- dividendPerShare: item.asset.dividendPerShare !== undefined ? {
1511
- set: item.asset.dividendPerShare
1512
- } : undefined,
1513
- dividendYield: item.asset.dividendYield !== undefined ? {
1514
- set: item.asset.dividendYield
1515
- } : undefined,
1516
- eps: item.asset.eps !== undefined ? {
1517
- set: item.asset.eps
1518
- } : undefined,
1519
- revenuePerShareTTM: item.asset.revenuePerShareTTM !== undefined ? {
1520
- set: item.asset.revenuePerShareTTM
1521
- } : undefined,
1522
- profitMargin: item.asset.profitMargin !== undefined ? {
1523
- set: item.asset.profitMargin
1524
- } : undefined,
1525
- operatingMarginTTM: item.asset.operatingMarginTTM !== undefined ? {
1526
- set: item.asset.operatingMarginTTM
1527
- } : undefined,
1528
- returnOnAssetsTTM: item.asset.returnOnAssetsTTM !== undefined ? {
1529
- set: item.asset.returnOnAssetsTTM
1530
- } : undefined,
1531
- returnOnEquityTTM: item.asset.returnOnEquityTTM !== undefined ? {
1532
- set: item.asset.returnOnEquityTTM
1533
- } : undefined,
1534
- revenueTTM: item.asset.revenueTTM !== undefined ? {
1535
- set: item.asset.revenueTTM
1536
- } : undefined,
1537
- grossProfitTTM: item.asset.grossProfitTTM !== undefined ? {
1538
- set: item.asset.grossProfitTTM
1539
- } : undefined,
1540
- dilutedEPSTTM: item.asset.dilutedEPSTTM !== undefined ? {
1541
- set: item.asset.dilutedEPSTTM
1542
- } : undefined,
1543
- quarterlyEarningsGrowthYOY: item.asset.quarterlyEarningsGrowthYOY !== undefined ? {
1544
- set: item.asset.quarterlyEarningsGrowthYOY
1545
- } : undefined,
1546
- quarterlyRevenueGrowthYOY: item.asset.quarterlyRevenueGrowthYOY !== undefined ? {
1547
- set: item.asset.quarterlyRevenueGrowthYOY
1548
- } : undefined,
1549
- analystTargetPrice: item.asset.analystTargetPrice !== undefined ? {
1550
- set: item.asset.analystTargetPrice
1551
- } : undefined,
1552
- analystRatingStrongBuy: item.asset.analystRatingStrongBuy !== undefined ? {
1553
- set: item.asset.analystRatingStrongBuy
1554
- } : undefined,
1555
- analystRatingBuy: item.asset.analystRatingBuy !== undefined ? {
1556
- set: item.asset.analystRatingBuy
1557
- } : undefined,
1558
- analystRatingHold: item.asset.analystRatingHold !== undefined ? {
1559
- set: item.asset.analystRatingHold
1560
- } : undefined,
1561
- analystRatingSell: item.asset.analystRatingSell !== undefined ? {
1562
- set: item.asset.analystRatingSell
1563
- } : undefined,
1564
- analystRatingStrongSell: item.asset.analystRatingStrongSell !== undefined ? {
1565
- set: item.asset.analystRatingStrongSell
1566
- } : undefined,
1567
- trailingPE: item.asset.trailingPE !== undefined ? {
1568
- set: item.asset.trailingPE
1569
- } : undefined,
1570
- forwardPE: item.asset.forwardPE !== undefined ? {
1571
- set: item.asset.forwardPE
1572
- } : undefined,
1573
- priceToSalesRatioTTM: item.asset.priceToSalesRatioTTM !== undefined ? {
1574
- set: item.asset.priceToSalesRatioTTM
1575
- } : undefined,
1576
- priceToBookRatio: item.asset.priceToBookRatio !== undefined ? {
1577
- set: item.asset.priceToBookRatio
1578
- } : undefined,
1579
- evToRevenue: item.asset.evToRevenue !== undefined ? {
1580
- set: item.asset.evToRevenue
1581
- } : undefined,
1582
- evToEbitda: item.asset.evToEbitda !== undefined ? {
1583
- set: item.asset.evToEbitda
1584
- } : undefined,
1585
- beta: item.asset.beta !== undefined ? {
1586
- set: item.asset.beta
1587
- } : undefined,
1588
- week52High: item.asset.week52High !== undefined ? {
1589
- set: item.asset.week52High
1590
- } : undefined,
1591
- week52Low: item.asset.week52Low !== undefined ? {
1592
- set: item.asset.week52Low
1593
- } : undefined,
1594
- day50MovingAverage: item.asset.day50MovingAverage !== undefined ? {
1595
- set: item.asset.day50MovingAverage
1596
- } : undefined,
1597
- day200MovingAverage: item.asset.day200MovingAverage !== undefined ? {
1598
- set: item.asset.day200MovingAverage
1599
- } : undefined,
1600
- sharesOutstanding: item.asset.sharesOutstanding !== undefined ? {
1601
- set: item.asset.sharesOutstanding
1602
- } : undefined,
1603
- dividendDate: item.asset.dividendDate !== undefined ? {
1604
- set: item.asset.dividendDate
1605
- } : undefined,
1606
- exDividendDate: item.asset.exDividendDate !== undefined ? {
1607
- set: item.asset.exDividendDate
1608
- } : undefined,
1609
- askPrice: item.asset.askPrice !== undefined ? {
1610
- set: item.asset.askPrice
1611
- } : undefined,
1612
- bidPrice: item.asset.bidPrice !== undefined ? {
1613
- set: item.asset.bidPrice
1614
- } : undefined,
1615
- },
1616
- create: {
1617
- symbol: item.asset.symbol !== undefined ? item.asset.symbol : undefined,
1618
- name: item.asset.name !== undefined ? item.asset.name : undefined,
1619
- type: item.asset.type !== undefined ? item.asset.type : undefined,
1620
- logoUrl: item.asset.logoUrl !== undefined ? item.asset.logoUrl : undefined,
1621
- description: item.asset.description !== undefined ? item.asset.description : undefined,
1622
- cik: item.asset.cik !== undefined ? item.asset.cik : undefined,
1623
- exchange: item.asset.exchange !== undefined ? item.asset.exchange : undefined,
1624
- currency: item.asset.currency !== undefined ? item.asset.currency : undefined,
1625
- country: item.asset.country !== undefined ? item.asset.country : undefined,
1626
- sector: item.asset.sector !== undefined ? item.asset.sector : undefined,
1627
- industry: item.asset.industry !== undefined ? item.asset.industry : undefined,
1628
- address: item.asset.address !== undefined ? item.asset.address : undefined,
1629
- officialSite: item.asset.officialSite !== undefined ? item.asset.officialSite : undefined,
1630
- fiscalYearEnd: item.asset.fiscalYearEnd !== undefined ? item.asset.fiscalYearEnd : undefined,
1631
- latestQuarter: item.asset.latestQuarter !== undefined ? item.asset.latestQuarter : undefined,
1632
- marketCapitalization: item.asset.marketCapitalization !== undefined ? item.asset.marketCapitalization : undefined,
1633
- ebitda: item.asset.ebitda !== undefined ? item.asset.ebitda : undefined,
1634
- peRatio: item.asset.peRatio !== undefined ? item.asset.peRatio : undefined,
1635
- pegRatio: item.asset.pegRatio !== undefined ? item.asset.pegRatio : undefined,
1636
- bookValue: item.asset.bookValue !== undefined ? item.asset.bookValue : undefined,
1637
- dividendPerShare: item.asset.dividendPerShare !== undefined ? item.asset.dividendPerShare : undefined,
1638
- dividendYield: item.asset.dividendYield !== undefined ? item.asset.dividendYield : undefined,
1639
- eps: item.asset.eps !== undefined ? item.asset.eps : undefined,
1640
- revenuePerShareTTM: item.asset.revenuePerShareTTM !== undefined ? item.asset.revenuePerShareTTM : undefined,
1641
- profitMargin: item.asset.profitMargin !== undefined ? item.asset.profitMargin : undefined,
1642
- operatingMarginTTM: item.asset.operatingMarginTTM !== undefined ? item.asset.operatingMarginTTM : undefined,
1643
- returnOnAssetsTTM: item.asset.returnOnAssetsTTM !== undefined ? item.asset.returnOnAssetsTTM : undefined,
1644
- returnOnEquityTTM: item.asset.returnOnEquityTTM !== undefined ? item.asset.returnOnEquityTTM : undefined,
1645
- revenueTTM: item.asset.revenueTTM !== undefined ? item.asset.revenueTTM : undefined,
1646
- grossProfitTTM: item.asset.grossProfitTTM !== undefined ? item.asset.grossProfitTTM : undefined,
1647
- dilutedEPSTTM: item.asset.dilutedEPSTTM !== undefined ? item.asset.dilutedEPSTTM : undefined,
1648
- quarterlyEarningsGrowthYOY: item.asset.quarterlyEarningsGrowthYOY !== undefined ? item.asset.quarterlyEarningsGrowthYOY : undefined,
1649
- quarterlyRevenueGrowthYOY: item.asset.quarterlyRevenueGrowthYOY !== undefined ? item.asset.quarterlyRevenueGrowthYOY : undefined,
1650
- analystTargetPrice: item.asset.analystTargetPrice !== undefined ? item.asset.analystTargetPrice : undefined,
1651
- analystRatingStrongBuy: item.asset.analystRatingStrongBuy !== undefined ? item.asset.analystRatingStrongBuy : undefined,
1652
- analystRatingBuy: item.asset.analystRatingBuy !== undefined ? item.asset.analystRatingBuy : undefined,
1653
- analystRatingHold: item.asset.analystRatingHold !== undefined ? item.asset.analystRatingHold : undefined,
1654
- analystRatingSell: item.asset.analystRatingSell !== undefined ? item.asset.analystRatingSell : undefined,
1655
- analystRatingStrongSell: item.asset.analystRatingStrongSell !== undefined ? item.asset.analystRatingStrongSell : undefined,
1656
- trailingPE: item.asset.trailingPE !== undefined ? item.asset.trailingPE : undefined,
1657
- forwardPE: item.asset.forwardPE !== undefined ? item.asset.forwardPE : undefined,
1658
- priceToSalesRatioTTM: item.asset.priceToSalesRatioTTM !== undefined ? item.asset.priceToSalesRatioTTM : undefined,
1659
- priceToBookRatio: item.asset.priceToBookRatio !== undefined ? item.asset.priceToBookRatio : undefined,
1660
- evToRevenue: item.asset.evToRevenue !== undefined ? item.asset.evToRevenue : undefined,
1661
- evToEbitda: item.asset.evToEbitda !== undefined ? item.asset.evToEbitda : undefined,
1662
- beta: item.asset.beta !== undefined ? item.asset.beta : undefined,
1663
- week52High: item.asset.week52High !== undefined ? item.asset.week52High : undefined,
1664
- week52Low: item.asset.week52Low !== undefined ? item.asset.week52Low : undefined,
1665
- day50MovingAverage: item.asset.day50MovingAverage !== undefined ? item.asset.day50MovingAverage : undefined,
1666
- day200MovingAverage: item.asset.day200MovingAverage !== undefined ? item.asset.day200MovingAverage : undefined,
1667
- sharesOutstanding: item.asset.sharesOutstanding !== undefined ? item.asset.sharesOutstanding : undefined,
1668
- dividendDate: item.asset.dividendDate !== undefined ? item.asset.dividendDate : undefined,
1669
- exDividendDate: item.asset.exDividendDate !== undefined ? item.asset.exDividendDate : undefined,
1670
- askPrice: item.asset.askPrice !== undefined ? item.asset.askPrice : undefined,
1671
- bidPrice: item.asset.bidPrice !== undefined ? item.asset.bidPrice : undefined,
1672
- },
1673
- }
1674
- } : undefined,
1675
- },
1676
- create: {
1677
- url: item.url !== undefined ? item.url : undefined,
1678
- relevancyScore: item.relevancyScore !== undefined ? item.relevancyScore : undefined,
1679
- sentimentScore: item.sentimentScore !== undefined ? item.sentimentScore : undefined,
1680
- sentimentLabel: item.sentimentLabel !== undefined ? item.sentimentLabel : undefined,
1681
- asset: item.asset ?
1682
- typeof item.asset === 'object' && Object.keys(item.asset).length === 1 && Object.keys(item.asset)[0] === 'id'
1683
- ? { connect: {
1684
- id: item.asset.id
1685
- }
1686
- }
1687
- : { connectOrCreate: {
1688
- where: {
1689
- id: item.asset.id !== undefined ? item.asset.id : undefined,
1690
- symbol: item.asset.symbol !== undefined ? item.asset.symbol : undefined,
1691
- name: item.asset.name !== undefined ? item.asset.name : undefined,
1692
- },
1693
- create: {
1694
- symbol: item.asset.symbol !== undefined ? item.asset.symbol : undefined,
1695
- name: item.asset.name !== undefined ? item.asset.name : undefined,
1696
- type: item.asset.type !== undefined ? item.asset.type : undefined,
1697
- logoUrl: item.asset.logoUrl !== undefined ? item.asset.logoUrl : undefined,
1698
- description: item.asset.description !== undefined ? item.asset.description : undefined,
1699
- cik: item.asset.cik !== undefined ? item.asset.cik : undefined,
1700
- exchange: item.asset.exchange !== undefined ? item.asset.exchange : undefined,
1701
- currency: item.asset.currency !== undefined ? item.asset.currency : undefined,
1702
- country: item.asset.country !== undefined ? item.asset.country : undefined,
1703
- sector: item.asset.sector !== undefined ? item.asset.sector : undefined,
1704
- industry: item.asset.industry !== undefined ? item.asset.industry : undefined,
1705
- address: item.asset.address !== undefined ? item.asset.address : undefined,
1706
- officialSite: item.asset.officialSite !== undefined ? item.asset.officialSite : undefined,
1707
- fiscalYearEnd: item.asset.fiscalYearEnd !== undefined ? item.asset.fiscalYearEnd : undefined,
1708
- latestQuarter: item.asset.latestQuarter !== undefined ? item.asset.latestQuarter : undefined,
1709
- marketCapitalization: item.asset.marketCapitalization !== undefined ? item.asset.marketCapitalization : undefined,
1710
- ebitda: item.asset.ebitda !== undefined ? item.asset.ebitda : undefined,
1711
- peRatio: item.asset.peRatio !== undefined ? item.asset.peRatio : undefined,
1712
- pegRatio: item.asset.pegRatio !== undefined ? item.asset.pegRatio : undefined,
1713
- bookValue: item.asset.bookValue !== undefined ? item.asset.bookValue : undefined,
1714
- dividendPerShare: item.asset.dividendPerShare !== undefined ? item.asset.dividendPerShare : undefined,
1715
- dividendYield: item.asset.dividendYield !== undefined ? item.asset.dividendYield : undefined,
1716
- eps: item.asset.eps !== undefined ? item.asset.eps : undefined,
1717
- revenuePerShareTTM: item.asset.revenuePerShareTTM !== undefined ? item.asset.revenuePerShareTTM : undefined,
1718
- profitMargin: item.asset.profitMargin !== undefined ? item.asset.profitMargin : undefined,
1719
- operatingMarginTTM: item.asset.operatingMarginTTM !== undefined ? item.asset.operatingMarginTTM : undefined,
1720
- returnOnAssetsTTM: item.asset.returnOnAssetsTTM !== undefined ? item.asset.returnOnAssetsTTM : undefined,
1721
- returnOnEquityTTM: item.asset.returnOnEquityTTM !== undefined ? item.asset.returnOnEquityTTM : undefined,
1722
- revenueTTM: item.asset.revenueTTM !== undefined ? item.asset.revenueTTM : undefined,
1723
- grossProfitTTM: item.asset.grossProfitTTM !== undefined ? item.asset.grossProfitTTM : undefined,
1724
- dilutedEPSTTM: item.asset.dilutedEPSTTM !== undefined ? item.asset.dilutedEPSTTM : undefined,
1725
- quarterlyEarningsGrowthYOY: item.asset.quarterlyEarningsGrowthYOY !== undefined ? item.asset.quarterlyEarningsGrowthYOY : undefined,
1726
- quarterlyRevenueGrowthYOY: item.asset.quarterlyRevenueGrowthYOY !== undefined ? item.asset.quarterlyRevenueGrowthYOY : undefined,
1727
- analystTargetPrice: item.asset.analystTargetPrice !== undefined ? item.asset.analystTargetPrice : undefined,
1728
- analystRatingStrongBuy: item.asset.analystRatingStrongBuy !== undefined ? item.asset.analystRatingStrongBuy : undefined,
1729
- analystRatingBuy: item.asset.analystRatingBuy !== undefined ? item.asset.analystRatingBuy : undefined,
1730
- analystRatingHold: item.asset.analystRatingHold !== undefined ? item.asset.analystRatingHold : undefined,
1731
- analystRatingSell: item.asset.analystRatingSell !== undefined ? item.asset.analystRatingSell : undefined,
1732
- analystRatingStrongSell: item.asset.analystRatingStrongSell !== undefined ? item.asset.analystRatingStrongSell : undefined,
1733
- trailingPE: item.asset.trailingPE !== undefined ? item.asset.trailingPE : undefined,
1734
- forwardPE: item.asset.forwardPE !== undefined ? item.asset.forwardPE : undefined,
1735
- priceToSalesRatioTTM: item.asset.priceToSalesRatioTTM !== undefined ? item.asset.priceToSalesRatioTTM : undefined,
1736
- priceToBookRatio: item.asset.priceToBookRatio !== undefined ? item.asset.priceToBookRatio : undefined,
1737
- evToRevenue: item.asset.evToRevenue !== undefined ? item.asset.evToRevenue : undefined,
1738
- evToEbitda: item.asset.evToEbitda !== undefined ? item.asset.evToEbitda : undefined,
1739
- beta: item.asset.beta !== undefined ? item.asset.beta : undefined,
1740
- week52High: item.asset.week52High !== undefined ? item.asset.week52High : undefined,
1741
- week52Low: item.asset.week52Low !== undefined ? item.asset.week52Low : undefined,
1742
- day50MovingAverage: item.asset.day50MovingAverage !== undefined ? item.asset.day50MovingAverage : undefined,
1743
- day200MovingAverage: item.asset.day200MovingAverage !== undefined ? item.asset.day200MovingAverage : undefined,
1744
- sharesOutstanding: item.asset.sharesOutstanding !== undefined ? item.asset.sharesOutstanding : undefined,
1745
- dividendDate: item.asset.dividendDate !== undefined ? item.asset.dividendDate : undefined,
1746
- exDividendDate: item.asset.exDividendDate !== undefined ? item.asset.exDividendDate : undefined,
1747
- askPrice: item.asset.askPrice !== undefined ? item.asset.askPrice : undefined,
1748
- bidPrice: item.asset.bidPrice !== undefined ? item.asset.bidPrice : undefined,
1749
- },
1750
- }
1453
+ // Maximum number of retries for database connection issues
1454
+ const MAX_RETRIES = 3;
1455
+ let retryCount = 0;
1456
+ let lastError = null;
1457
+ // Retry loop to handle potential database connection issues
1458
+ while (retryCount < MAX_RETRIES) {
1459
+ try {
1460
+ const [modules, client] = await Promise.all([
1461
+ getApolloModules(),
1462
+ globalClient
1463
+ ? Promise.resolve(globalClient)
1464
+ : importedClient
1465
+ ]);
1466
+ const { gql, ApolloError } = modules;
1467
+ const UPDATE_MANY_NEWSARTICLE = gql `
1468
+ mutation updateManyNewsArticle($data: [NewsArticleCreateManyInput!]!) {
1469
+ updateManyNewsArticle(data: $data) {
1470
+ count
1471
+ }
1472
+ }`;
1473
+ const variables = props.map(prop => ({
1474
+ where: {
1475
+ id: prop.id !== undefined ? prop.id : undefined,
1476
+ url: prop.url !== undefined ? prop.url : undefined,
1477
+ title: prop.title !== undefined ? {
1478
+ equals: prop.title
1479
+ } : undefined,
1480
+ },
1481
+ data: {
1482
+ id: prop.id !== undefined ? {
1483
+ set: prop.id
1484
+ } : undefined,
1485
+ title: prop.title !== undefined ? {
1486
+ set: prop.title
1487
+ } : undefined,
1488
+ content: prop.content !== undefined ? {
1489
+ set: prop.content
1490
+ } : undefined,
1491
+ source: prop.source !== undefined ? {
1492
+ set: prop.source
1493
+ } : undefined,
1494
+ sourceDomain: prop.sourceDomain !== undefined ? {
1495
+ set: prop.sourceDomain
1496
+ } : undefined,
1497
+ url: prop.url !== undefined ? {
1498
+ set: prop.url
1499
+ } : undefined,
1500
+ sentiment: prop.sentiment !== undefined ? {
1501
+ set: prop.sentiment
1502
+ } : undefined,
1503
+ authors: prop.authors !== undefined ? {
1504
+ set: prop.authors
1505
+ } : undefined,
1506
+ summary: prop.summary !== undefined ? {
1507
+ set: prop.summary
1508
+ } : undefined,
1509
+ bannerImage: prop.bannerImage !== undefined ? {
1510
+ set: prop.bannerImage
1511
+ } : undefined,
1512
+ timePublished: prop.timePublished !== undefined ? {
1513
+ set: prop.timePublished
1514
+ } : undefined,
1515
+ category: prop.category !== undefined ? {
1516
+ set: prop.category
1517
+ } : undefined,
1518
+ topics: prop.topics !== undefined ? {
1519
+ set: prop.topics
1520
+ } : undefined,
1521
+ logo: prop.logo !== undefined ? {
1522
+ set: prop.logo
1523
+ } : undefined,
1524
+ createdAt: prop.createdAt !== undefined ? {
1525
+ set: prop.createdAt
1526
+ } : undefined,
1527
+ updatedAt: prop.updatedAt !== undefined ? {
1528
+ set: prop.updatedAt
1529
+ } : undefined,
1530
+ assets: prop.assets ?
1531
+ Array.isArray(prop.assets) && prop.assets.length > 0 && prop.assets.every((item) => typeof item === 'object' && ('id' in item || 'symbol' in item) && Object.keys(item).length === 1) ? {
1532
+ connect: prop.assets.map((item) => ({
1533
+ id: item.id
1534
+ }))
1535
+ } : { upsert: prop.assets.map((item) => ({
1536
+ where: {
1537
+ id: item.id !== undefined ? item.id : undefined,
1538
+ url: item.url !== undefined ? item.url : undefined,
1539
+ assetId: item.assetId !== undefined ? {
1540
+ equals: item.assetId
1541
+ } : undefined,
1542
+ newsArticleId: item.newsArticleId !== undefined ? {
1543
+ equals: item.newsArticleId
1751
1544
  } : undefined,
1752
- },
1753
- }))
1754
- } : undefined,
1755
- },
1756
- }));
1757
- const filteredVariables = removeUndefinedProps(variables);
1758
- try {
1759
- const response = await client.mutate({ mutation: UPDATE_MANY_NEWSARTICLE, variables: filteredVariables });
1760
- if (response.errors && response.errors.length > 0)
1761
- throw new Error(response.errors[0].message);
1762
- if (response && response.data && response.data.updateManyNewsArticle) {
1763
- return response.data.updateManyNewsArticle;
1545
+ },
1546
+ update: {
1547
+ id: item.id !== undefined ? {
1548
+ set: item.id
1549
+ } : undefined,
1550
+ url: item.url !== undefined ? {
1551
+ set: item.url
1552
+ } : undefined,
1553
+ relevancyScore: item.relevancyScore !== undefined ? {
1554
+ set: item.relevancyScore
1555
+ } : undefined,
1556
+ sentimentScore: item.sentimentScore !== undefined ? {
1557
+ set: item.sentimentScore
1558
+ } : undefined,
1559
+ sentimentLabel: item.sentimentLabel !== undefined ? {
1560
+ set: item.sentimentLabel
1561
+ } : undefined,
1562
+ asset: item.asset ?
1563
+ typeof item.asset === 'object' && Object.keys(item.asset).length === 1 && (Object.keys(item.asset)[0] === 'id' || Object.keys(item.asset)[0] === 'symbol')
1564
+ ? {
1565
+ connect: {
1566
+ id: item.asset.id
1567
+ }
1568
+ } : { upsert: {
1569
+ where: {
1570
+ id: item.asset.id !== undefined ? {
1571
+ equals: item.asset.id
1572
+ } : undefined,
1573
+ symbol: item.asset.symbol !== undefined ? {
1574
+ equals: item.asset.symbol
1575
+ } : undefined,
1576
+ name: item.asset.name !== undefined ? {
1577
+ equals: item.asset.name
1578
+ } : undefined,
1579
+ },
1580
+ update: {
1581
+ id: item.asset.id !== undefined ? {
1582
+ set: item.asset.id
1583
+ } : undefined,
1584
+ symbol: item.asset.symbol !== undefined ? {
1585
+ set: item.asset.symbol
1586
+ } : undefined,
1587
+ name: item.asset.name !== undefined ? {
1588
+ set: item.asset.name
1589
+ } : undefined,
1590
+ type: item.asset.type !== undefined ? {
1591
+ set: item.asset.type
1592
+ } : undefined,
1593
+ logoUrl: item.asset.logoUrl !== undefined ? {
1594
+ set: item.asset.logoUrl
1595
+ } : undefined,
1596
+ description: item.asset.description !== undefined ? {
1597
+ set: item.asset.description
1598
+ } : undefined,
1599
+ cik: item.asset.cik !== undefined ? {
1600
+ set: item.asset.cik
1601
+ } : undefined,
1602
+ exchange: item.asset.exchange !== undefined ? {
1603
+ set: item.asset.exchange
1604
+ } : undefined,
1605
+ currency: item.asset.currency !== undefined ? {
1606
+ set: item.asset.currency
1607
+ } : undefined,
1608
+ country: item.asset.country !== undefined ? {
1609
+ set: item.asset.country
1610
+ } : undefined,
1611
+ sector: item.asset.sector !== undefined ? {
1612
+ set: item.asset.sector
1613
+ } : undefined,
1614
+ industry: item.asset.industry !== undefined ? {
1615
+ set: item.asset.industry
1616
+ } : undefined,
1617
+ address: item.asset.address !== undefined ? {
1618
+ set: item.asset.address
1619
+ } : undefined,
1620
+ officialSite: item.asset.officialSite !== undefined ? {
1621
+ set: item.asset.officialSite
1622
+ } : undefined,
1623
+ fiscalYearEnd: item.asset.fiscalYearEnd !== undefined ? {
1624
+ set: item.asset.fiscalYearEnd
1625
+ } : undefined,
1626
+ latestQuarter: item.asset.latestQuarter !== undefined ? {
1627
+ set: item.asset.latestQuarter
1628
+ } : undefined,
1629
+ marketCapitalization: item.asset.marketCapitalization !== undefined ? {
1630
+ set: item.asset.marketCapitalization
1631
+ } : undefined,
1632
+ ebitda: item.asset.ebitda !== undefined ? {
1633
+ set: item.asset.ebitda
1634
+ } : undefined,
1635
+ peRatio: item.asset.peRatio !== undefined ? {
1636
+ set: item.asset.peRatio
1637
+ } : undefined,
1638
+ pegRatio: item.asset.pegRatio !== undefined ? {
1639
+ set: item.asset.pegRatio
1640
+ } : undefined,
1641
+ bookValue: item.asset.bookValue !== undefined ? {
1642
+ set: item.asset.bookValue
1643
+ } : undefined,
1644
+ dividendPerShare: item.asset.dividendPerShare !== undefined ? {
1645
+ set: item.asset.dividendPerShare
1646
+ } : undefined,
1647
+ dividendYield: item.asset.dividendYield !== undefined ? {
1648
+ set: item.asset.dividendYield
1649
+ } : undefined,
1650
+ eps: item.asset.eps !== undefined ? {
1651
+ set: item.asset.eps
1652
+ } : undefined,
1653
+ revenuePerShareTTM: item.asset.revenuePerShareTTM !== undefined ? {
1654
+ set: item.asset.revenuePerShareTTM
1655
+ } : undefined,
1656
+ profitMargin: item.asset.profitMargin !== undefined ? {
1657
+ set: item.asset.profitMargin
1658
+ } : undefined,
1659
+ operatingMarginTTM: item.asset.operatingMarginTTM !== undefined ? {
1660
+ set: item.asset.operatingMarginTTM
1661
+ } : undefined,
1662
+ returnOnAssetsTTM: item.asset.returnOnAssetsTTM !== undefined ? {
1663
+ set: item.asset.returnOnAssetsTTM
1664
+ } : undefined,
1665
+ returnOnEquityTTM: item.asset.returnOnEquityTTM !== undefined ? {
1666
+ set: item.asset.returnOnEquityTTM
1667
+ } : undefined,
1668
+ revenueTTM: item.asset.revenueTTM !== undefined ? {
1669
+ set: item.asset.revenueTTM
1670
+ } : undefined,
1671
+ grossProfitTTM: item.asset.grossProfitTTM !== undefined ? {
1672
+ set: item.asset.grossProfitTTM
1673
+ } : undefined,
1674
+ dilutedEPSTTM: item.asset.dilutedEPSTTM !== undefined ? {
1675
+ set: item.asset.dilutedEPSTTM
1676
+ } : undefined,
1677
+ quarterlyEarningsGrowthYOY: item.asset.quarterlyEarningsGrowthYOY !== undefined ? {
1678
+ set: item.asset.quarterlyEarningsGrowthYOY
1679
+ } : undefined,
1680
+ quarterlyRevenueGrowthYOY: item.asset.quarterlyRevenueGrowthYOY !== undefined ? {
1681
+ set: item.asset.quarterlyRevenueGrowthYOY
1682
+ } : undefined,
1683
+ analystTargetPrice: item.asset.analystTargetPrice !== undefined ? {
1684
+ set: item.asset.analystTargetPrice
1685
+ } : undefined,
1686
+ analystRatingStrongBuy: item.asset.analystRatingStrongBuy !== undefined ? {
1687
+ set: item.asset.analystRatingStrongBuy
1688
+ } : undefined,
1689
+ analystRatingBuy: item.asset.analystRatingBuy !== undefined ? {
1690
+ set: item.asset.analystRatingBuy
1691
+ } : undefined,
1692
+ analystRatingHold: item.asset.analystRatingHold !== undefined ? {
1693
+ set: item.asset.analystRatingHold
1694
+ } : undefined,
1695
+ analystRatingSell: item.asset.analystRatingSell !== undefined ? {
1696
+ set: item.asset.analystRatingSell
1697
+ } : undefined,
1698
+ analystRatingStrongSell: item.asset.analystRatingStrongSell !== undefined ? {
1699
+ set: item.asset.analystRatingStrongSell
1700
+ } : undefined,
1701
+ trailingPE: item.asset.trailingPE !== undefined ? {
1702
+ set: item.asset.trailingPE
1703
+ } : undefined,
1704
+ forwardPE: item.asset.forwardPE !== undefined ? {
1705
+ set: item.asset.forwardPE
1706
+ } : undefined,
1707
+ priceToSalesRatioTTM: item.asset.priceToSalesRatioTTM !== undefined ? {
1708
+ set: item.asset.priceToSalesRatioTTM
1709
+ } : undefined,
1710
+ priceToBookRatio: item.asset.priceToBookRatio !== undefined ? {
1711
+ set: item.asset.priceToBookRatio
1712
+ } : undefined,
1713
+ evToRevenue: item.asset.evToRevenue !== undefined ? {
1714
+ set: item.asset.evToRevenue
1715
+ } : undefined,
1716
+ evToEbitda: item.asset.evToEbitda !== undefined ? {
1717
+ set: item.asset.evToEbitda
1718
+ } : undefined,
1719
+ beta: item.asset.beta !== undefined ? {
1720
+ set: item.asset.beta
1721
+ } : undefined,
1722
+ week52High: item.asset.week52High !== undefined ? {
1723
+ set: item.asset.week52High
1724
+ } : undefined,
1725
+ week52Low: item.asset.week52Low !== undefined ? {
1726
+ set: item.asset.week52Low
1727
+ } : undefined,
1728
+ day50MovingAverage: item.asset.day50MovingAverage !== undefined ? {
1729
+ set: item.asset.day50MovingAverage
1730
+ } : undefined,
1731
+ day200MovingAverage: item.asset.day200MovingAverage !== undefined ? {
1732
+ set: item.asset.day200MovingAverage
1733
+ } : undefined,
1734
+ sharesOutstanding: item.asset.sharesOutstanding !== undefined ? {
1735
+ set: item.asset.sharesOutstanding
1736
+ } : undefined,
1737
+ dividendDate: item.asset.dividendDate !== undefined ? {
1738
+ set: item.asset.dividendDate
1739
+ } : undefined,
1740
+ exDividendDate: item.asset.exDividendDate !== undefined ? {
1741
+ set: item.asset.exDividendDate
1742
+ } : undefined,
1743
+ askPrice: item.asset.askPrice !== undefined ? {
1744
+ set: item.asset.askPrice
1745
+ } : undefined,
1746
+ bidPrice: item.asset.bidPrice !== undefined ? {
1747
+ set: item.asset.bidPrice
1748
+ } : undefined,
1749
+ },
1750
+ create: {
1751
+ symbol: item.asset.symbol !== undefined ? item.asset.symbol : undefined,
1752
+ name: item.asset.name !== undefined ? item.asset.name : undefined,
1753
+ type: item.asset.type !== undefined ? item.asset.type : undefined,
1754
+ logoUrl: item.asset.logoUrl !== undefined ? item.asset.logoUrl : undefined,
1755
+ description: item.asset.description !== undefined ? item.asset.description : undefined,
1756
+ cik: item.asset.cik !== undefined ? item.asset.cik : undefined,
1757
+ exchange: item.asset.exchange !== undefined ? item.asset.exchange : undefined,
1758
+ currency: item.asset.currency !== undefined ? item.asset.currency : undefined,
1759
+ country: item.asset.country !== undefined ? item.asset.country : undefined,
1760
+ sector: item.asset.sector !== undefined ? item.asset.sector : undefined,
1761
+ industry: item.asset.industry !== undefined ? item.asset.industry : undefined,
1762
+ address: item.asset.address !== undefined ? item.asset.address : undefined,
1763
+ officialSite: item.asset.officialSite !== undefined ? item.asset.officialSite : undefined,
1764
+ fiscalYearEnd: item.asset.fiscalYearEnd !== undefined ? item.asset.fiscalYearEnd : undefined,
1765
+ latestQuarter: item.asset.latestQuarter !== undefined ? item.asset.latestQuarter : undefined,
1766
+ marketCapitalization: item.asset.marketCapitalization !== undefined ? item.asset.marketCapitalization : undefined,
1767
+ ebitda: item.asset.ebitda !== undefined ? item.asset.ebitda : undefined,
1768
+ peRatio: item.asset.peRatio !== undefined ? item.asset.peRatio : undefined,
1769
+ pegRatio: item.asset.pegRatio !== undefined ? item.asset.pegRatio : undefined,
1770
+ bookValue: item.asset.bookValue !== undefined ? item.asset.bookValue : undefined,
1771
+ dividendPerShare: item.asset.dividendPerShare !== undefined ? item.asset.dividendPerShare : undefined,
1772
+ dividendYield: item.asset.dividendYield !== undefined ? item.asset.dividendYield : undefined,
1773
+ eps: item.asset.eps !== undefined ? item.asset.eps : undefined,
1774
+ revenuePerShareTTM: item.asset.revenuePerShareTTM !== undefined ? item.asset.revenuePerShareTTM : undefined,
1775
+ profitMargin: item.asset.profitMargin !== undefined ? item.asset.profitMargin : undefined,
1776
+ operatingMarginTTM: item.asset.operatingMarginTTM !== undefined ? item.asset.operatingMarginTTM : undefined,
1777
+ returnOnAssetsTTM: item.asset.returnOnAssetsTTM !== undefined ? item.asset.returnOnAssetsTTM : undefined,
1778
+ returnOnEquityTTM: item.asset.returnOnEquityTTM !== undefined ? item.asset.returnOnEquityTTM : undefined,
1779
+ revenueTTM: item.asset.revenueTTM !== undefined ? item.asset.revenueTTM : undefined,
1780
+ grossProfitTTM: item.asset.grossProfitTTM !== undefined ? item.asset.grossProfitTTM : undefined,
1781
+ dilutedEPSTTM: item.asset.dilutedEPSTTM !== undefined ? item.asset.dilutedEPSTTM : undefined,
1782
+ quarterlyEarningsGrowthYOY: item.asset.quarterlyEarningsGrowthYOY !== undefined ? item.asset.quarterlyEarningsGrowthYOY : undefined,
1783
+ quarterlyRevenueGrowthYOY: item.asset.quarterlyRevenueGrowthYOY !== undefined ? item.asset.quarterlyRevenueGrowthYOY : undefined,
1784
+ analystTargetPrice: item.asset.analystTargetPrice !== undefined ? item.asset.analystTargetPrice : undefined,
1785
+ analystRatingStrongBuy: item.asset.analystRatingStrongBuy !== undefined ? item.asset.analystRatingStrongBuy : undefined,
1786
+ analystRatingBuy: item.asset.analystRatingBuy !== undefined ? item.asset.analystRatingBuy : undefined,
1787
+ analystRatingHold: item.asset.analystRatingHold !== undefined ? item.asset.analystRatingHold : undefined,
1788
+ analystRatingSell: item.asset.analystRatingSell !== undefined ? item.asset.analystRatingSell : undefined,
1789
+ analystRatingStrongSell: item.asset.analystRatingStrongSell !== undefined ? item.asset.analystRatingStrongSell : undefined,
1790
+ trailingPE: item.asset.trailingPE !== undefined ? item.asset.trailingPE : undefined,
1791
+ forwardPE: item.asset.forwardPE !== undefined ? item.asset.forwardPE : undefined,
1792
+ priceToSalesRatioTTM: item.asset.priceToSalesRatioTTM !== undefined ? item.asset.priceToSalesRatioTTM : undefined,
1793
+ priceToBookRatio: item.asset.priceToBookRatio !== undefined ? item.asset.priceToBookRatio : undefined,
1794
+ evToRevenue: item.asset.evToRevenue !== undefined ? item.asset.evToRevenue : undefined,
1795
+ evToEbitda: item.asset.evToEbitda !== undefined ? item.asset.evToEbitda : undefined,
1796
+ beta: item.asset.beta !== undefined ? item.asset.beta : undefined,
1797
+ week52High: item.asset.week52High !== undefined ? item.asset.week52High : undefined,
1798
+ week52Low: item.asset.week52Low !== undefined ? item.asset.week52Low : undefined,
1799
+ day50MovingAverage: item.asset.day50MovingAverage !== undefined ? item.asset.day50MovingAverage : undefined,
1800
+ day200MovingAverage: item.asset.day200MovingAverage !== undefined ? item.asset.day200MovingAverage : undefined,
1801
+ sharesOutstanding: item.asset.sharesOutstanding !== undefined ? item.asset.sharesOutstanding : undefined,
1802
+ dividendDate: item.asset.dividendDate !== undefined ? item.asset.dividendDate : undefined,
1803
+ exDividendDate: item.asset.exDividendDate !== undefined ? item.asset.exDividendDate : undefined,
1804
+ askPrice: item.asset.askPrice !== undefined ? item.asset.askPrice : undefined,
1805
+ bidPrice: item.asset.bidPrice !== undefined ? item.asset.bidPrice : undefined,
1806
+ },
1807
+ }
1808
+ } : undefined,
1809
+ },
1810
+ create: {
1811
+ url: item.url !== undefined ? item.url : undefined,
1812
+ relevancyScore: item.relevancyScore !== undefined ? item.relevancyScore : undefined,
1813
+ sentimentScore: item.sentimentScore !== undefined ? item.sentimentScore : undefined,
1814
+ sentimentLabel: item.sentimentLabel !== undefined ? item.sentimentLabel : undefined,
1815
+ asset: item.asset ?
1816
+ typeof item.asset === 'object' && Object.keys(item.asset).length === 1 && Object.keys(item.asset)[0] === 'id'
1817
+ ? { connect: {
1818
+ id: item.asset.id
1819
+ }
1820
+ }
1821
+ : { connectOrCreate: {
1822
+ where: {
1823
+ id: item.asset.id !== undefined ? item.asset.id : undefined,
1824
+ symbol: item.asset.symbol !== undefined ? item.asset.symbol : undefined,
1825
+ name: item.asset.name !== undefined ? item.asset.name : undefined,
1826
+ },
1827
+ create: {
1828
+ symbol: item.asset.symbol !== undefined ? item.asset.symbol : undefined,
1829
+ name: item.asset.name !== undefined ? item.asset.name : undefined,
1830
+ type: item.asset.type !== undefined ? item.asset.type : undefined,
1831
+ logoUrl: item.asset.logoUrl !== undefined ? item.asset.logoUrl : undefined,
1832
+ description: item.asset.description !== undefined ? item.asset.description : undefined,
1833
+ cik: item.asset.cik !== undefined ? item.asset.cik : undefined,
1834
+ exchange: item.asset.exchange !== undefined ? item.asset.exchange : undefined,
1835
+ currency: item.asset.currency !== undefined ? item.asset.currency : undefined,
1836
+ country: item.asset.country !== undefined ? item.asset.country : undefined,
1837
+ sector: item.asset.sector !== undefined ? item.asset.sector : undefined,
1838
+ industry: item.asset.industry !== undefined ? item.asset.industry : undefined,
1839
+ address: item.asset.address !== undefined ? item.asset.address : undefined,
1840
+ officialSite: item.asset.officialSite !== undefined ? item.asset.officialSite : undefined,
1841
+ fiscalYearEnd: item.asset.fiscalYearEnd !== undefined ? item.asset.fiscalYearEnd : undefined,
1842
+ latestQuarter: item.asset.latestQuarter !== undefined ? item.asset.latestQuarter : undefined,
1843
+ marketCapitalization: item.asset.marketCapitalization !== undefined ? item.asset.marketCapitalization : undefined,
1844
+ ebitda: item.asset.ebitda !== undefined ? item.asset.ebitda : undefined,
1845
+ peRatio: item.asset.peRatio !== undefined ? item.asset.peRatio : undefined,
1846
+ pegRatio: item.asset.pegRatio !== undefined ? item.asset.pegRatio : undefined,
1847
+ bookValue: item.asset.bookValue !== undefined ? item.asset.bookValue : undefined,
1848
+ dividendPerShare: item.asset.dividendPerShare !== undefined ? item.asset.dividendPerShare : undefined,
1849
+ dividendYield: item.asset.dividendYield !== undefined ? item.asset.dividendYield : undefined,
1850
+ eps: item.asset.eps !== undefined ? item.asset.eps : undefined,
1851
+ revenuePerShareTTM: item.asset.revenuePerShareTTM !== undefined ? item.asset.revenuePerShareTTM : undefined,
1852
+ profitMargin: item.asset.profitMargin !== undefined ? item.asset.profitMargin : undefined,
1853
+ operatingMarginTTM: item.asset.operatingMarginTTM !== undefined ? item.asset.operatingMarginTTM : undefined,
1854
+ returnOnAssetsTTM: item.asset.returnOnAssetsTTM !== undefined ? item.asset.returnOnAssetsTTM : undefined,
1855
+ returnOnEquityTTM: item.asset.returnOnEquityTTM !== undefined ? item.asset.returnOnEquityTTM : undefined,
1856
+ revenueTTM: item.asset.revenueTTM !== undefined ? item.asset.revenueTTM : undefined,
1857
+ grossProfitTTM: item.asset.grossProfitTTM !== undefined ? item.asset.grossProfitTTM : undefined,
1858
+ dilutedEPSTTM: item.asset.dilutedEPSTTM !== undefined ? item.asset.dilutedEPSTTM : undefined,
1859
+ quarterlyEarningsGrowthYOY: item.asset.quarterlyEarningsGrowthYOY !== undefined ? item.asset.quarterlyEarningsGrowthYOY : undefined,
1860
+ quarterlyRevenueGrowthYOY: item.asset.quarterlyRevenueGrowthYOY !== undefined ? item.asset.quarterlyRevenueGrowthYOY : undefined,
1861
+ analystTargetPrice: item.asset.analystTargetPrice !== undefined ? item.asset.analystTargetPrice : undefined,
1862
+ analystRatingStrongBuy: item.asset.analystRatingStrongBuy !== undefined ? item.asset.analystRatingStrongBuy : undefined,
1863
+ analystRatingBuy: item.asset.analystRatingBuy !== undefined ? item.asset.analystRatingBuy : undefined,
1864
+ analystRatingHold: item.asset.analystRatingHold !== undefined ? item.asset.analystRatingHold : undefined,
1865
+ analystRatingSell: item.asset.analystRatingSell !== undefined ? item.asset.analystRatingSell : undefined,
1866
+ analystRatingStrongSell: item.asset.analystRatingStrongSell !== undefined ? item.asset.analystRatingStrongSell : undefined,
1867
+ trailingPE: item.asset.trailingPE !== undefined ? item.asset.trailingPE : undefined,
1868
+ forwardPE: item.asset.forwardPE !== undefined ? item.asset.forwardPE : undefined,
1869
+ priceToSalesRatioTTM: item.asset.priceToSalesRatioTTM !== undefined ? item.asset.priceToSalesRatioTTM : undefined,
1870
+ priceToBookRatio: item.asset.priceToBookRatio !== undefined ? item.asset.priceToBookRatio : undefined,
1871
+ evToRevenue: item.asset.evToRevenue !== undefined ? item.asset.evToRevenue : undefined,
1872
+ evToEbitda: item.asset.evToEbitda !== undefined ? item.asset.evToEbitda : undefined,
1873
+ beta: item.asset.beta !== undefined ? item.asset.beta : undefined,
1874
+ week52High: item.asset.week52High !== undefined ? item.asset.week52High : undefined,
1875
+ week52Low: item.asset.week52Low !== undefined ? item.asset.week52Low : undefined,
1876
+ day50MovingAverage: item.asset.day50MovingAverage !== undefined ? item.asset.day50MovingAverage : undefined,
1877
+ day200MovingAverage: item.asset.day200MovingAverage !== undefined ? item.asset.day200MovingAverage : undefined,
1878
+ sharesOutstanding: item.asset.sharesOutstanding !== undefined ? item.asset.sharesOutstanding : undefined,
1879
+ dividendDate: item.asset.dividendDate !== undefined ? item.asset.dividendDate : undefined,
1880
+ exDividendDate: item.asset.exDividendDate !== undefined ? item.asset.exDividendDate : undefined,
1881
+ askPrice: item.asset.askPrice !== undefined ? item.asset.askPrice : undefined,
1882
+ bidPrice: item.asset.bidPrice !== undefined ? item.asset.bidPrice : undefined,
1883
+ },
1884
+ }
1885
+ } : undefined,
1886
+ },
1887
+ }))
1888
+ } : undefined,
1889
+ },
1890
+ }));
1891
+ const filteredVariables = removeUndefinedProps(variables);
1892
+ const response = await client.mutate({
1893
+ mutation: UPDATE_MANY_NEWSARTICLE,
1894
+ variables: filteredVariables,
1895
+ // Don't cache mutations, but ensure we're using the freshest context
1896
+ fetchPolicy: 'no-cache'
1897
+ });
1898
+ if (response.errors && response.errors.length > 0)
1899
+ throw new Error(response.errors[0].message);
1900
+ if (response && response.data && response.data.updateManyNewsArticle) {
1901
+ return response.data.updateManyNewsArticle;
1902
+ }
1903
+ else {
1904
+ return null;
1905
+ }
1764
1906
  }
1765
- else {
1766
- return null;
1907
+ catch (error) {
1908
+ lastError = error;
1909
+ // Check if this is a database connection error that we should retry
1910
+ const isConnectionError = error.message?.includes('Server has closed the connection') ||
1911
+ error.message?.includes('Cannot reach database server') ||
1912
+ error.message?.includes('Connection timed out') ||
1913
+ error.message?.includes('Accelerate') || // Prisma Accelerate proxy errors
1914
+ (error.networkError && error.networkError.message?.includes('Failed to fetch'));
1915
+ if (isConnectionError && retryCount < MAX_RETRIES - 1) {
1916
+ retryCount++;
1917
+ const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
1918
+ console.warn("Database connection error, retrying...");
1919
+ await new Promise(resolve => setTimeout(resolve, delay));
1920
+ continue;
1921
+ }
1922
+ // Log the error and rethrow
1923
+ console.error("Database error occurred:", error);
1924
+ throw error;
1767
1925
  }
1768
1926
  }
1769
- catch (error) {
1770
- console.error('Error in updateManyNewsArticle:', error);
1771
- throw error;
1772
- }
1927
+ // If we exhausted retries, throw the last error
1928
+ throw lastError;
1773
1929
  },
1774
1930
  /**
1775
1931
  * Delete a single NewsArticle record.
1776
- * @param props - Properties to update.
1932
+ * Enhanced with connection resilience against Prisma connection errors.
1933
+ * @param props - Properties to identify the record to delete.
1777
1934
  * @param globalClient - Apollo Client instance.
1778
1935
  * @returns The deleted NewsArticle or null.
1779
1936
  */
1780
1937
  async delete(props, globalClient) {
1781
- const [modules, client] = await Promise.all([
1782
- getApolloModules(),
1783
- globalClient
1784
- ? Promise.resolve(globalClient)
1785
- : importedClient
1786
- ]);
1787
- const { gql, ApolloError } = modules;
1788
- const DELETE_ONE_NEWSARTICLE = gql `
1789
- mutation deleteOneNewsArticle($where: NewsArticleWhereUniqueInput!) {
1790
- deleteOneNewsArticle(where: $where) {
1791
- id
1792
- }
1793
- }`;
1794
- const variables = {
1795
- where: {
1796
- id: props.id ? props.id : undefined,
1938
+ // Maximum number of retries for database connection issues
1939
+ const MAX_RETRIES = 3;
1940
+ let retryCount = 0;
1941
+ let lastError = null;
1942
+ // Retry loop to handle potential database connection issues
1943
+ while (retryCount < MAX_RETRIES) {
1944
+ try {
1945
+ const [modules, client] = await Promise.all([
1946
+ getApolloModules(),
1947
+ globalClient
1948
+ ? Promise.resolve(globalClient)
1949
+ : importedClient
1950
+ ]);
1951
+ const { gql, ApolloError } = modules;
1952
+ const DELETE_ONE_NEWSARTICLE = gql `
1953
+ mutation deleteOneNewsArticle($where: NewsArticleWhereUniqueInput!) {
1954
+ deleteOneNewsArticle(where: $where) {
1955
+ id
1797
1956
  }
1798
- };
1799
- const filteredVariables = removeUndefinedProps(variables);
1800
- try {
1801
- const response = await client.mutate({ mutation: DELETE_ONE_NEWSARTICLE, variables: filteredVariables });
1802
- if (response.errors && response.errors.length > 0)
1803
- throw new Error(response.errors[0].message);
1804
- if (response && response.data && response.data.deleteOneNewsArticle) {
1805
- return response.data.deleteOneNewsArticle;
1957
+ }`;
1958
+ const variables = {
1959
+ where: {
1960
+ id: props.id ? props.id : undefined,
1961
+ }
1962
+ };
1963
+ const filteredVariables = removeUndefinedProps(variables);
1964
+ const response = await client.mutate({
1965
+ mutation: DELETE_ONE_NEWSARTICLE,
1966
+ variables: filteredVariables,
1967
+ // Don't cache mutations, but ensure we're using the freshest context
1968
+ fetchPolicy: 'no-cache'
1969
+ });
1970
+ if (response.errors && response.errors.length > 0)
1971
+ throw new Error(response.errors[0].message);
1972
+ if (response && response.data && response.data.deleteOneNewsArticle) {
1973
+ return response.data.deleteOneNewsArticle;
1974
+ }
1975
+ else {
1976
+ return null;
1977
+ }
1806
1978
  }
1807
- else {
1808
- return null;
1979
+ catch (error) {
1980
+ lastError = error;
1981
+ // Check if this is a database connection error that we should retry
1982
+ const isConnectionError = error.message?.includes('Server has closed the connection') ||
1983
+ error.message?.includes('Cannot reach database server') ||
1984
+ error.message?.includes('Connection timed out') ||
1985
+ error.message?.includes('Accelerate') || // Prisma Accelerate proxy errors
1986
+ (error.networkError && error.networkError.message?.includes('Failed to fetch'));
1987
+ if (isConnectionError && retryCount < MAX_RETRIES - 1) {
1988
+ retryCount++;
1989
+ const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
1990
+ console.warn("Database connection error, retrying...");
1991
+ await new Promise(resolve => setTimeout(resolve, delay));
1992
+ continue;
1993
+ }
1994
+ // Log the error and rethrow
1995
+ console.error("Database error occurred:", error);
1996
+ throw error;
1809
1997
  }
1810
1998
  }
1811
- catch (error) {
1812
- console.error('Error in deleteOneNewsArticle:', error);
1813
- throw error;
1814
- }
1999
+ // If we exhausted retries, throw the last error
2000
+ throw lastError;
1815
2001
  },
1816
2002
  /**
1817
2003
  * Retrieve a single NewsArticle record by ID.
1818
- * @param props - Properties to update.
2004
+ * Enhanced with connection resilience against Prisma connection errors.
2005
+ * @param props - Properties to identify the record.
1819
2006
  * @param globalClient - Apollo Client instance.
2007
+ * @param whereInput - Optional custom where input.
1820
2008
  * @returns The retrieved NewsArticle or null.
1821
2009
  */
1822
2010
  async get(props, globalClient, whereInput) {
1823
- const [modules, client] = await Promise.all([
1824
- getApolloModules(),
1825
- globalClient
1826
- ? Promise.resolve(globalClient)
1827
- : importedClient
1828
- ]);
1829
- const { gql, ApolloError } = modules;
1830
- const GET_NEWSARTICLE = gql `
1831
- query getNewsArticle($where: NewsArticleWhereUniqueInput!) {
1832
- getNewsArticle(where: $where) {
1833
- ${selectionSet}
1834
- }
1835
- }`;
1836
- const variables = {
1837
- where: whereInput ? whereInput : {
1838
- id: props.id !== undefined ? props.id : undefined,
1839
- url: props.url !== undefined ? props.url : undefined,
1840
- title: props.title !== undefined ? {
1841
- equals: props.title
1842
- } : undefined,
1843
- },
1844
- };
1845
- const filteredVariables = removeUndefinedProps(variables);
1846
- try {
1847
- const response = await client.query({ query: GET_NEWSARTICLE, variables: filteredVariables });
1848
- if (response.errors && response.errors.length > 0)
1849
- throw new Error(response.errors[0].message);
1850
- return response.data?.getNewsArticle ?? null;
1851
- }
1852
- catch (error) {
1853
- if (error instanceof ApolloError && error.message === 'No NewsArticle found') {
1854
- return null;
2011
+ // Maximum number of retries for database connection issues
2012
+ const MAX_RETRIES = 3;
2013
+ let retryCount = 0;
2014
+ let lastError = null;
2015
+ // Retry loop to handle potential database connection issues
2016
+ while (retryCount < MAX_RETRIES) {
2017
+ try {
2018
+ const [modules, client] = await Promise.all([
2019
+ getApolloModules(),
2020
+ globalClient
2021
+ ? Promise.resolve(globalClient)
2022
+ : importedClient
2023
+ ]);
2024
+ const { gql, ApolloError } = modules;
2025
+ const GET_NEWSARTICLE = gql `
2026
+ query getNewsArticle($where: NewsArticleWhereUniqueInput!) {
2027
+ getNewsArticle(where: $where) {
2028
+ ${selectionSet}
2029
+ }
2030
+ }`;
2031
+ const variables = {
2032
+ where: whereInput ? whereInput : {
2033
+ id: props.id !== undefined ? props.id : undefined,
2034
+ url: props.url !== undefined ? props.url : undefined,
2035
+ title: props.title !== undefined ? {
2036
+ equals: props.title
2037
+ } : undefined,
2038
+ },
2039
+ };
2040
+ const filteredVariables = removeUndefinedProps(variables);
2041
+ const response = await client.query({
2042
+ query: GET_NEWSARTICLE,
2043
+ variables: filteredVariables,
2044
+ fetchPolicy: 'network-only', // Force network request to avoid stale cache
2045
+ });
2046
+ if (response.errors && response.errors.length > 0)
2047
+ throw new Error(response.errors[0].message);
2048
+ return response.data?.getNewsArticle ?? null;
1855
2049
  }
1856
- else {
1857
- console.error('Error in getNewsArticle:', error);
2050
+ catch (error) {
2051
+ lastError = error;
2052
+ // Check if this is a "No record found" error - this is an expected condition, not a failure
2053
+ if (error.message === 'No NewsArticle found') {
2054
+ return null;
2055
+ }
2056
+ // Check if this is a database connection error that we should retry
2057
+ const isConnectionError = error.message?.includes('Server has closed the connection') ||
2058
+ error.message?.includes('Cannot reach database server') ||
2059
+ error.message?.includes('Connection timed out') ||
2060
+ error.message?.includes('Accelerate') || // Prisma Accelerate proxy errors
2061
+ (error.networkError && error.networkError.message?.includes('Failed to fetch'));
2062
+ if (isConnectionError && retryCount < MAX_RETRIES - 1) {
2063
+ retryCount++;
2064
+ const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
2065
+ console.warn("Database connection error, retrying...");
2066
+ await new Promise(resolve => setTimeout(resolve, delay));
2067
+ continue;
2068
+ }
2069
+ // Log the error and rethrow
2070
+ console.error("Database error occurred:", error);
1858
2071
  throw error;
1859
2072
  }
1860
2073
  }
2074
+ // If we exhausted retries, throw the last error
2075
+ throw lastError;
1861
2076
  },
1862
2077
  /**
1863
2078
  * Retrieve all NewsArticles records.
2079
+ * Enhanced with connection resilience against Prisma connection errors.
1864
2080
  * @param globalClient - Apollo Client instance.
1865
2081
  * @returns An array of NewsArticle records or null.
1866
2082
  */
1867
2083
  async getAll(globalClient) {
1868
- const [modules, client] = await Promise.all([
1869
- getApolloModules(),
1870
- globalClient
1871
- ? Promise.resolve(globalClient)
1872
- : importedClient
1873
- ]);
1874
- const { gql, ApolloError } = modules;
1875
- const GET_ALL_NEWSARTICLE = gql `
1876
- query getAllNewsArticle {
1877
- newsArticles {
1878
- ${selectionSet}
1879
- }
1880
- }`;
1881
- try {
1882
- const response = await client.query({ query: GET_ALL_NEWSARTICLE });
1883
- if (response.errors && response.errors.length > 0)
1884
- throw new Error(response.errors[0].message);
1885
- return response.data?.newsArticles ?? null;
1886
- }
1887
- catch (error) {
1888
- if (error instanceof ApolloError && error.message === 'No NewsArticle found') {
1889
- return null;
2084
+ // Maximum number of retries for database connection issues
2085
+ const MAX_RETRIES = 3;
2086
+ let retryCount = 0;
2087
+ let lastError = null;
2088
+ // Retry loop to handle potential database connection issues
2089
+ while (retryCount < MAX_RETRIES) {
2090
+ try {
2091
+ const [modules, client] = await Promise.all([
2092
+ getApolloModules(),
2093
+ globalClient
2094
+ ? Promise.resolve(globalClient)
2095
+ : importedClient
2096
+ ]);
2097
+ const { gql, ApolloError } = modules;
2098
+ const GET_ALL_NEWSARTICLE = gql `
2099
+ query getAllNewsArticle {
2100
+ newsArticles {
2101
+ ${selectionSet}
2102
+ }
2103
+ }`;
2104
+ const response = await client.query({
2105
+ query: GET_ALL_NEWSARTICLE,
2106
+ fetchPolicy: 'network-only', // Force network request to avoid stale cache
2107
+ });
2108
+ if (response.errors && response.errors.length > 0)
2109
+ throw new Error(response.errors[0].message);
2110
+ return response.data?.newsArticles ?? null;
1890
2111
  }
1891
- else {
1892
- console.error('Error in getNewsArticle:', error);
2112
+ catch (error) {
2113
+ lastError = error;
2114
+ // Check if this is a "No record found" error - this is an expected condition, not a failure
2115
+ if (error.message === 'No NewsArticle found') {
2116
+ return null;
2117
+ }
2118
+ // Check if this is a database connection error that we should retry
2119
+ const isConnectionError = error.message?.includes('Server has closed the connection') ||
2120
+ error.message?.includes('Cannot reach database server') ||
2121
+ error.message?.includes('Connection timed out') ||
2122
+ error.message?.includes('Accelerate') || // Prisma Accelerate proxy errors
2123
+ (error.networkError && error.networkError.message?.includes('Failed to fetch'));
2124
+ if (isConnectionError && retryCount < MAX_RETRIES - 1) {
2125
+ retryCount++;
2126
+ const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
2127
+ console.warn("Database connection error, retrying...");
2128
+ await new Promise(resolve => setTimeout(resolve, delay));
2129
+ continue;
2130
+ }
2131
+ // Log the error and rethrow
2132
+ console.error("Database error occurred:", error);
1893
2133
  throw error;
1894
2134
  }
1895
2135
  }
2136
+ // If we exhausted retries, throw the last error
2137
+ throw lastError;
1896
2138
  },
1897
2139
  /**
1898
2140
  * Find multiple NewsArticle records based on conditions.
2141
+ * Enhanced with connection resilience against Prisma connection errors.
1899
2142
  * @param props - Conditions to find records.
1900
2143
  * @param globalClient - Apollo Client instance.
2144
+ * @param whereInput - Optional custom where input.
1901
2145
  * @returns An array of found NewsArticle records or null.
1902
2146
  */
1903
2147
  async findMany(props, globalClient, whereInput) {
1904
- const [modules, client] = await Promise.all([
1905
- getApolloModules(),
1906
- globalClient
1907
- ? Promise.resolve(globalClient)
1908
- : importedClient
1909
- ]);
1910
- const { gql, ApolloError } = modules;
1911
- const FIND_MANY_NEWSARTICLE = gql `
1912
- query findManyNewsArticle($where: NewsArticleWhereInput!) {
1913
- newsArticles(where: $where) {
1914
- ${selectionSet}
1915
- }
1916
- }`;
1917
- const variables = {
1918
- where: whereInput ? whereInput : {
1919
- id: props.id !== undefined ? {
1920
- equals: props.id
1921
- } : undefined,
1922
- title: props.title !== undefined ? {
1923
- equals: props.title
1924
- } : undefined,
1925
- url: props.url !== undefined ? {
1926
- equals: props.url
1927
- } : undefined,
1928
- },
1929
- };
1930
- const filteredVariables = removeUndefinedProps(variables);
1931
- try {
1932
- const response = await client.query({ query: FIND_MANY_NEWSARTICLE, variables: filteredVariables });
1933
- if (response.errors && response.errors.length > 0)
1934
- throw new Error(response.errors[0].message);
1935
- if (response && response.data && response.data.newsarticles) {
1936
- return response.data.newsArticles;
1937
- }
1938
- else {
1939
- return [];
2148
+ // Maximum number of retries for database connection issues
2149
+ const MAX_RETRIES = 3;
2150
+ let retryCount = 0;
2151
+ let lastError = null;
2152
+ // Retry loop to handle potential database connection issues
2153
+ while (retryCount < MAX_RETRIES) {
2154
+ try {
2155
+ const [modules, client] = await Promise.all([
2156
+ getApolloModules(),
2157
+ globalClient
2158
+ ? Promise.resolve(globalClient)
2159
+ : importedClient
2160
+ ]);
2161
+ const { gql, ApolloError } = modules;
2162
+ const FIND_MANY_NEWSARTICLE = gql `
2163
+ query findManyNewsArticle($where: NewsArticleWhereInput!) {
2164
+ newsArticles(where: $where) {
2165
+ ${selectionSet}
1940
2166
  }
1941
- }
1942
- catch (error) {
1943
- if (error instanceof ApolloError && error.message === 'No NewsArticle found') {
1944
- return null;
2167
+ }`;
2168
+ const variables = {
2169
+ where: whereInput ? whereInput : {
2170
+ id: props.id !== undefined ? {
2171
+ equals: props.id
2172
+ } : undefined,
2173
+ title: props.title !== undefined ? {
2174
+ equals: props.title
2175
+ } : undefined,
2176
+ url: props.url !== undefined ? {
2177
+ equals: props.url
2178
+ } : undefined,
2179
+ },
2180
+ };
2181
+ const filteredVariables = removeUndefinedProps(variables);
2182
+ const response = await client.query({
2183
+ query: FIND_MANY_NEWSARTICLE,
2184
+ variables: filteredVariables,
2185
+ fetchPolicy: 'network-only', // Force network request to avoid stale cache
2186
+ });
2187
+ if (response.errors && response.errors.length > 0)
2188
+ throw new Error(response.errors[0].message);
2189
+ if (response && response.data && response.data.newsarticles) {
2190
+ return response.data.newsArticles;
2191
+ }
2192
+ else {
2193
+ return [];
2194
+ }
1945
2195
  }
1946
- else {
1947
- console.error('Error in getNewsArticle:', error);
2196
+ catch (error) {
2197
+ lastError = error;
2198
+ // Check if this is a "No record found" error - this is an expected condition, not a failure
2199
+ if (error.message === 'No NewsArticle found') {
2200
+ return null;
2201
+ }
2202
+ // Check if this is a database connection error that we should retry
2203
+ const isConnectionError = error.message?.includes('Server has closed the connection') ||
2204
+ error.message?.includes('Cannot reach database server') ||
2205
+ error.message?.includes('Connection timed out') ||
2206
+ error.message?.includes('Accelerate') || // Prisma Accelerate proxy errors
2207
+ (error.networkError && error.networkError.message?.includes('Failed to fetch'));
2208
+ if (isConnectionError && retryCount < MAX_RETRIES - 1) {
2209
+ retryCount++;
2210
+ const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
2211
+ console.warn("Database connection error, retrying...");
2212
+ await new Promise(resolve => setTimeout(resolve, delay));
2213
+ continue;
2214
+ }
2215
+ // Log the error and rethrow
2216
+ console.error("Database error occurred:", error);
1948
2217
  throw error;
1949
2218
  }
1950
2219
  }
2220
+ // If we exhausted retries, throw the last error
2221
+ throw lastError;
1951
2222
  }
1952
2223
  };
1953
2224
  //# sourceMappingURL=NewsArticle.js.map