adaptic-backend 1.0.340 → 1.0.342

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 (122) hide show
  1. package/Account.cjs +2670 -2264
  2. package/Account.d.ts +19 -2
  3. package/Action.cjs +1195 -839
  4. package/Action.d.ts +19 -2
  5. package/Alert.cjs +2651 -2347
  6. package/Alert.d.ts +19 -2
  7. package/Allocation.cjs +2631 -2304
  8. package/Allocation.d.ts +19 -2
  9. package/AlpacaAccount.cjs +2654 -2104
  10. package/AlpacaAccount.d.ts +19 -2
  11. package/Asset.cjs +2611 -1544
  12. package/Asset.d.ts +19 -2
  13. package/Authenticator.cjs +2603 -2290
  14. package/Authenticator.d.ts +19 -2
  15. package/Customer.cjs +2506 -2220
  16. package/Customer.d.ts +19 -2
  17. package/EconomicEvent.cjs +708 -367
  18. package/EconomicEvent.d.ts +19 -2
  19. package/MarketSentiment.cjs +691 -340
  20. package/MarketSentiment.d.ts +19 -2
  21. package/NewsArticle.cjs +2114 -1655
  22. package/NewsArticle.d.ts +19 -2
  23. package/NewsArticleAssetSentiment.cjs +1873 -1564
  24. package/NewsArticleAssetSentiment.d.ts +19 -2
  25. package/ScheduledOptionOrder.cjs +607 -316
  26. package/ScheduledOptionOrder.d.ts +19 -2
  27. package/Session.cjs +2592 -2294
  28. package/Session.d.ts +19 -2
  29. package/Trade.cjs +1261 -795
  30. package/Trade.d.ts +19 -2
  31. package/User.cjs +2432 -2013
  32. package/User.d.ts +19 -2
  33. package/VerificationToken.cjs +637 -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 +2661 -2262
  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 +1186 -837
  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 +2642 -2345
  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 +2622 -2302
  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 +2645 -2102
  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 +2602 -1542
  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 +2594 -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 +2497 -2218
  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 +699 -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 +682 -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 +2105 -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 +1864 -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 +598 -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 +2583 -2292
  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 +1252 -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 +2423 -2011
  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 +628 -326
  103. package/esm/generated/typegraphql-prisma/enhance.js.map +1 -1
  104. package/esm/generated/typegraphql-prisma/enhance.mjs +1 -1
  105. package/esm/generated/typegraphql-prisma/resolvers/inputs/AccountWhereUniqueInput.d.ts +1 -1
  106. package/esm/generated/typegraphql-prisma/resolvers/inputs/AccountWhereUniqueInput.d.ts.map +1 -1
  107. package/esm/generated/typegraphql-prisma/resolvers/inputs/AccountWhereUniqueInput.js.map +1 -1
  108. package/esm/generated/typegraphql-prisma/resolvers/inputs/AccountWhereUniqueInput.mjs +7 -7
  109. package/esm/prismaClient.d.ts +4 -5
  110. package/esm/prismaClient.d.ts.map +1 -1
  111. package/esm/prismaClient.js.map +1 -1
  112. package/esm/prismaClient.mjs +13 -11
  113. package/generated/typegraphql-prisma/enhance.cjs +1 -1
  114. package/generated/typegraphql-prisma/enhance.js.map +1 -1
  115. package/generated/typegraphql-prisma/resolvers/inputs/AccountWhereUniqueInput.cjs +6 -6
  116. package/generated/typegraphql-prisma/resolvers/inputs/AccountWhereUniqueInput.d.ts +1 -1
  117. package/generated/typegraphql-prisma/resolvers/inputs/AccountWhereUniqueInput.d.ts.map +1 -1
  118. package/generated/typegraphql-prisma/resolvers/inputs/AccountWhereUniqueInput.js.map +1 -1
  119. package/package.json +1 -1
  120. package/prismaClient.cjs +13 -11
  121. package/prismaClient.d.ts +4 -5
  122. package/server.cjs +37 -5
@@ -99,70 +99,617 @@ 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 ? props.title : undefined,
405
+ content: props.content !== undefined ? {
406
+ equals: props.content
407
+ } : undefined,
408
+ source: props.source !== undefined ? {
409
+ equals: props.source
410
+ } : undefined,
411
+ sourceDomain: props.sourceDomain !== undefined ? {
412
+ equals: props.sourceDomain
413
+ } : undefined,
414
+ sentiment: props.sentiment !== undefined ? {
415
+ equals: props.sentiment
416
+ } : undefined,
417
+ authors: props.authors !== undefined ? {
418
+ equals: props.authors
419
+ } : undefined,
420
+ summary: props.summary !== undefined ? {
421
+ equals: props.summary
422
+ } : undefined,
423
+ bannerImage: props.bannerImage !== undefined ? {
424
+ equals: props.bannerImage
425
+ } : undefined,
426
+ timePublished: props.timePublished !== undefined ? {
427
+ equals: props.timePublished
428
+ } : undefined,
429
+ category: props.category !== undefined ? {
430
+ equals: props.category
431
+ } : undefined,
432
+ topics: props.topics !== undefined ? {
433
+ equals: props.topics
434
+ } : undefined,
435
+ logo: props.logo !== undefined ? {
436
+ equals: props.logo
437
+ } : undefined,
438
+ createdAt: props.createdAt !== undefined ? {
439
+ equals: props.createdAt
440
+ } : undefined,
441
+ updatedAt: props.updatedAt !== undefined ? {
442
+ equals: props.updatedAt
443
+ } : undefined,
444
+ },
445
+ data: {
446
+ id: props.id !== undefined ? {
447
+ set: props.id
448
+ } : undefined,
449
+ title: props.title !== undefined ? {
450
+ set: props.title
451
+ } : undefined,
452
+ content: props.content !== undefined ? {
453
+ set: props.content
454
+ } : undefined,
455
+ source: props.source !== undefined ? {
456
+ set: props.source
457
+ } : undefined,
458
+ sourceDomain: props.sourceDomain !== undefined ? {
459
+ set: props.sourceDomain
460
+ } : undefined,
461
+ url: props.url !== undefined ? {
462
+ set: props.url
463
+ } : undefined,
464
+ sentiment: props.sentiment !== undefined ? {
465
+ set: props.sentiment
466
+ } : undefined,
467
+ authors: props.authors !== undefined ? {
468
+ set: props.authors
469
+ } : undefined,
470
+ summary: props.summary !== undefined ? {
471
+ set: props.summary
472
+ } : undefined,
473
+ bannerImage: props.bannerImage !== undefined ? {
474
+ set: props.bannerImage
475
+ } : undefined,
476
+ timePublished: props.timePublished !== undefined ? {
477
+ set: props.timePublished
478
+ } : undefined,
479
+ category: props.category !== undefined ? {
480
+ set: props.category
481
+ } : undefined,
482
+ topics: props.topics !== undefined ? {
483
+ set: props.topics
484
+ } : undefined,
485
+ logo: props.logo !== undefined ? {
486
+ set: props.logo
487
+ } : undefined,
488
+ createdAt: props.createdAt !== undefined ? {
489
+ set: props.createdAt
490
+ } : undefined,
491
+ updatedAt: props.updatedAt !== undefined ? {
492
+ set: props.updatedAt
493
+ } : undefined,
494
+ assets: props.assets ?
495
+ 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) ? {
496
+ connect: props.assets.map((item) => ({
497
+ id: item.id
498
+ }))
499
+ } : { upsert: props.assets.map((item) => ({
500
+ where: {
501
+ id: item.id !== undefined ? item.id : undefined,
502
+ url: item.url !== undefined ? item.url : undefined,
503
+ assetId: item.assetId !== undefined ? {
504
+ equals: item.assetId
505
+ } : undefined,
506
+ newsArticleId: item.newsArticleId !== undefined ? {
507
+ equals: item.newsArticleId
508
+ } : undefined,
509
+ },
510
+ update: {
511
+ id: item.id !== undefined ? {
512
+ set: item.id
513
+ } : undefined,
514
+ url: item.url !== undefined ? {
515
+ set: item.url
516
+ } : undefined,
517
+ relevancyScore: item.relevancyScore !== undefined ? {
518
+ set: item.relevancyScore
519
+ } : undefined,
520
+ sentimentScore: item.sentimentScore !== undefined ? {
521
+ set: item.sentimentScore
522
+ } : undefined,
523
+ sentimentLabel: item.sentimentLabel !== undefined ? {
524
+ set: item.sentimentLabel
525
+ } : undefined,
526
+ asset: item.asset ?
527
+ typeof item.asset === 'object' && Object.keys(item.asset).length === 1 && (Object.keys(item.asset)[0] === 'id' || Object.keys(item.asset)[0] === 'symbol')
528
+ ? {
529
+ connect: {
530
+ id: item.asset.id
531
+ }
532
+ } : { upsert: {
162
533
  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,
534
+ id: item.asset.id !== undefined ? {
535
+ equals: item.asset.id
536
+ } : undefined,
537
+ symbol: item.asset.symbol !== undefined ? {
538
+ equals: item.asset.symbol
539
+ } : undefined,
540
+ name: item.asset.name !== undefined ? {
541
+ equals: item.asset.name
542
+ } : undefined,
543
+ },
544
+ update: {
545
+ id: item.asset.id !== undefined ? {
546
+ set: item.asset.id
547
+ } : undefined,
548
+ symbol: item.asset.symbol !== undefined ? {
549
+ set: item.asset.symbol
550
+ } : undefined,
551
+ name: item.asset.name !== undefined ? {
552
+ set: item.asset.name
553
+ } : undefined,
554
+ type: item.asset.type !== undefined ? {
555
+ set: item.asset.type
556
+ } : undefined,
557
+ logoUrl: item.asset.logoUrl !== undefined ? {
558
+ set: item.asset.logoUrl
559
+ } : undefined,
560
+ description: item.asset.description !== undefined ? {
561
+ set: item.asset.description
562
+ } : undefined,
563
+ cik: item.asset.cik !== undefined ? {
564
+ set: item.asset.cik
565
+ } : undefined,
566
+ exchange: item.asset.exchange !== undefined ? {
567
+ set: item.asset.exchange
568
+ } : undefined,
569
+ currency: item.asset.currency !== undefined ? {
570
+ set: item.asset.currency
571
+ } : undefined,
572
+ country: item.asset.country !== undefined ? {
573
+ set: item.asset.country
574
+ } : undefined,
575
+ sector: item.asset.sector !== undefined ? {
576
+ set: item.asset.sector
577
+ } : undefined,
578
+ industry: item.asset.industry !== undefined ? {
579
+ set: item.asset.industry
580
+ } : undefined,
581
+ address: item.asset.address !== undefined ? {
582
+ set: item.asset.address
583
+ } : undefined,
584
+ officialSite: item.asset.officialSite !== undefined ? {
585
+ set: item.asset.officialSite
586
+ } : undefined,
587
+ fiscalYearEnd: item.asset.fiscalYearEnd !== undefined ? {
588
+ set: item.asset.fiscalYearEnd
589
+ } : undefined,
590
+ latestQuarter: item.asset.latestQuarter !== undefined ? {
591
+ set: item.asset.latestQuarter
592
+ } : undefined,
593
+ marketCapitalization: item.asset.marketCapitalization !== undefined ? {
594
+ set: item.asset.marketCapitalization
595
+ } : undefined,
596
+ ebitda: item.asset.ebitda !== undefined ? {
597
+ set: item.asset.ebitda
598
+ } : undefined,
599
+ peRatio: item.asset.peRatio !== undefined ? {
600
+ set: item.asset.peRatio
601
+ } : undefined,
602
+ pegRatio: item.asset.pegRatio !== undefined ? {
603
+ set: item.asset.pegRatio
604
+ } : undefined,
605
+ bookValue: item.asset.bookValue !== undefined ? {
606
+ set: item.asset.bookValue
607
+ } : undefined,
608
+ dividendPerShare: item.asset.dividendPerShare !== undefined ? {
609
+ set: item.asset.dividendPerShare
610
+ } : undefined,
611
+ dividendYield: item.asset.dividendYield !== undefined ? {
612
+ set: item.asset.dividendYield
613
+ } : undefined,
614
+ eps: item.asset.eps !== undefined ? {
615
+ set: item.asset.eps
616
+ } : undefined,
617
+ revenuePerShareTTM: item.asset.revenuePerShareTTM !== undefined ? {
618
+ set: item.asset.revenuePerShareTTM
619
+ } : undefined,
620
+ profitMargin: item.asset.profitMargin !== undefined ? {
621
+ set: item.asset.profitMargin
622
+ } : undefined,
623
+ operatingMarginTTM: item.asset.operatingMarginTTM !== undefined ? {
624
+ set: item.asset.operatingMarginTTM
625
+ } : undefined,
626
+ returnOnAssetsTTM: item.asset.returnOnAssetsTTM !== undefined ? {
627
+ set: item.asset.returnOnAssetsTTM
628
+ } : undefined,
629
+ returnOnEquityTTM: item.asset.returnOnEquityTTM !== undefined ? {
630
+ set: item.asset.returnOnEquityTTM
631
+ } : undefined,
632
+ revenueTTM: item.asset.revenueTTM !== undefined ? {
633
+ set: item.asset.revenueTTM
634
+ } : undefined,
635
+ grossProfitTTM: item.asset.grossProfitTTM !== undefined ? {
636
+ set: item.asset.grossProfitTTM
637
+ } : undefined,
638
+ dilutedEPSTTM: item.asset.dilutedEPSTTM !== undefined ? {
639
+ set: item.asset.dilutedEPSTTM
640
+ } : undefined,
641
+ quarterlyEarningsGrowthYOY: item.asset.quarterlyEarningsGrowthYOY !== undefined ? {
642
+ set: item.asset.quarterlyEarningsGrowthYOY
643
+ } : undefined,
644
+ quarterlyRevenueGrowthYOY: item.asset.quarterlyRevenueGrowthYOY !== undefined ? {
645
+ set: item.asset.quarterlyRevenueGrowthYOY
646
+ } : undefined,
647
+ analystTargetPrice: item.asset.analystTargetPrice !== undefined ? {
648
+ set: item.asset.analystTargetPrice
649
+ } : undefined,
650
+ analystRatingStrongBuy: item.asset.analystRatingStrongBuy !== undefined ? {
651
+ set: item.asset.analystRatingStrongBuy
652
+ } : undefined,
653
+ analystRatingBuy: item.asset.analystRatingBuy !== undefined ? {
654
+ set: item.asset.analystRatingBuy
655
+ } : undefined,
656
+ analystRatingHold: item.asset.analystRatingHold !== undefined ? {
657
+ set: item.asset.analystRatingHold
658
+ } : undefined,
659
+ analystRatingSell: item.asset.analystRatingSell !== undefined ? {
660
+ set: item.asset.analystRatingSell
661
+ } : undefined,
662
+ analystRatingStrongSell: item.asset.analystRatingStrongSell !== undefined ? {
663
+ set: item.asset.analystRatingStrongSell
664
+ } : undefined,
665
+ trailingPE: item.asset.trailingPE !== undefined ? {
666
+ set: item.asset.trailingPE
667
+ } : undefined,
668
+ forwardPE: item.asset.forwardPE !== undefined ? {
669
+ set: item.asset.forwardPE
670
+ } : undefined,
671
+ priceToSalesRatioTTM: item.asset.priceToSalesRatioTTM !== undefined ? {
672
+ set: item.asset.priceToSalesRatioTTM
673
+ } : undefined,
674
+ priceToBookRatio: item.asset.priceToBookRatio !== undefined ? {
675
+ set: item.asset.priceToBookRatio
676
+ } : undefined,
677
+ evToRevenue: item.asset.evToRevenue !== undefined ? {
678
+ set: item.asset.evToRevenue
679
+ } : undefined,
680
+ evToEbitda: item.asset.evToEbitda !== undefined ? {
681
+ set: item.asset.evToEbitda
682
+ } : undefined,
683
+ beta: item.asset.beta !== undefined ? {
684
+ set: item.asset.beta
685
+ } : undefined,
686
+ week52High: item.asset.week52High !== undefined ? {
687
+ set: item.asset.week52High
688
+ } : undefined,
689
+ week52Low: item.asset.week52Low !== undefined ? {
690
+ set: item.asset.week52Low
691
+ } : undefined,
692
+ day50MovingAverage: item.asset.day50MovingAverage !== undefined ? {
693
+ set: item.asset.day50MovingAverage
694
+ } : undefined,
695
+ day200MovingAverage: item.asset.day200MovingAverage !== undefined ? {
696
+ set: item.asset.day200MovingAverage
697
+ } : undefined,
698
+ sharesOutstanding: item.asset.sharesOutstanding !== undefined ? {
699
+ set: item.asset.sharesOutstanding
700
+ } : undefined,
701
+ dividendDate: item.asset.dividendDate !== undefined ? {
702
+ set: item.asset.dividendDate
703
+ } : undefined,
704
+ exDividendDate: item.asset.exDividendDate !== undefined ? {
705
+ set: item.asset.exDividendDate
706
+ } : undefined,
707
+ askPrice: item.asset.askPrice !== undefined ? {
708
+ set: item.asset.askPrice
709
+ } : undefined,
710
+ bidPrice: item.asset.bidPrice !== undefined ? {
711
+ set: item.asset.bidPrice
712
+ } : undefined,
166
713
  },
167
714
  create: {
168
715
  symbol: item.asset.symbol !== undefined ? item.asset.symbol : undefined,
@@ -223,617 +770,571 @@ export const NewsArticle = {
223
770
  },
224
771
  }
225
772
  } : 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;
773
+ },
774
+ create: {
775
+ url: item.url !== undefined ? item.url : undefined,
776
+ relevancyScore: item.relevancyScore !== undefined ? item.relevancyScore : undefined,
777
+ sentimentScore: item.sentimentScore !== undefined ? item.sentimentScore : undefined,
778
+ sentimentLabel: item.sentimentLabel !== undefined ? item.sentimentLabel : undefined,
779
+ asset: item.asset ?
780
+ typeof item.asset === 'object' && Object.keys(item.asset).length === 1 && Object.keys(item.asset)[0] === 'id'
781
+ ? { connect: {
782
+ id: item.asset.id
783
+ }
784
+ }
785
+ : { connectOrCreate: {
786
+ where: {
787
+ id: item.asset.id !== undefined ? item.asset.id : undefined,
788
+ symbol: item.asset.symbol !== undefined ? item.asset.symbol : undefined,
789
+ name: item.asset.name !== undefined ? item.asset.name : undefined,
790
+ },
791
+ create: {
792
+ symbol: item.asset.symbol !== undefined ? item.asset.symbol : undefined,
793
+ name: item.asset.name !== undefined ? item.asset.name : undefined,
794
+ type: item.asset.type !== undefined ? item.asset.type : undefined,
795
+ logoUrl: item.asset.logoUrl !== undefined ? item.asset.logoUrl : undefined,
796
+ description: item.asset.description !== undefined ? item.asset.description : undefined,
797
+ cik: item.asset.cik !== undefined ? item.asset.cik : undefined,
798
+ exchange: item.asset.exchange !== undefined ? item.asset.exchange : undefined,
799
+ currency: item.asset.currency !== undefined ? item.asset.currency : undefined,
800
+ country: item.asset.country !== undefined ? item.asset.country : undefined,
801
+ sector: item.asset.sector !== undefined ? item.asset.sector : undefined,
802
+ industry: item.asset.industry !== undefined ? item.asset.industry : undefined,
803
+ address: item.asset.address !== undefined ? item.asset.address : undefined,
804
+ officialSite: item.asset.officialSite !== undefined ? item.asset.officialSite : undefined,
805
+ fiscalYearEnd: item.asset.fiscalYearEnd !== undefined ? item.asset.fiscalYearEnd : undefined,
806
+ latestQuarter: item.asset.latestQuarter !== undefined ? item.asset.latestQuarter : undefined,
807
+ marketCapitalization: item.asset.marketCapitalization !== undefined ? item.asset.marketCapitalization : undefined,
808
+ ebitda: item.asset.ebitda !== undefined ? item.asset.ebitda : undefined,
809
+ peRatio: item.asset.peRatio !== undefined ? item.asset.peRatio : undefined,
810
+ pegRatio: item.asset.pegRatio !== undefined ? item.asset.pegRatio : undefined,
811
+ bookValue: item.asset.bookValue !== undefined ? item.asset.bookValue : undefined,
812
+ dividendPerShare: item.asset.dividendPerShare !== undefined ? item.asset.dividendPerShare : undefined,
813
+ dividendYield: item.asset.dividendYield !== undefined ? item.asset.dividendYield : undefined,
814
+ eps: item.asset.eps !== undefined ? item.asset.eps : undefined,
815
+ revenuePerShareTTM: item.asset.revenuePerShareTTM !== undefined ? item.asset.revenuePerShareTTM : undefined,
816
+ profitMargin: item.asset.profitMargin !== undefined ? item.asset.profitMargin : undefined,
817
+ operatingMarginTTM: item.asset.operatingMarginTTM !== undefined ? item.asset.operatingMarginTTM : undefined,
818
+ returnOnAssetsTTM: item.asset.returnOnAssetsTTM !== undefined ? item.asset.returnOnAssetsTTM : undefined,
819
+ returnOnEquityTTM: item.asset.returnOnEquityTTM !== undefined ? item.asset.returnOnEquityTTM : undefined,
820
+ revenueTTM: item.asset.revenueTTM !== undefined ? item.asset.revenueTTM : undefined,
821
+ grossProfitTTM: item.asset.grossProfitTTM !== undefined ? item.asset.grossProfitTTM : undefined,
822
+ dilutedEPSTTM: item.asset.dilutedEPSTTM !== undefined ? item.asset.dilutedEPSTTM : undefined,
823
+ quarterlyEarningsGrowthYOY: item.asset.quarterlyEarningsGrowthYOY !== undefined ? item.asset.quarterlyEarningsGrowthYOY : undefined,
824
+ quarterlyRevenueGrowthYOY: item.asset.quarterlyRevenueGrowthYOY !== undefined ? item.asset.quarterlyRevenueGrowthYOY : undefined,
825
+ analystTargetPrice: item.asset.analystTargetPrice !== undefined ? item.asset.analystTargetPrice : undefined,
826
+ analystRatingStrongBuy: item.asset.analystRatingStrongBuy !== undefined ? item.asset.analystRatingStrongBuy : undefined,
827
+ analystRatingBuy: item.asset.analystRatingBuy !== undefined ? item.asset.analystRatingBuy : undefined,
828
+ analystRatingHold: item.asset.analystRatingHold !== undefined ? item.asset.analystRatingHold : undefined,
829
+ analystRatingSell: item.asset.analystRatingSell !== undefined ? item.asset.analystRatingSell : undefined,
830
+ analystRatingStrongSell: item.asset.analystRatingStrongSell !== undefined ? item.asset.analystRatingStrongSell : undefined,
831
+ trailingPE: item.asset.trailingPE !== undefined ? item.asset.trailingPE : undefined,
832
+ forwardPE: item.asset.forwardPE !== undefined ? item.asset.forwardPE : undefined,
833
+ priceToSalesRatioTTM: item.asset.priceToSalesRatioTTM !== undefined ? item.asset.priceToSalesRatioTTM : undefined,
834
+ priceToBookRatio: item.asset.priceToBookRatio !== undefined ? item.asset.priceToBookRatio : undefined,
835
+ evToRevenue: item.asset.evToRevenue !== undefined ? item.asset.evToRevenue : undefined,
836
+ evToEbitda: item.asset.evToEbitda !== undefined ? item.asset.evToEbitda : undefined,
837
+ beta: item.asset.beta !== undefined ? item.asset.beta : undefined,
838
+ week52High: item.asset.week52High !== undefined ? item.asset.week52High : undefined,
839
+ week52Low: item.asset.week52Low !== undefined ? item.asset.week52Low : undefined,
840
+ day50MovingAverage: item.asset.day50MovingAverage !== undefined ? item.asset.day50MovingAverage : undefined,
841
+ day200MovingAverage: item.asset.day200MovingAverage !== undefined ? item.asset.day200MovingAverage : undefined,
842
+ sharesOutstanding: item.asset.sharesOutstanding !== undefined ? item.asset.sharesOutstanding : undefined,
843
+ dividendDate: item.asset.dividendDate !== undefined ? item.asset.dividendDate : undefined,
844
+ exDividendDate: item.asset.exDividendDate !== undefined ? item.asset.exDividendDate : undefined,
845
+ askPrice: item.asset.askPrice !== undefined ? item.asset.askPrice : undefined,
846
+ bidPrice: item.asset.bidPrice !== undefined ? item.asset.bidPrice : undefined,
847
+ },
848
+ }
849
+ } : undefined,
850
+ },
851
+ }))
852
+ } : undefined,
853
+ },
854
+ };
855
+ const filteredVariables = removeUndefinedProps(variables);
856
+ const response = await client.mutate({
857
+ mutation: UPDATE_ONE_NEWSARTICLE,
858
+ variables: filteredVariables,
859
+ // Don't cache mutations, but ensure we're using the freshest context
860
+ fetchPolicy: 'no-cache'
861
+ });
862
+ if (response.errors && response.errors.length > 0)
863
+ throw new Error(response.errors[0].message);
864
+ if (response && response.data && response.data.updateOneNewsArticle) {
865
+ return response.data.updateOneNewsArticle;
866
+ }
867
+ else {
868
+ return null;
869
+ }
751
870
  }
752
- else {
753
- return null;
871
+ catch (error) {
872
+ lastError = error;
873
+ // Check if this is a database connection error that we should retry
874
+ const isConnectionError = error.message?.includes('Server has closed the connection') ||
875
+ error.message?.includes('Cannot reach database server') ||
876
+ error.message?.includes('Connection timed out') ||
877
+ error.message?.includes('Accelerate') || // Prisma Accelerate proxy errors
878
+ (error.networkError && error.networkError.message?.includes('Failed to fetch'));
879
+ if (isConnectionError && retryCount < MAX_RETRIES - 1) {
880
+ retryCount++;
881
+ const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
882
+ console.warn("Database connection error, retrying...");
883
+ await new Promise(resolve => setTimeout(resolve, delay));
884
+ continue;
885
+ }
886
+ // Log the error and rethrow
887
+ console.error("Database error occurred:", error);
888
+ throw error;
754
889
  }
755
890
  }
756
- catch (error) {
757
- console.error('Error in updateOneNewsArticle:', error);
758
- throw error;
759
- }
891
+ // If we exhausted retries, throw the last error
892
+ throw lastError;
760
893
  },
761
894
  /**
762
895
  * Upsert a single NewsArticle record.
896
+ * Enhanced with connection resilience against Prisma connection errors.
763
897
  * @param props - Properties to update.
764
898
  * @param globalClient - Apollo Client instance.
765
899
  * @returns The updated NewsArticle or null.
766
900
  */
767
901
  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: {
902
+ // Maximum number of retries for database connection issues
903
+ const MAX_RETRIES = 3;
904
+ let retryCount = 0;
905
+ let lastError = null;
906
+ // Retry loop to handle potential database connection issues
907
+ while (retryCount < MAX_RETRIES) {
908
+ try {
909
+ const [modules, client] = await Promise.all([
910
+ getApolloModules(),
911
+ globalClient
912
+ ? Promise.resolve(globalClient)
913
+ : importedClient
914
+ ]);
915
+ const { gql, ApolloError } = modules;
916
+ const UPSERT_ONE_NEWSARTICLE = gql `
917
+ mutation upsertOneNewsArticle($where: NewsArticleWhereUniqueInput!, $create: NewsArticleCreateInput!, $update: NewsArticleUpdateInput!) {
918
+ upsertOneNewsArticle(where: $where, create: $create, update: $update) {
919
+ ${selectionSet}
920
+ }
921
+ }`;
922
+ const variables = {
923
+ where: {
924
+ id: props.id !== undefined ? props.id : undefined,
925
+ url: props.url !== undefined ? props.url : undefined,
926
+ title: props.title !== undefined ? props.title : undefined,
927
+ content: props.content !== undefined ? {
928
+ equals: props.content
929
+ } : undefined,
930
+ source: props.source !== undefined ? {
931
+ equals: props.source
932
+ } : undefined,
933
+ sourceDomain: props.sourceDomain !== undefined ? {
934
+ equals: props.sourceDomain
935
+ } : undefined,
936
+ sentiment: props.sentiment !== undefined ? {
937
+ equals: props.sentiment
938
+ } : undefined,
939
+ authors: props.authors !== undefined ? {
940
+ equals: props.authors
941
+ } : undefined,
942
+ summary: props.summary !== undefined ? {
943
+ equals: props.summary
944
+ } : undefined,
945
+ bannerImage: props.bannerImage !== undefined ? {
946
+ equals: props.bannerImage
947
+ } : undefined,
948
+ timePublished: props.timePublished !== undefined ? {
949
+ equals: props.timePublished
950
+ } : undefined,
951
+ category: props.category !== undefined ? {
952
+ equals: props.category
953
+ } : undefined,
954
+ topics: props.topics !== undefined ? {
955
+ equals: props.topics
956
+ } : undefined,
957
+ logo: props.logo !== undefined ? {
958
+ equals: props.logo
959
+ } : undefined,
960
+ createdAt: props.createdAt !== undefined ? {
961
+ equals: props.createdAt
962
+ } : undefined,
963
+ updatedAt: props.updatedAt !== undefined ? {
964
+ equals: props.updatedAt
965
+ } : undefined,
966
+ },
967
+ create: {
968
+ title: props.title !== undefined ? props.title : undefined,
969
+ content: props.content !== undefined ? props.content : undefined,
970
+ source: props.source !== undefined ? props.source : undefined,
971
+ sourceDomain: props.sourceDomain !== undefined ? props.sourceDomain : undefined,
972
+ url: props.url !== undefined ? props.url : undefined,
973
+ sentiment: props.sentiment !== undefined ? props.sentiment : undefined,
974
+ authors: props.authors !== undefined ? {
975
+ set: props.authors
976
+ } : undefined,
977
+ summary: props.summary !== undefined ? props.summary : undefined,
978
+ bannerImage: props.bannerImage !== undefined ? props.bannerImage : undefined,
979
+ timePublished: props.timePublished !== undefined ? props.timePublished : undefined,
980
+ category: props.category !== undefined ? props.category : undefined,
981
+ topics: props.topics !== undefined ? {
982
+ set: props.topics
983
+ } : undefined,
984
+ logo: props.logo !== undefined ? props.logo : undefined,
985
+ assets: props.assets ?
986
+ Array.isArray(props.assets) && props.assets.length > 0 && props.assets.every((item) => typeof item === 'object' && 'id' in item && Object.keys(item).length === 1) ? {
987
+ connect: props.assets.map((item) => ({
988
+ id: item.id
989
+ }))
990
+ }
991
+ : { connectOrCreate: props.assets.map((item) => ({
992
+ where: {
993
+ id: item.id !== undefined ? item.id : undefined,
994
+ url: item.url !== undefined ? item.url : undefined,
995
+ newsArticleId: item.newsArticleId !== undefined ? {
996
+ equals: item.newsArticleId
997
+ } : undefined,
998
+ },
999
+ create: {
1000
+ url: item.url !== undefined ? item.url : undefined,
1001
+ relevancyScore: item.relevancyScore !== undefined ? item.relevancyScore : undefined,
1002
+ sentimentScore: item.sentimentScore !== undefined ? item.sentimentScore : undefined,
1003
+ sentimentLabel: item.sentimentLabel !== undefined ? item.sentimentLabel : undefined,
1004
+ asset: item.asset ?
1005
+ typeof item.asset === 'object' && Object.keys(item.asset).length === 1 && Object.keys(item.asset)[0] === 'id'
1006
+ ? { connect: {
1007
+ id: item.asset.id
1008
+ }
1009
+ }
1010
+ : { connectOrCreate: {
1011
+ where: {
1012
+ id: item.asset.id !== undefined ? item.asset.id : undefined,
1013
+ symbol: item.asset.symbol !== undefined ? item.asset.symbol : undefined,
1014
+ name: item.asset.name !== undefined ? item.asset.name : undefined,
1015
+ },
1016
+ create: {
1017
+ symbol: item.asset.symbol !== undefined ? item.asset.symbol : undefined,
1018
+ name: item.asset.name !== undefined ? item.asset.name : undefined,
1019
+ type: item.asset.type !== undefined ? item.asset.type : undefined,
1020
+ logoUrl: item.asset.logoUrl !== undefined ? item.asset.logoUrl : undefined,
1021
+ description: item.asset.description !== undefined ? item.asset.description : undefined,
1022
+ cik: item.asset.cik !== undefined ? item.asset.cik : undefined,
1023
+ exchange: item.asset.exchange !== undefined ? item.asset.exchange : undefined,
1024
+ currency: item.asset.currency !== undefined ? item.asset.currency : undefined,
1025
+ country: item.asset.country !== undefined ? item.asset.country : undefined,
1026
+ sector: item.asset.sector !== undefined ? item.asset.sector : undefined,
1027
+ industry: item.asset.industry !== undefined ? item.asset.industry : undefined,
1028
+ address: item.asset.address !== undefined ? item.asset.address : undefined,
1029
+ officialSite: item.asset.officialSite !== undefined ? item.asset.officialSite : undefined,
1030
+ fiscalYearEnd: item.asset.fiscalYearEnd !== undefined ? item.asset.fiscalYearEnd : undefined,
1031
+ latestQuarter: item.asset.latestQuarter !== undefined ? item.asset.latestQuarter : undefined,
1032
+ marketCapitalization: item.asset.marketCapitalization !== undefined ? item.asset.marketCapitalization : undefined,
1033
+ ebitda: item.asset.ebitda !== undefined ? item.asset.ebitda : undefined,
1034
+ peRatio: item.asset.peRatio !== undefined ? item.asset.peRatio : undefined,
1035
+ pegRatio: item.asset.pegRatio !== undefined ? item.asset.pegRatio : undefined,
1036
+ bookValue: item.asset.bookValue !== undefined ? item.asset.bookValue : undefined,
1037
+ dividendPerShare: item.asset.dividendPerShare !== undefined ? item.asset.dividendPerShare : undefined,
1038
+ dividendYield: item.asset.dividendYield !== undefined ? item.asset.dividendYield : undefined,
1039
+ eps: item.asset.eps !== undefined ? item.asset.eps : undefined,
1040
+ revenuePerShareTTM: item.asset.revenuePerShareTTM !== undefined ? item.asset.revenuePerShareTTM : undefined,
1041
+ profitMargin: item.asset.profitMargin !== undefined ? item.asset.profitMargin : undefined,
1042
+ operatingMarginTTM: item.asset.operatingMarginTTM !== undefined ? item.asset.operatingMarginTTM : undefined,
1043
+ returnOnAssetsTTM: item.asset.returnOnAssetsTTM !== undefined ? item.asset.returnOnAssetsTTM : undefined,
1044
+ returnOnEquityTTM: item.asset.returnOnEquityTTM !== undefined ? item.asset.returnOnEquityTTM : undefined,
1045
+ revenueTTM: item.asset.revenueTTM !== undefined ? item.asset.revenueTTM : undefined,
1046
+ grossProfitTTM: item.asset.grossProfitTTM !== undefined ? item.asset.grossProfitTTM : undefined,
1047
+ dilutedEPSTTM: item.asset.dilutedEPSTTM !== undefined ? item.asset.dilutedEPSTTM : undefined,
1048
+ quarterlyEarningsGrowthYOY: item.asset.quarterlyEarningsGrowthYOY !== undefined ? item.asset.quarterlyEarningsGrowthYOY : undefined,
1049
+ quarterlyRevenueGrowthYOY: item.asset.quarterlyRevenueGrowthYOY !== undefined ? item.asset.quarterlyRevenueGrowthYOY : undefined,
1050
+ analystTargetPrice: item.asset.analystTargetPrice !== undefined ? item.asset.analystTargetPrice : undefined,
1051
+ analystRatingStrongBuy: item.asset.analystRatingStrongBuy !== undefined ? item.asset.analystRatingStrongBuy : undefined,
1052
+ analystRatingBuy: item.asset.analystRatingBuy !== undefined ? item.asset.analystRatingBuy : undefined,
1053
+ analystRatingHold: item.asset.analystRatingHold !== undefined ? item.asset.analystRatingHold : undefined,
1054
+ analystRatingSell: item.asset.analystRatingSell !== undefined ? item.asset.analystRatingSell : undefined,
1055
+ analystRatingStrongSell: item.asset.analystRatingStrongSell !== undefined ? item.asset.analystRatingStrongSell : undefined,
1056
+ trailingPE: item.asset.trailingPE !== undefined ? item.asset.trailingPE : undefined,
1057
+ forwardPE: item.asset.forwardPE !== undefined ? item.asset.forwardPE : undefined,
1058
+ priceToSalesRatioTTM: item.asset.priceToSalesRatioTTM !== undefined ? item.asset.priceToSalesRatioTTM : undefined,
1059
+ priceToBookRatio: item.asset.priceToBookRatio !== undefined ? item.asset.priceToBookRatio : undefined,
1060
+ evToRevenue: item.asset.evToRevenue !== undefined ? item.asset.evToRevenue : undefined,
1061
+ evToEbitda: item.asset.evToEbitda !== undefined ? item.asset.evToEbitda : undefined,
1062
+ beta: item.asset.beta !== undefined ? item.asset.beta : undefined,
1063
+ week52High: item.asset.week52High !== undefined ? item.asset.week52High : undefined,
1064
+ week52Low: item.asset.week52Low !== undefined ? item.asset.week52Low : undefined,
1065
+ day50MovingAverage: item.asset.day50MovingAverage !== undefined ? item.asset.day50MovingAverage : undefined,
1066
+ day200MovingAverage: item.asset.day200MovingAverage !== undefined ? item.asset.day200MovingAverage : undefined,
1067
+ sharesOutstanding: item.asset.sharesOutstanding !== undefined ? item.asset.sharesOutstanding : undefined,
1068
+ dividendDate: item.asset.dividendDate !== undefined ? item.asset.dividendDate : undefined,
1069
+ exDividendDate: item.asset.exDividendDate !== undefined ? item.asset.exDividendDate : undefined,
1070
+ askPrice: item.asset.askPrice !== undefined ? item.asset.askPrice : undefined,
1071
+ bidPrice: item.asset.bidPrice !== undefined ? item.asset.bidPrice : undefined,
1072
+ },
1073
+ }
1074
+ } : undefined,
1075
+ },
1076
+ }))
1077
+ } : undefined,
1078
+ },
1079
+ update: {
1080
+ title: props.title !== undefined ? {
1081
+ set: props.title
1082
+ } : undefined,
1083
+ content: props.content !== undefined ? {
1084
+ set: props.content
1085
+ } : undefined,
1086
+ source: props.source !== undefined ? {
1087
+ set: props.source
1088
+ } : undefined,
1089
+ sourceDomain: props.sourceDomain !== undefined ? {
1090
+ set: props.sourceDomain
1091
+ } : undefined,
1092
+ url: props.url !== undefined ? {
1093
+ set: props.url
1094
+ } : undefined,
1095
+ sentiment: props.sentiment !== undefined ? {
1096
+ set: props.sentiment
1097
+ } : undefined,
1098
+ authors: props.authors !== undefined ? {
1099
+ set: props.authors
1100
+ } : undefined,
1101
+ summary: props.summary !== undefined ? {
1102
+ set: props.summary
1103
+ } : undefined,
1104
+ bannerImage: props.bannerImage !== undefined ? {
1105
+ set: props.bannerImage
1106
+ } : undefined,
1107
+ timePublished: props.timePublished !== undefined ? {
1108
+ set: props.timePublished
1109
+ } : undefined,
1110
+ category: props.category !== undefined ? {
1111
+ set: props.category
1112
+ } : undefined,
1113
+ topics: props.topics !== undefined ? {
1114
+ set: props.topics
1115
+ } : undefined,
1116
+ logo: props.logo !== undefined ? {
1117
+ set: props.logo
1118
+ } : undefined,
1119
+ assets: props.assets ?
1120
+ 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) ? {
1121
+ connect: props.assets.map((item) => ({
1122
+ id: item.id
1123
+ }))
1124
+ } : { upsert: props.assets.map((item) => ({
1125
+ where: {
1126
+ id: item.id !== undefined ? item.id : undefined,
1127
+ url: item.url !== undefined ? item.url : undefined,
1128
+ assetId: item.assetId !== undefined ? {
1129
+ equals: item.assetId
1130
+ } : undefined,
1131
+ newsArticleId: item.newsArticleId !== undefined ? {
1132
+ equals: item.newsArticleId
1133
+ } : undefined,
1134
+ },
1135
+ update: {
1136
+ id: item.id !== undefined ? {
1137
+ set: item.id
1138
+ } : undefined,
1139
+ url: item.url !== undefined ? {
1140
+ set: item.url
1141
+ } : undefined,
1142
+ relevancyScore: item.relevancyScore !== undefined ? {
1143
+ set: item.relevancyScore
1144
+ } : undefined,
1145
+ sentimentScore: item.sentimentScore !== undefined ? {
1146
+ set: item.sentimentScore
1147
+ } : undefined,
1148
+ sentimentLabel: item.sentimentLabel !== undefined ? {
1149
+ set: item.sentimentLabel
1150
+ } : undefined,
1151
+ asset: item.asset ?
1152
+ typeof item.asset === 'object' && Object.keys(item.asset).length === 1 && (Object.keys(item.asset)[0] === 'id' || Object.keys(item.asset)[0] === 'symbol')
1153
+ ? {
1154
+ connect: {
1155
+ id: item.asset.id
1156
+ }
1157
+ } : { upsert: {
833
1158
  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,
1159
+ id: item.asset.id !== undefined ? {
1160
+ equals: item.asset.id
1161
+ } : undefined,
1162
+ symbol: item.asset.symbol !== undefined ? {
1163
+ equals: item.asset.symbol
1164
+ } : undefined,
1165
+ name: item.asset.name !== undefined ? {
1166
+ equals: item.asset.name
1167
+ } : undefined,
1168
+ },
1169
+ update: {
1170
+ id: item.asset.id !== undefined ? {
1171
+ set: item.asset.id
1172
+ } : undefined,
1173
+ symbol: item.asset.symbol !== undefined ? {
1174
+ set: item.asset.symbol
1175
+ } : undefined,
1176
+ name: item.asset.name !== undefined ? {
1177
+ set: item.asset.name
1178
+ } : undefined,
1179
+ type: item.asset.type !== undefined ? {
1180
+ set: item.asset.type
1181
+ } : undefined,
1182
+ logoUrl: item.asset.logoUrl !== undefined ? {
1183
+ set: item.asset.logoUrl
1184
+ } : undefined,
1185
+ description: item.asset.description !== undefined ? {
1186
+ set: item.asset.description
1187
+ } : undefined,
1188
+ cik: item.asset.cik !== undefined ? {
1189
+ set: item.asset.cik
1190
+ } : undefined,
1191
+ exchange: item.asset.exchange !== undefined ? {
1192
+ set: item.asset.exchange
1193
+ } : undefined,
1194
+ currency: item.asset.currency !== undefined ? {
1195
+ set: item.asset.currency
1196
+ } : undefined,
1197
+ country: item.asset.country !== undefined ? {
1198
+ set: item.asset.country
1199
+ } : undefined,
1200
+ sector: item.asset.sector !== undefined ? {
1201
+ set: item.asset.sector
1202
+ } : undefined,
1203
+ industry: item.asset.industry !== undefined ? {
1204
+ set: item.asset.industry
1205
+ } : undefined,
1206
+ address: item.asset.address !== undefined ? {
1207
+ set: item.asset.address
1208
+ } : undefined,
1209
+ officialSite: item.asset.officialSite !== undefined ? {
1210
+ set: item.asset.officialSite
1211
+ } : undefined,
1212
+ fiscalYearEnd: item.asset.fiscalYearEnd !== undefined ? {
1213
+ set: item.asset.fiscalYearEnd
1214
+ } : undefined,
1215
+ latestQuarter: item.asset.latestQuarter !== undefined ? {
1216
+ set: item.asset.latestQuarter
1217
+ } : undefined,
1218
+ marketCapitalization: item.asset.marketCapitalization !== undefined ? {
1219
+ set: item.asset.marketCapitalization
1220
+ } : undefined,
1221
+ ebitda: item.asset.ebitda !== undefined ? {
1222
+ set: item.asset.ebitda
1223
+ } : undefined,
1224
+ peRatio: item.asset.peRatio !== undefined ? {
1225
+ set: item.asset.peRatio
1226
+ } : undefined,
1227
+ pegRatio: item.asset.pegRatio !== undefined ? {
1228
+ set: item.asset.pegRatio
1229
+ } : undefined,
1230
+ bookValue: item.asset.bookValue !== undefined ? {
1231
+ set: item.asset.bookValue
1232
+ } : undefined,
1233
+ dividendPerShare: item.asset.dividendPerShare !== undefined ? {
1234
+ set: item.asset.dividendPerShare
1235
+ } : undefined,
1236
+ dividendYield: item.asset.dividendYield !== undefined ? {
1237
+ set: item.asset.dividendYield
1238
+ } : undefined,
1239
+ eps: item.asset.eps !== undefined ? {
1240
+ set: item.asset.eps
1241
+ } : undefined,
1242
+ revenuePerShareTTM: item.asset.revenuePerShareTTM !== undefined ? {
1243
+ set: item.asset.revenuePerShareTTM
1244
+ } : undefined,
1245
+ profitMargin: item.asset.profitMargin !== undefined ? {
1246
+ set: item.asset.profitMargin
1247
+ } : undefined,
1248
+ operatingMarginTTM: item.asset.operatingMarginTTM !== undefined ? {
1249
+ set: item.asset.operatingMarginTTM
1250
+ } : undefined,
1251
+ returnOnAssetsTTM: item.asset.returnOnAssetsTTM !== undefined ? {
1252
+ set: item.asset.returnOnAssetsTTM
1253
+ } : undefined,
1254
+ returnOnEquityTTM: item.asset.returnOnEquityTTM !== undefined ? {
1255
+ set: item.asset.returnOnEquityTTM
1256
+ } : undefined,
1257
+ revenueTTM: item.asset.revenueTTM !== undefined ? {
1258
+ set: item.asset.revenueTTM
1259
+ } : undefined,
1260
+ grossProfitTTM: item.asset.grossProfitTTM !== undefined ? {
1261
+ set: item.asset.grossProfitTTM
1262
+ } : undefined,
1263
+ dilutedEPSTTM: item.asset.dilutedEPSTTM !== undefined ? {
1264
+ set: item.asset.dilutedEPSTTM
1265
+ } : undefined,
1266
+ quarterlyEarningsGrowthYOY: item.asset.quarterlyEarningsGrowthYOY !== undefined ? {
1267
+ set: item.asset.quarterlyEarningsGrowthYOY
1268
+ } : undefined,
1269
+ quarterlyRevenueGrowthYOY: item.asset.quarterlyRevenueGrowthYOY !== undefined ? {
1270
+ set: item.asset.quarterlyRevenueGrowthYOY
1271
+ } : undefined,
1272
+ analystTargetPrice: item.asset.analystTargetPrice !== undefined ? {
1273
+ set: item.asset.analystTargetPrice
1274
+ } : undefined,
1275
+ analystRatingStrongBuy: item.asset.analystRatingStrongBuy !== undefined ? {
1276
+ set: item.asset.analystRatingStrongBuy
1277
+ } : undefined,
1278
+ analystRatingBuy: item.asset.analystRatingBuy !== undefined ? {
1279
+ set: item.asset.analystRatingBuy
1280
+ } : undefined,
1281
+ analystRatingHold: item.asset.analystRatingHold !== undefined ? {
1282
+ set: item.asset.analystRatingHold
1283
+ } : undefined,
1284
+ analystRatingSell: item.asset.analystRatingSell !== undefined ? {
1285
+ set: item.asset.analystRatingSell
1286
+ } : undefined,
1287
+ analystRatingStrongSell: item.asset.analystRatingStrongSell !== undefined ? {
1288
+ set: item.asset.analystRatingStrongSell
1289
+ } : undefined,
1290
+ trailingPE: item.asset.trailingPE !== undefined ? {
1291
+ set: item.asset.trailingPE
1292
+ } : undefined,
1293
+ forwardPE: item.asset.forwardPE !== undefined ? {
1294
+ set: item.asset.forwardPE
1295
+ } : undefined,
1296
+ priceToSalesRatioTTM: item.asset.priceToSalesRatioTTM !== undefined ? {
1297
+ set: item.asset.priceToSalesRatioTTM
1298
+ } : undefined,
1299
+ priceToBookRatio: item.asset.priceToBookRatio !== undefined ? {
1300
+ set: item.asset.priceToBookRatio
1301
+ } : undefined,
1302
+ evToRevenue: item.asset.evToRevenue !== undefined ? {
1303
+ set: item.asset.evToRevenue
1304
+ } : undefined,
1305
+ evToEbitda: item.asset.evToEbitda !== undefined ? {
1306
+ set: item.asset.evToEbitda
1307
+ } : undefined,
1308
+ beta: item.asset.beta !== undefined ? {
1309
+ set: item.asset.beta
1310
+ } : undefined,
1311
+ week52High: item.asset.week52High !== undefined ? {
1312
+ set: item.asset.week52High
1313
+ } : undefined,
1314
+ week52Low: item.asset.week52Low !== undefined ? {
1315
+ set: item.asset.week52Low
1316
+ } : undefined,
1317
+ day50MovingAverage: item.asset.day50MovingAverage !== undefined ? {
1318
+ set: item.asset.day50MovingAverage
1319
+ } : undefined,
1320
+ day200MovingAverage: item.asset.day200MovingAverage !== undefined ? {
1321
+ set: item.asset.day200MovingAverage
1322
+ } : undefined,
1323
+ sharesOutstanding: item.asset.sharesOutstanding !== undefined ? {
1324
+ set: item.asset.sharesOutstanding
1325
+ } : undefined,
1326
+ dividendDate: item.asset.dividendDate !== undefined ? {
1327
+ set: item.asset.dividendDate
1328
+ } : undefined,
1329
+ exDividendDate: item.asset.exDividendDate !== undefined ? {
1330
+ set: item.asset.exDividendDate
1331
+ } : undefined,
1332
+ askPrice: item.asset.askPrice !== undefined ? {
1333
+ set: item.asset.askPrice
1334
+ } : undefined,
1335
+ bidPrice: item.asset.bidPrice !== undefined ? {
1336
+ set: item.asset.bidPrice
1337
+ } : undefined,
837
1338
  },
838
1339
  create: {
839
1340
  symbol: item.asset.symbol !== undefined ? item.asset.symbol : undefined,
@@ -894,1060 +1395,1011 @@ export const NewsArticle = {
894
1395
  },
895
1396
  }
896
1397
  } : 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;
1398
+ },
1399
+ create: {
1400
+ url: item.url !== undefined ? item.url : undefined,
1401
+ relevancyScore: item.relevancyScore !== undefined ? item.relevancyScore : undefined,
1402
+ sentimentScore: item.sentimentScore !== undefined ? item.sentimentScore : undefined,
1403
+ sentimentLabel: item.sentimentLabel !== undefined ? item.sentimentLabel : undefined,
1404
+ asset: item.asset ?
1405
+ typeof item.asset === 'object' && Object.keys(item.asset).length === 1 && Object.keys(item.asset)[0] === 'id'
1406
+ ? { connect: {
1407
+ id: item.asset.id
1408
+ }
1409
+ }
1410
+ : { connectOrCreate: {
1411
+ where: {
1412
+ id: item.asset.id !== undefined ? item.asset.id : undefined,
1413
+ symbol: item.asset.symbol !== undefined ? item.asset.symbol : undefined,
1414
+ name: item.asset.name !== undefined ? item.asset.name : undefined,
1415
+ },
1416
+ create: {
1417
+ symbol: item.asset.symbol !== undefined ? item.asset.symbol : undefined,
1418
+ name: item.asset.name !== undefined ? item.asset.name : undefined,
1419
+ type: item.asset.type !== undefined ? item.asset.type : undefined,
1420
+ logoUrl: item.asset.logoUrl !== undefined ? item.asset.logoUrl : undefined,
1421
+ description: item.asset.description !== undefined ? item.asset.description : undefined,
1422
+ cik: item.asset.cik !== undefined ? item.asset.cik : undefined,
1423
+ exchange: item.asset.exchange !== undefined ? item.asset.exchange : undefined,
1424
+ currency: item.asset.currency !== undefined ? item.asset.currency : undefined,
1425
+ country: item.asset.country !== undefined ? item.asset.country : undefined,
1426
+ sector: item.asset.sector !== undefined ? item.asset.sector : undefined,
1427
+ industry: item.asset.industry !== undefined ? item.asset.industry : undefined,
1428
+ address: item.asset.address !== undefined ? item.asset.address : undefined,
1429
+ officialSite: item.asset.officialSite !== undefined ? item.asset.officialSite : undefined,
1430
+ fiscalYearEnd: item.asset.fiscalYearEnd !== undefined ? item.asset.fiscalYearEnd : undefined,
1431
+ latestQuarter: item.asset.latestQuarter !== undefined ? item.asset.latestQuarter : undefined,
1432
+ marketCapitalization: item.asset.marketCapitalization !== undefined ? item.asset.marketCapitalization : undefined,
1433
+ ebitda: item.asset.ebitda !== undefined ? item.asset.ebitda : undefined,
1434
+ peRatio: item.asset.peRatio !== undefined ? item.asset.peRatio : undefined,
1435
+ pegRatio: item.asset.pegRatio !== undefined ? item.asset.pegRatio : undefined,
1436
+ bookValue: item.asset.bookValue !== undefined ? item.asset.bookValue : undefined,
1437
+ dividendPerShare: item.asset.dividendPerShare !== undefined ? item.asset.dividendPerShare : undefined,
1438
+ dividendYield: item.asset.dividendYield !== undefined ? item.asset.dividendYield : undefined,
1439
+ eps: item.asset.eps !== undefined ? item.asset.eps : undefined,
1440
+ revenuePerShareTTM: item.asset.revenuePerShareTTM !== undefined ? item.asset.revenuePerShareTTM : undefined,
1441
+ profitMargin: item.asset.profitMargin !== undefined ? item.asset.profitMargin : undefined,
1442
+ operatingMarginTTM: item.asset.operatingMarginTTM !== undefined ? item.asset.operatingMarginTTM : undefined,
1443
+ returnOnAssetsTTM: item.asset.returnOnAssetsTTM !== undefined ? item.asset.returnOnAssetsTTM : undefined,
1444
+ returnOnEquityTTM: item.asset.returnOnEquityTTM !== undefined ? item.asset.returnOnEquityTTM : undefined,
1445
+ revenueTTM: item.asset.revenueTTM !== undefined ? item.asset.revenueTTM : undefined,
1446
+ grossProfitTTM: item.asset.grossProfitTTM !== undefined ? item.asset.grossProfitTTM : undefined,
1447
+ dilutedEPSTTM: item.asset.dilutedEPSTTM !== undefined ? item.asset.dilutedEPSTTM : undefined,
1448
+ quarterlyEarningsGrowthYOY: item.asset.quarterlyEarningsGrowthYOY !== undefined ? item.asset.quarterlyEarningsGrowthYOY : undefined,
1449
+ quarterlyRevenueGrowthYOY: item.asset.quarterlyRevenueGrowthYOY !== undefined ? item.asset.quarterlyRevenueGrowthYOY : undefined,
1450
+ analystTargetPrice: item.asset.analystTargetPrice !== undefined ? item.asset.analystTargetPrice : undefined,
1451
+ analystRatingStrongBuy: item.asset.analystRatingStrongBuy !== undefined ? item.asset.analystRatingStrongBuy : undefined,
1452
+ analystRatingBuy: item.asset.analystRatingBuy !== undefined ? item.asset.analystRatingBuy : undefined,
1453
+ analystRatingHold: item.asset.analystRatingHold !== undefined ? item.asset.analystRatingHold : undefined,
1454
+ analystRatingSell: item.asset.analystRatingSell !== undefined ? item.asset.analystRatingSell : undefined,
1455
+ analystRatingStrongSell: item.asset.analystRatingStrongSell !== undefined ? item.asset.analystRatingStrongSell : undefined,
1456
+ trailingPE: item.asset.trailingPE !== undefined ? item.asset.trailingPE : undefined,
1457
+ forwardPE: item.asset.forwardPE !== undefined ? item.asset.forwardPE : undefined,
1458
+ priceToSalesRatioTTM: item.asset.priceToSalesRatioTTM !== undefined ? item.asset.priceToSalesRatioTTM : undefined,
1459
+ priceToBookRatio: item.asset.priceToBookRatio !== undefined ? item.asset.priceToBookRatio : undefined,
1460
+ evToRevenue: item.asset.evToRevenue !== undefined ? item.asset.evToRevenue : undefined,
1461
+ evToEbitda: item.asset.evToEbitda !== undefined ? item.asset.evToEbitda : undefined,
1462
+ beta: item.asset.beta !== undefined ? item.asset.beta : undefined,
1463
+ week52High: item.asset.week52High !== undefined ? item.asset.week52High : undefined,
1464
+ week52Low: item.asset.week52Low !== undefined ? item.asset.week52Low : undefined,
1465
+ day50MovingAverage: item.asset.day50MovingAverage !== undefined ? item.asset.day50MovingAverage : undefined,
1466
+ day200MovingAverage: item.asset.day200MovingAverage !== undefined ? item.asset.day200MovingAverage : undefined,
1467
+ sharesOutstanding: item.asset.sharesOutstanding !== undefined ? item.asset.sharesOutstanding : undefined,
1468
+ dividendDate: item.asset.dividendDate !== undefined ? item.asset.dividendDate : undefined,
1469
+ exDividendDate: item.asset.exDividendDate !== undefined ? item.asset.exDividendDate : undefined,
1470
+ askPrice: item.asset.askPrice !== undefined ? item.asset.askPrice : undefined,
1471
+ bidPrice: item.asset.bidPrice !== undefined ? item.asset.bidPrice : undefined,
1472
+ },
1473
+ }
1474
+ } : undefined,
1475
+ },
1476
+ }))
1477
+ } : undefined,
1478
+ },
1479
+ };
1480
+ const filteredVariables = removeUndefinedProps(variables);
1481
+ const response = await client.mutate({
1482
+ mutation: UPSERT_ONE_NEWSARTICLE,
1483
+ variables: filteredVariables,
1484
+ // Don't cache mutations, but ensure we're using the freshest context
1485
+ fetchPolicy: 'no-cache'
1486
+ });
1487
+ if (response.errors && response.errors.length > 0)
1488
+ throw new Error(response.errors[0].message);
1489
+ if (response && response.data && response.data.upsertOneNewsArticle) {
1490
+ return response.data.upsertOneNewsArticle;
1491
+ }
1492
+ else {
1493
+ return null;
1494
+ }
1309
1495
  }
1310
- else {
1311
- return null;
1496
+ catch (error) {
1497
+ lastError = error;
1498
+ // Check if this is a database connection error that we should retry
1499
+ const isConnectionError = error.message?.includes('Server has closed the connection') ||
1500
+ error.message?.includes('Cannot reach database server') ||
1501
+ error.message?.includes('Connection timed out') ||
1502
+ error.message?.includes('Accelerate') || // Prisma Accelerate proxy errors
1503
+ (error.networkError && error.networkError.message?.includes('Failed to fetch'));
1504
+ if (isConnectionError && retryCount < MAX_RETRIES - 1) {
1505
+ retryCount++;
1506
+ const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
1507
+ console.warn("Database connection error, retrying...");
1508
+ await new Promise(resolve => setTimeout(resolve, delay));
1509
+ continue;
1510
+ }
1511
+ // Log the error and rethrow
1512
+ console.error("Database error occurred:", error);
1513
+ throw error;
1312
1514
  }
1313
1515
  }
1314
- catch (error) {
1315
- console.error('Error in upsertOneNewsArticle:', error);
1316
- throw error;
1317
- }
1516
+ // If we exhausted retries, throw the last error
1517
+ throw lastError;
1318
1518
  },
1319
1519
  /**
1320
1520
  * Update multiple NewsArticle records.
1521
+ * Enhanced with connection resilience against Prisma connection errors.
1321
1522
  * @param props - Array of NewsArticle objects for the updated records.
1322
1523
  * @param globalClient - Apollo Client instance.
1323
1524
  * @returns The count of created records or null.
1324
1525
  */
1325
1526
  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
- }
1527
+ // Maximum number of retries for database connection issues
1528
+ const MAX_RETRIES = 3;
1529
+ let retryCount = 0;
1530
+ let lastError = null;
1531
+ // Retry loop to handle potential database connection issues
1532
+ while (retryCount < MAX_RETRIES) {
1533
+ try {
1534
+ const [modules, client] = await Promise.all([
1535
+ getApolloModules(),
1536
+ globalClient
1537
+ ? Promise.resolve(globalClient)
1538
+ : importedClient
1539
+ ]);
1540
+ const { gql, ApolloError } = modules;
1541
+ const UPDATE_MANY_NEWSARTICLE = gql `
1542
+ mutation updateManyNewsArticle($data: [NewsArticleCreateManyInput!]!) {
1543
+ updateManyNewsArticle(data: $data) {
1544
+ count
1545
+ }
1546
+ }`;
1547
+ const variables = props.map(prop => ({
1548
+ where: {
1549
+ id: prop.id !== undefined ? prop.id : undefined,
1550
+ url: prop.url !== undefined ? prop.url : undefined,
1551
+ title: prop.title !== undefined ? prop.title : undefined,
1552
+ content: prop.content !== undefined ? {
1553
+ equals: prop.content
1554
+ } : undefined,
1555
+ source: prop.source !== undefined ? {
1556
+ equals: prop.source
1557
+ } : undefined,
1558
+ sourceDomain: prop.sourceDomain !== undefined ? {
1559
+ equals: prop.sourceDomain
1560
+ } : undefined,
1561
+ sentiment: prop.sentiment !== undefined ? {
1562
+ equals: prop.sentiment
1563
+ } : undefined,
1564
+ authors: prop.authors !== undefined ? {
1565
+ equals: prop.authors
1566
+ } : undefined,
1567
+ summary: prop.summary !== undefined ? {
1568
+ equals: prop.summary
1569
+ } : undefined,
1570
+ bannerImage: prop.bannerImage !== undefined ? {
1571
+ equals: prop.bannerImage
1572
+ } : undefined,
1573
+ timePublished: prop.timePublished !== undefined ? {
1574
+ equals: prop.timePublished
1575
+ } : undefined,
1576
+ category: prop.category !== undefined ? {
1577
+ equals: prop.category
1578
+ } : undefined,
1579
+ topics: prop.topics !== undefined ? {
1580
+ equals: prop.topics
1581
+ } : undefined,
1582
+ logo: prop.logo !== undefined ? {
1583
+ equals: prop.logo
1584
+ } : undefined,
1585
+ createdAt: prop.createdAt !== undefined ? {
1586
+ equals: prop.createdAt
1587
+ } : undefined,
1588
+ updatedAt: prop.updatedAt !== undefined ? {
1589
+ equals: prop.updatedAt
1590
+ } : undefined,
1591
+ },
1592
+ data: {
1593
+ id: prop.id !== undefined ? {
1594
+ set: prop.id
1595
+ } : undefined,
1596
+ title: prop.title !== undefined ? {
1597
+ set: prop.title
1598
+ } : undefined,
1599
+ content: prop.content !== undefined ? {
1600
+ set: prop.content
1601
+ } : undefined,
1602
+ source: prop.source !== undefined ? {
1603
+ set: prop.source
1604
+ } : undefined,
1605
+ sourceDomain: prop.sourceDomain !== undefined ? {
1606
+ set: prop.sourceDomain
1607
+ } : undefined,
1608
+ url: prop.url !== undefined ? {
1609
+ set: prop.url
1610
+ } : undefined,
1611
+ sentiment: prop.sentiment !== undefined ? {
1612
+ set: prop.sentiment
1613
+ } : undefined,
1614
+ authors: prop.authors !== undefined ? {
1615
+ set: prop.authors
1616
+ } : undefined,
1617
+ summary: prop.summary !== undefined ? {
1618
+ set: prop.summary
1619
+ } : undefined,
1620
+ bannerImage: prop.bannerImage !== undefined ? {
1621
+ set: prop.bannerImage
1622
+ } : undefined,
1623
+ timePublished: prop.timePublished !== undefined ? {
1624
+ set: prop.timePublished
1625
+ } : undefined,
1626
+ category: prop.category !== undefined ? {
1627
+ set: prop.category
1628
+ } : undefined,
1629
+ topics: prop.topics !== undefined ? {
1630
+ set: prop.topics
1631
+ } : undefined,
1632
+ logo: prop.logo !== undefined ? {
1633
+ set: prop.logo
1634
+ } : undefined,
1635
+ createdAt: prop.createdAt !== undefined ? {
1636
+ set: prop.createdAt
1637
+ } : undefined,
1638
+ updatedAt: prop.updatedAt !== undefined ? {
1639
+ set: prop.updatedAt
1640
+ } : undefined,
1641
+ assets: prop.assets ?
1642
+ 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) ? {
1643
+ connect: prop.assets.map((item) => ({
1644
+ id: item.id
1645
+ }))
1646
+ } : { upsert: prop.assets.map((item) => ({
1647
+ where: {
1648
+ id: item.id !== undefined ? item.id : undefined,
1649
+ url: item.url !== undefined ? item.url : undefined,
1650
+ assetId: item.assetId !== undefined ? {
1651
+ equals: item.assetId
1652
+ } : undefined,
1653
+ newsArticleId: item.newsArticleId !== undefined ? {
1654
+ equals: item.newsArticleId
1655
+ } : undefined,
1656
+ },
1657
+ update: {
1658
+ id: item.id !== undefined ? {
1659
+ set: item.id
1660
+ } : undefined,
1661
+ url: item.url !== undefined ? {
1662
+ set: item.url
1663
+ } : undefined,
1664
+ relevancyScore: item.relevancyScore !== undefined ? {
1665
+ set: item.relevancyScore
1751
1666
  } : 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;
1667
+ sentimentScore: item.sentimentScore !== undefined ? {
1668
+ set: item.sentimentScore
1669
+ } : undefined,
1670
+ sentimentLabel: item.sentimentLabel !== undefined ? {
1671
+ set: item.sentimentLabel
1672
+ } : undefined,
1673
+ asset: item.asset ?
1674
+ typeof item.asset === 'object' && Object.keys(item.asset).length === 1 && (Object.keys(item.asset)[0] === 'id' || Object.keys(item.asset)[0] === 'symbol')
1675
+ ? {
1676
+ connect: {
1677
+ id: item.asset.id
1678
+ }
1679
+ } : { upsert: {
1680
+ where: {
1681
+ id: item.asset.id !== undefined ? {
1682
+ equals: item.asset.id
1683
+ } : undefined,
1684
+ symbol: item.asset.symbol !== undefined ? {
1685
+ equals: item.asset.symbol
1686
+ } : undefined,
1687
+ name: item.asset.name !== undefined ? {
1688
+ equals: item.asset.name
1689
+ } : undefined,
1690
+ },
1691
+ update: {
1692
+ id: item.asset.id !== undefined ? {
1693
+ set: item.asset.id
1694
+ } : undefined,
1695
+ symbol: item.asset.symbol !== undefined ? {
1696
+ set: item.asset.symbol
1697
+ } : undefined,
1698
+ name: item.asset.name !== undefined ? {
1699
+ set: item.asset.name
1700
+ } : undefined,
1701
+ type: item.asset.type !== undefined ? {
1702
+ set: item.asset.type
1703
+ } : undefined,
1704
+ logoUrl: item.asset.logoUrl !== undefined ? {
1705
+ set: item.asset.logoUrl
1706
+ } : undefined,
1707
+ description: item.asset.description !== undefined ? {
1708
+ set: item.asset.description
1709
+ } : undefined,
1710
+ cik: item.asset.cik !== undefined ? {
1711
+ set: item.asset.cik
1712
+ } : undefined,
1713
+ exchange: item.asset.exchange !== undefined ? {
1714
+ set: item.asset.exchange
1715
+ } : undefined,
1716
+ currency: item.asset.currency !== undefined ? {
1717
+ set: item.asset.currency
1718
+ } : undefined,
1719
+ country: item.asset.country !== undefined ? {
1720
+ set: item.asset.country
1721
+ } : undefined,
1722
+ sector: item.asset.sector !== undefined ? {
1723
+ set: item.asset.sector
1724
+ } : undefined,
1725
+ industry: item.asset.industry !== undefined ? {
1726
+ set: item.asset.industry
1727
+ } : undefined,
1728
+ address: item.asset.address !== undefined ? {
1729
+ set: item.asset.address
1730
+ } : undefined,
1731
+ officialSite: item.asset.officialSite !== undefined ? {
1732
+ set: item.asset.officialSite
1733
+ } : undefined,
1734
+ fiscalYearEnd: item.asset.fiscalYearEnd !== undefined ? {
1735
+ set: item.asset.fiscalYearEnd
1736
+ } : undefined,
1737
+ latestQuarter: item.asset.latestQuarter !== undefined ? {
1738
+ set: item.asset.latestQuarter
1739
+ } : undefined,
1740
+ marketCapitalization: item.asset.marketCapitalization !== undefined ? {
1741
+ set: item.asset.marketCapitalization
1742
+ } : undefined,
1743
+ ebitda: item.asset.ebitda !== undefined ? {
1744
+ set: item.asset.ebitda
1745
+ } : undefined,
1746
+ peRatio: item.asset.peRatio !== undefined ? {
1747
+ set: item.asset.peRatio
1748
+ } : undefined,
1749
+ pegRatio: item.asset.pegRatio !== undefined ? {
1750
+ set: item.asset.pegRatio
1751
+ } : undefined,
1752
+ bookValue: item.asset.bookValue !== undefined ? {
1753
+ set: item.asset.bookValue
1754
+ } : undefined,
1755
+ dividendPerShare: item.asset.dividendPerShare !== undefined ? {
1756
+ set: item.asset.dividendPerShare
1757
+ } : undefined,
1758
+ dividendYield: item.asset.dividendYield !== undefined ? {
1759
+ set: item.asset.dividendYield
1760
+ } : undefined,
1761
+ eps: item.asset.eps !== undefined ? {
1762
+ set: item.asset.eps
1763
+ } : undefined,
1764
+ revenuePerShareTTM: item.asset.revenuePerShareTTM !== undefined ? {
1765
+ set: item.asset.revenuePerShareTTM
1766
+ } : undefined,
1767
+ profitMargin: item.asset.profitMargin !== undefined ? {
1768
+ set: item.asset.profitMargin
1769
+ } : undefined,
1770
+ operatingMarginTTM: item.asset.operatingMarginTTM !== undefined ? {
1771
+ set: item.asset.operatingMarginTTM
1772
+ } : undefined,
1773
+ returnOnAssetsTTM: item.asset.returnOnAssetsTTM !== undefined ? {
1774
+ set: item.asset.returnOnAssetsTTM
1775
+ } : undefined,
1776
+ returnOnEquityTTM: item.asset.returnOnEquityTTM !== undefined ? {
1777
+ set: item.asset.returnOnEquityTTM
1778
+ } : undefined,
1779
+ revenueTTM: item.asset.revenueTTM !== undefined ? {
1780
+ set: item.asset.revenueTTM
1781
+ } : undefined,
1782
+ grossProfitTTM: item.asset.grossProfitTTM !== undefined ? {
1783
+ set: item.asset.grossProfitTTM
1784
+ } : undefined,
1785
+ dilutedEPSTTM: item.asset.dilutedEPSTTM !== undefined ? {
1786
+ set: item.asset.dilutedEPSTTM
1787
+ } : undefined,
1788
+ quarterlyEarningsGrowthYOY: item.asset.quarterlyEarningsGrowthYOY !== undefined ? {
1789
+ set: item.asset.quarterlyEarningsGrowthYOY
1790
+ } : undefined,
1791
+ quarterlyRevenueGrowthYOY: item.asset.quarterlyRevenueGrowthYOY !== undefined ? {
1792
+ set: item.asset.quarterlyRevenueGrowthYOY
1793
+ } : undefined,
1794
+ analystTargetPrice: item.asset.analystTargetPrice !== undefined ? {
1795
+ set: item.asset.analystTargetPrice
1796
+ } : undefined,
1797
+ analystRatingStrongBuy: item.asset.analystRatingStrongBuy !== undefined ? {
1798
+ set: item.asset.analystRatingStrongBuy
1799
+ } : undefined,
1800
+ analystRatingBuy: item.asset.analystRatingBuy !== undefined ? {
1801
+ set: item.asset.analystRatingBuy
1802
+ } : undefined,
1803
+ analystRatingHold: item.asset.analystRatingHold !== undefined ? {
1804
+ set: item.asset.analystRatingHold
1805
+ } : undefined,
1806
+ analystRatingSell: item.asset.analystRatingSell !== undefined ? {
1807
+ set: item.asset.analystRatingSell
1808
+ } : undefined,
1809
+ analystRatingStrongSell: item.asset.analystRatingStrongSell !== undefined ? {
1810
+ set: item.asset.analystRatingStrongSell
1811
+ } : undefined,
1812
+ trailingPE: item.asset.trailingPE !== undefined ? {
1813
+ set: item.asset.trailingPE
1814
+ } : undefined,
1815
+ forwardPE: item.asset.forwardPE !== undefined ? {
1816
+ set: item.asset.forwardPE
1817
+ } : undefined,
1818
+ priceToSalesRatioTTM: item.asset.priceToSalesRatioTTM !== undefined ? {
1819
+ set: item.asset.priceToSalesRatioTTM
1820
+ } : undefined,
1821
+ priceToBookRatio: item.asset.priceToBookRatio !== undefined ? {
1822
+ set: item.asset.priceToBookRatio
1823
+ } : undefined,
1824
+ evToRevenue: item.asset.evToRevenue !== undefined ? {
1825
+ set: item.asset.evToRevenue
1826
+ } : undefined,
1827
+ evToEbitda: item.asset.evToEbitda !== undefined ? {
1828
+ set: item.asset.evToEbitda
1829
+ } : undefined,
1830
+ beta: item.asset.beta !== undefined ? {
1831
+ set: item.asset.beta
1832
+ } : undefined,
1833
+ week52High: item.asset.week52High !== undefined ? {
1834
+ set: item.asset.week52High
1835
+ } : undefined,
1836
+ week52Low: item.asset.week52Low !== undefined ? {
1837
+ set: item.asset.week52Low
1838
+ } : undefined,
1839
+ day50MovingAverage: item.asset.day50MovingAverage !== undefined ? {
1840
+ set: item.asset.day50MovingAverage
1841
+ } : undefined,
1842
+ day200MovingAverage: item.asset.day200MovingAverage !== undefined ? {
1843
+ set: item.asset.day200MovingAverage
1844
+ } : undefined,
1845
+ sharesOutstanding: item.asset.sharesOutstanding !== undefined ? {
1846
+ set: item.asset.sharesOutstanding
1847
+ } : undefined,
1848
+ dividendDate: item.asset.dividendDate !== undefined ? {
1849
+ set: item.asset.dividendDate
1850
+ } : undefined,
1851
+ exDividendDate: item.asset.exDividendDate !== undefined ? {
1852
+ set: item.asset.exDividendDate
1853
+ } : undefined,
1854
+ askPrice: item.asset.askPrice !== undefined ? {
1855
+ set: item.asset.askPrice
1856
+ } : undefined,
1857
+ bidPrice: item.asset.bidPrice !== undefined ? {
1858
+ set: item.asset.bidPrice
1859
+ } : undefined,
1860
+ },
1861
+ create: {
1862
+ symbol: item.asset.symbol !== undefined ? item.asset.symbol : undefined,
1863
+ name: item.asset.name !== undefined ? item.asset.name : undefined,
1864
+ type: item.asset.type !== undefined ? item.asset.type : undefined,
1865
+ logoUrl: item.asset.logoUrl !== undefined ? item.asset.logoUrl : undefined,
1866
+ description: item.asset.description !== undefined ? item.asset.description : undefined,
1867
+ cik: item.asset.cik !== undefined ? item.asset.cik : undefined,
1868
+ exchange: item.asset.exchange !== undefined ? item.asset.exchange : undefined,
1869
+ currency: item.asset.currency !== undefined ? item.asset.currency : undefined,
1870
+ country: item.asset.country !== undefined ? item.asset.country : undefined,
1871
+ sector: item.asset.sector !== undefined ? item.asset.sector : undefined,
1872
+ industry: item.asset.industry !== undefined ? item.asset.industry : undefined,
1873
+ address: item.asset.address !== undefined ? item.asset.address : undefined,
1874
+ officialSite: item.asset.officialSite !== undefined ? item.asset.officialSite : undefined,
1875
+ fiscalYearEnd: item.asset.fiscalYearEnd !== undefined ? item.asset.fiscalYearEnd : undefined,
1876
+ latestQuarter: item.asset.latestQuarter !== undefined ? item.asset.latestQuarter : undefined,
1877
+ marketCapitalization: item.asset.marketCapitalization !== undefined ? item.asset.marketCapitalization : undefined,
1878
+ ebitda: item.asset.ebitda !== undefined ? item.asset.ebitda : undefined,
1879
+ peRatio: item.asset.peRatio !== undefined ? item.asset.peRatio : undefined,
1880
+ pegRatio: item.asset.pegRatio !== undefined ? item.asset.pegRatio : undefined,
1881
+ bookValue: item.asset.bookValue !== undefined ? item.asset.bookValue : undefined,
1882
+ dividendPerShare: item.asset.dividendPerShare !== undefined ? item.asset.dividendPerShare : undefined,
1883
+ dividendYield: item.asset.dividendYield !== undefined ? item.asset.dividendYield : undefined,
1884
+ eps: item.asset.eps !== undefined ? item.asset.eps : undefined,
1885
+ revenuePerShareTTM: item.asset.revenuePerShareTTM !== undefined ? item.asset.revenuePerShareTTM : undefined,
1886
+ profitMargin: item.asset.profitMargin !== undefined ? item.asset.profitMargin : undefined,
1887
+ operatingMarginTTM: item.asset.operatingMarginTTM !== undefined ? item.asset.operatingMarginTTM : undefined,
1888
+ returnOnAssetsTTM: item.asset.returnOnAssetsTTM !== undefined ? item.asset.returnOnAssetsTTM : undefined,
1889
+ returnOnEquityTTM: item.asset.returnOnEquityTTM !== undefined ? item.asset.returnOnEquityTTM : undefined,
1890
+ revenueTTM: item.asset.revenueTTM !== undefined ? item.asset.revenueTTM : undefined,
1891
+ grossProfitTTM: item.asset.grossProfitTTM !== undefined ? item.asset.grossProfitTTM : undefined,
1892
+ dilutedEPSTTM: item.asset.dilutedEPSTTM !== undefined ? item.asset.dilutedEPSTTM : undefined,
1893
+ quarterlyEarningsGrowthYOY: item.asset.quarterlyEarningsGrowthYOY !== undefined ? item.asset.quarterlyEarningsGrowthYOY : undefined,
1894
+ quarterlyRevenueGrowthYOY: item.asset.quarterlyRevenueGrowthYOY !== undefined ? item.asset.quarterlyRevenueGrowthYOY : undefined,
1895
+ analystTargetPrice: item.asset.analystTargetPrice !== undefined ? item.asset.analystTargetPrice : undefined,
1896
+ analystRatingStrongBuy: item.asset.analystRatingStrongBuy !== undefined ? item.asset.analystRatingStrongBuy : undefined,
1897
+ analystRatingBuy: item.asset.analystRatingBuy !== undefined ? item.asset.analystRatingBuy : undefined,
1898
+ analystRatingHold: item.asset.analystRatingHold !== undefined ? item.asset.analystRatingHold : undefined,
1899
+ analystRatingSell: item.asset.analystRatingSell !== undefined ? item.asset.analystRatingSell : undefined,
1900
+ analystRatingStrongSell: item.asset.analystRatingStrongSell !== undefined ? item.asset.analystRatingStrongSell : undefined,
1901
+ trailingPE: item.asset.trailingPE !== undefined ? item.asset.trailingPE : undefined,
1902
+ forwardPE: item.asset.forwardPE !== undefined ? item.asset.forwardPE : undefined,
1903
+ priceToSalesRatioTTM: item.asset.priceToSalesRatioTTM !== undefined ? item.asset.priceToSalesRatioTTM : undefined,
1904
+ priceToBookRatio: item.asset.priceToBookRatio !== undefined ? item.asset.priceToBookRatio : undefined,
1905
+ evToRevenue: item.asset.evToRevenue !== undefined ? item.asset.evToRevenue : undefined,
1906
+ evToEbitda: item.asset.evToEbitda !== undefined ? item.asset.evToEbitda : undefined,
1907
+ beta: item.asset.beta !== undefined ? item.asset.beta : undefined,
1908
+ week52High: item.asset.week52High !== undefined ? item.asset.week52High : undefined,
1909
+ week52Low: item.asset.week52Low !== undefined ? item.asset.week52Low : undefined,
1910
+ day50MovingAverage: item.asset.day50MovingAverage !== undefined ? item.asset.day50MovingAverage : undefined,
1911
+ day200MovingAverage: item.asset.day200MovingAverage !== undefined ? item.asset.day200MovingAverage : undefined,
1912
+ sharesOutstanding: item.asset.sharesOutstanding !== undefined ? item.asset.sharesOutstanding : undefined,
1913
+ dividendDate: item.asset.dividendDate !== undefined ? item.asset.dividendDate : undefined,
1914
+ exDividendDate: item.asset.exDividendDate !== undefined ? item.asset.exDividendDate : undefined,
1915
+ askPrice: item.asset.askPrice !== undefined ? item.asset.askPrice : undefined,
1916
+ bidPrice: item.asset.bidPrice !== undefined ? item.asset.bidPrice : undefined,
1917
+ },
1918
+ }
1919
+ } : undefined,
1920
+ },
1921
+ create: {
1922
+ url: item.url !== undefined ? item.url : undefined,
1923
+ relevancyScore: item.relevancyScore !== undefined ? item.relevancyScore : undefined,
1924
+ sentimentScore: item.sentimentScore !== undefined ? item.sentimentScore : undefined,
1925
+ sentimentLabel: item.sentimentLabel !== undefined ? item.sentimentLabel : undefined,
1926
+ asset: item.asset ?
1927
+ typeof item.asset === 'object' && Object.keys(item.asset).length === 1 && Object.keys(item.asset)[0] === 'id'
1928
+ ? { connect: {
1929
+ id: item.asset.id
1930
+ }
1931
+ }
1932
+ : { connectOrCreate: {
1933
+ where: {
1934
+ id: item.asset.id !== undefined ? item.asset.id : undefined,
1935
+ symbol: item.asset.symbol !== undefined ? item.asset.symbol : undefined,
1936
+ name: item.asset.name !== undefined ? item.asset.name : undefined,
1937
+ },
1938
+ create: {
1939
+ symbol: item.asset.symbol !== undefined ? item.asset.symbol : undefined,
1940
+ name: item.asset.name !== undefined ? item.asset.name : undefined,
1941
+ type: item.asset.type !== undefined ? item.asset.type : undefined,
1942
+ logoUrl: item.asset.logoUrl !== undefined ? item.asset.logoUrl : undefined,
1943
+ description: item.asset.description !== undefined ? item.asset.description : undefined,
1944
+ cik: item.asset.cik !== undefined ? item.asset.cik : undefined,
1945
+ exchange: item.asset.exchange !== undefined ? item.asset.exchange : undefined,
1946
+ currency: item.asset.currency !== undefined ? item.asset.currency : undefined,
1947
+ country: item.asset.country !== undefined ? item.asset.country : undefined,
1948
+ sector: item.asset.sector !== undefined ? item.asset.sector : undefined,
1949
+ industry: item.asset.industry !== undefined ? item.asset.industry : undefined,
1950
+ address: item.asset.address !== undefined ? item.asset.address : undefined,
1951
+ officialSite: item.asset.officialSite !== undefined ? item.asset.officialSite : undefined,
1952
+ fiscalYearEnd: item.asset.fiscalYearEnd !== undefined ? item.asset.fiscalYearEnd : undefined,
1953
+ latestQuarter: item.asset.latestQuarter !== undefined ? item.asset.latestQuarter : undefined,
1954
+ marketCapitalization: item.asset.marketCapitalization !== undefined ? item.asset.marketCapitalization : undefined,
1955
+ ebitda: item.asset.ebitda !== undefined ? item.asset.ebitda : undefined,
1956
+ peRatio: item.asset.peRatio !== undefined ? item.asset.peRatio : undefined,
1957
+ pegRatio: item.asset.pegRatio !== undefined ? item.asset.pegRatio : undefined,
1958
+ bookValue: item.asset.bookValue !== undefined ? item.asset.bookValue : undefined,
1959
+ dividendPerShare: item.asset.dividendPerShare !== undefined ? item.asset.dividendPerShare : undefined,
1960
+ dividendYield: item.asset.dividendYield !== undefined ? item.asset.dividendYield : undefined,
1961
+ eps: item.asset.eps !== undefined ? item.asset.eps : undefined,
1962
+ revenuePerShareTTM: item.asset.revenuePerShareTTM !== undefined ? item.asset.revenuePerShareTTM : undefined,
1963
+ profitMargin: item.asset.profitMargin !== undefined ? item.asset.profitMargin : undefined,
1964
+ operatingMarginTTM: item.asset.operatingMarginTTM !== undefined ? item.asset.operatingMarginTTM : undefined,
1965
+ returnOnAssetsTTM: item.asset.returnOnAssetsTTM !== undefined ? item.asset.returnOnAssetsTTM : undefined,
1966
+ returnOnEquityTTM: item.asset.returnOnEquityTTM !== undefined ? item.asset.returnOnEquityTTM : undefined,
1967
+ revenueTTM: item.asset.revenueTTM !== undefined ? item.asset.revenueTTM : undefined,
1968
+ grossProfitTTM: item.asset.grossProfitTTM !== undefined ? item.asset.grossProfitTTM : undefined,
1969
+ dilutedEPSTTM: item.asset.dilutedEPSTTM !== undefined ? item.asset.dilutedEPSTTM : undefined,
1970
+ quarterlyEarningsGrowthYOY: item.asset.quarterlyEarningsGrowthYOY !== undefined ? item.asset.quarterlyEarningsGrowthYOY : undefined,
1971
+ quarterlyRevenueGrowthYOY: item.asset.quarterlyRevenueGrowthYOY !== undefined ? item.asset.quarterlyRevenueGrowthYOY : undefined,
1972
+ analystTargetPrice: item.asset.analystTargetPrice !== undefined ? item.asset.analystTargetPrice : undefined,
1973
+ analystRatingStrongBuy: item.asset.analystRatingStrongBuy !== undefined ? item.asset.analystRatingStrongBuy : undefined,
1974
+ analystRatingBuy: item.asset.analystRatingBuy !== undefined ? item.asset.analystRatingBuy : undefined,
1975
+ analystRatingHold: item.asset.analystRatingHold !== undefined ? item.asset.analystRatingHold : undefined,
1976
+ analystRatingSell: item.asset.analystRatingSell !== undefined ? item.asset.analystRatingSell : undefined,
1977
+ analystRatingStrongSell: item.asset.analystRatingStrongSell !== undefined ? item.asset.analystRatingStrongSell : undefined,
1978
+ trailingPE: item.asset.trailingPE !== undefined ? item.asset.trailingPE : undefined,
1979
+ forwardPE: item.asset.forwardPE !== undefined ? item.asset.forwardPE : undefined,
1980
+ priceToSalesRatioTTM: item.asset.priceToSalesRatioTTM !== undefined ? item.asset.priceToSalesRatioTTM : undefined,
1981
+ priceToBookRatio: item.asset.priceToBookRatio !== undefined ? item.asset.priceToBookRatio : undefined,
1982
+ evToRevenue: item.asset.evToRevenue !== undefined ? item.asset.evToRevenue : undefined,
1983
+ evToEbitda: item.asset.evToEbitda !== undefined ? item.asset.evToEbitda : undefined,
1984
+ beta: item.asset.beta !== undefined ? item.asset.beta : undefined,
1985
+ week52High: item.asset.week52High !== undefined ? item.asset.week52High : undefined,
1986
+ week52Low: item.asset.week52Low !== undefined ? item.asset.week52Low : undefined,
1987
+ day50MovingAverage: item.asset.day50MovingAverage !== undefined ? item.asset.day50MovingAverage : undefined,
1988
+ day200MovingAverage: item.asset.day200MovingAverage !== undefined ? item.asset.day200MovingAverage : undefined,
1989
+ sharesOutstanding: item.asset.sharesOutstanding !== undefined ? item.asset.sharesOutstanding : undefined,
1990
+ dividendDate: item.asset.dividendDate !== undefined ? item.asset.dividendDate : undefined,
1991
+ exDividendDate: item.asset.exDividendDate !== undefined ? item.asset.exDividendDate : undefined,
1992
+ askPrice: item.asset.askPrice !== undefined ? item.asset.askPrice : undefined,
1993
+ bidPrice: item.asset.bidPrice !== undefined ? item.asset.bidPrice : undefined,
1994
+ },
1995
+ }
1996
+ } : undefined,
1997
+ },
1998
+ }))
1999
+ } : undefined,
2000
+ },
2001
+ }));
2002
+ const filteredVariables = removeUndefinedProps(variables);
2003
+ const response = await client.mutate({
2004
+ mutation: UPDATE_MANY_NEWSARTICLE,
2005
+ variables: filteredVariables,
2006
+ // Don't cache mutations, but ensure we're using the freshest context
2007
+ fetchPolicy: 'no-cache'
2008
+ });
2009
+ if (response.errors && response.errors.length > 0)
2010
+ throw new Error(response.errors[0].message);
2011
+ if (response && response.data && response.data.updateManyNewsArticle) {
2012
+ return response.data.updateManyNewsArticle;
2013
+ }
2014
+ else {
2015
+ return null;
2016
+ }
1764
2017
  }
1765
- else {
1766
- return null;
2018
+ catch (error) {
2019
+ lastError = error;
2020
+ // Check if this is a database connection error that we should retry
2021
+ const isConnectionError = error.message?.includes('Server has closed the connection') ||
2022
+ error.message?.includes('Cannot reach database server') ||
2023
+ error.message?.includes('Connection timed out') ||
2024
+ error.message?.includes('Accelerate') || // Prisma Accelerate proxy errors
2025
+ (error.networkError && error.networkError.message?.includes('Failed to fetch'));
2026
+ if (isConnectionError && retryCount < MAX_RETRIES - 1) {
2027
+ retryCount++;
2028
+ const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
2029
+ console.warn("Database connection error, retrying...");
2030
+ await new Promise(resolve => setTimeout(resolve, delay));
2031
+ continue;
2032
+ }
2033
+ // Log the error and rethrow
2034
+ console.error("Database error occurred:", error);
2035
+ throw error;
1767
2036
  }
1768
2037
  }
1769
- catch (error) {
1770
- console.error('Error in updateManyNewsArticle:', error);
1771
- throw error;
1772
- }
2038
+ // If we exhausted retries, throw the last error
2039
+ throw lastError;
1773
2040
  },
1774
2041
  /**
1775
2042
  * Delete a single NewsArticle record.
1776
- * @param props - Properties to update.
2043
+ * Enhanced with connection resilience against Prisma connection errors.
2044
+ * @param props - Properties to identify the record to delete.
1777
2045
  * @param globalClient - Apollo Client instance.
1778
2046
  * @returns The deleted NewsArticle or null.
1779
2047
  */
1780
2048
  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,
2049
+ // Maximum number of retries for database connection issues
2050
+ const MAX_RETRIES = 3;
2051
+ let retryCount = 0;
2052
+ let lastError = null;
2053
+ // Retry loop to handle potential database connection issues
2054
+ while (retryCount < MAX_RETRIES) {
2055
+ try {
2056
+ const [modules, client] = await Promise.all([
2057
+ getApolloModules(),
2058
+ globalClient
2059
+ ? Promise.resolve(globalClient)
2060
+ : importedClient
2061
+ ]);
2062
+ const { gql, ApolloError } = modules;
2063
+ const DELETE_ONE_NEWSARTICLE = gql `
2064
+ mutation deleteOneNewsArticle($where: NewsArticleWhereUniqueInput!) {
2065
+ deleteOneNewsArticle(where: $where) {
2066
+ id
1797
2067
  }
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;
2068
+ }`;
2069
+ const variables = {
2070
+ where: {
2071
+ id: props.id ? props.id : undefined,
2072
+ }
2073
+ };
2074
+ const filteredVariables = removeUndefinedProps(variables);
2075
+ const response = await client.mutate({
2076
+ mutation: DELETE_ONE_NEWSARTICLE,
2077
+ variables: filteredVariables,
2078
+ // Don't cache mutations, but ensure we're using the freshest context
2079
+ fetchPolicy: 'no-cache'
2080
+ });
2081
+ if (response.errors && response.errors.length > 0)
2082
+ throw new Error(response.errors[0].message);
2083
+ if (response && response.data && response.data.deleteOneNewsArticle) {
2084
+ return response.data.deleteOneNewsArticle;
2085
+ }
2086
+ else {
2087
+ return null;
2088
+ }
1806
2089
  }
1807
- else {
1808
- return null;
2090
+ catch (error) {
2091
+ lastError = error;
2092
+ // Check if this is a database connection error that we should retry
2093
+ const isConnectionError = error.message?.includes('Server has closed the connection') ||
2094
+ error.message?.includes('Cannot reach database server') ||
2095
+ error.message?.includes('Connection timed out') ||
2096
+ error.message?.includes('Accelerate') || // Prisma Accelerate proxy errors
2097
+ (error.networkError && error.networkError.message?.includes('Failed to fetch'));
2098
+ if (isConnectionError && retryCount < MAX_RETRIES - 1) {
2099
+ retryCount++;
2100
+ const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
2101
+ console.warn("Database connection error, retrying...");
2102
+ await new Promise(resolve => setTimeout(resolve, delay));
2103
+ continue;
2104
+ }
2105
+ // Log the error and rethrow
2106
+ console.error("Database error occurred:", error);
2107
+ throw error;
1809
2108
  }
1810
2109
  }
1811
- catch (error) {
1812
- console.error('Error in deleteOneNewsArticle:', error);
1813
- throw error;
1814
- }
2110
+ // If we exhausted retries, throw the last error
2111
+ throw lastError;
1815
2112
  },
1816
2113
  /**
1817
2114
  * Retrieve a single NewsArticle record by ID.
1818
- * @param props - Properties to update.
2115
+ * Enhanced with connection resilience against Prisma connection errors.
2116
+ * @param props - Properties to identify the record.
1819
2117
  * @param globalClient - Apollo Client instance.
2118
+ * @param whereInput - Optional custom where input.
1820
2119
  * @returns The retrieved NewsArticle or null.
1821
2120
  */
1822
2121
  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;
2122
+ // Maximum number of retries for database connection issues
2123
+ const MAX_RETRIES = 3;
2124
+ let retryCount = 0;
2125
+ let lastError = null;
2126
+ // Retry loop to handle potential database connection issues
2127
+ while (retryCount < MAX_RETRIES) {
2128
+ try {
2129
+ const [modules, client] = await Promise.all([
2130
+ getApolloModules(),
2131
+ globalClient
2132
+ ? Promise.resolve(globalClient)
2133
+ : importedClient
2134
+ ]);
2135
+ const { gql, ApolloError } = modules;
2136
+ const GET_NEWSARTICLE = gql `
2137
+ query getNewsArticle($where: NewsArticleWhereUniqueInput!) {
2138
+ getNewsArticle(where: $where) {
2139
+ ${selectionSet}
2140
+ }
2141
+ }`;
2142
+ const variables = {
2143
+ where: whereInput ? whereInput : {
2144
+ id: props.id !== undefined ? props.id : undefined,
2145
+ url: props.url !== undefined ? props.url : undefined,
2146
+ title: props.title !== undefined ? props.title : undefined,
2147
+ content: props.content !== undefined ? {
2148
+ equals: props.content
2149
+ } : undefined,
2150
+ source: props.source !== undefined ? {
2151
+ equals: props.source
2152
+ } : undefined,
2153
+ sourceDomain: props.sourceDomain !== undefined ? {
2154
+ equals: props.sourceDomain
2155
+ } : undefined,
2156
+ sentiment: props.sentiment !== undefined ? {
2157
+ equals: props.sentiment
2158
+ } : undefined,
2159
+ authors: props.authors !== undefined ? {
2160
+ equals: props.authors
2161
+ } : undefined,
2162
+ summary: props.summary !== undefined ? {
2163
+ equals: props.summary
2164
+ } : undefined,
2165
+ bannerImage: props.bannerImage !== undefined ? {
2166
+ equals: props.bannerImage
2167
+ } : undefined,
2168
+ timePublished: props.timePublished !== undefined ? {
2169
+ equals: props.timePublished
2170
+ } : undefined,
2171
+ category: props.category !== undefined ? {
2172
+ equals: props.category
2173
+ } : undefined,
2174
+ topics: props.topics !== undefined ? {
2175
+ equals: props.topics
2176
+ } : undefined,
2177
+ logo: props.logo !== undefined ? {
2178
+ equals: props.logo
2179
+ } : undefined,
2180
+ createdAt: props.createdAt !== undefined ? {
2181
+ equals: props.createdAt
2182
+ } : undefined,
2183
+ updatedAt: props.updatedAt !== undefined ? {
2184
+ equals: props.updatedAt
2185
+ } : undefined,
2186
+ },
2187
+ };
2188
+ const filteredVariables = removeUndefinedProps(variables);
2189
+ const response = await client.query({
2190
+ query: GET_NEWSARTICLE,
2191
+ variables: filteredVariables,
2192
+ fetchPolicy: 'network-only', // Force network request to avoid stale cache
2193
+ });
2194
+ if (response.errors && response.errors.length > 0)
2195
+ throw new Error(response.errors[0].message);
2196
+ return response.data?.getNewsArticle ?? null;
1855
2197
  }
1856
- else {
1857
- console.error('Error in getNewsArticle:', error);
2198
+ catch (error) {
2199
+ lastError = error;
2200
+ // Check if this is a "No record found" error - this is an expected condition, not a failure
2201
+ if (error.message === 'No NewsArticle found') {
2202
+ return null;
2203
+ }
2204
+ // Check if this is a database connection error that we should retry
2205
+ const isConnectionError = error.message?.includes('Server has closed the connection') ||
2206
+ error.message?.includes('Cannot reach database server') ||
2207
+ error.message?.includes('Connection timed out') ||
2208
+ error.message?.includes('Accelerate') || // Prisma Accelerate proxy errors
2209
+ (error.networkError && error.networkError.message?.includes('Failed to fetch'));
2210
+ if (isConnectionError && retryCount < MAX_RETRIES - 1) {
2211
+ retryCount++;
2212
+ const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
2213
+ console.warn("Database connection error, retrying...");
2214
+ await new Promise(resolve => setTimeout(resolve, delay));
2215
+ continue;
2216
+ }
2217
+ // Log the error and rethrow
2218
+ console.error("Database error occurred:", error);
1858
2219
  throw error;
1859
2220
  }
1860
2221
  }
2222
+ // If we exhausted retries, throw the last error
2223
+ throw lastError;
1861
2224
  },
1862
2225
  /**
1863
2226
  * Retrieve all NewsArticles records.
2227
+ * Enhanced with connection resilience against Prisma connection errors.
1864
2228
  * @param globalClient - Apollo Client instance.
1865
2229
  * @returns An array of NewsArticle records or null.
1866
2230
  */
1867
2231
  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;
2232
+ // Maximum number of retries for database connection issues
2233
+ const MAX_RETRIES = 3;
2234
+ let retryCount = 0;
2235
+ let lastError = null;
2236
+ // Retry loop to handle potential database connection issues
2237
+ while (retryCount < MAX_RETRIES) {
2238
+ try {
2239
+ const [modules, client] = await Promise.all([
2240
+ getApolloModules(),
2241
+ globalClient
2242
+ ? Promise.resolve(globalClient)
2243
+ : importedClient
2244
+ ]);
2245
+ const { gql, ApolloError } = modules;
2246
+ const GET_ALL_NEWSARTICLE = gql `
2247
+ query getAllNewsArticle {
2248
+ newsArticles {
2249
+ ${selectionSet}
1890
2250
  }
1891
- else {
1892
- console.error('Error in getNewsArticle:', error);
2251
+ }`;
2252
+ const response = await client.query({
2253
+ query: GET_ALL_NEWSARTICLE,
2254
+ fetchPolicy: 'network-only', // Force network request to avoid stale cache
2255
+ });
2256
+ if (response.errors && response.errors.length > 0)
2257
+ throw new Error(response.errors[0].message);
2258
+ return response.data?.newsArticles ?? null;
2259
+ }
2260
+ catch (error) {
2261
+ lastError = error;
2262
+ // Check if this is a "No record found" error - this is an expected condition, not a failure
2263
+ if (error.message === 'No NewsArticle found') {
2264
+ return null;
2265
+ }
2266
+ // Check if this is a database connection error that we should retry
2267
+ const isConnectionError = error.message?.includes('Server has closed the connection') ||
2268
+ error.message?.includes('Cannot reach database server') ||
2269
+ error.message?.includes('Connection timed out') ||
2270
+ error.message?.includes('Accelerate') || // Prisma Accelerate proxy errors
2271
+ (error.networkError && error.networkError.message?.includes('Failed to fetch'));
2272
+ if (isConnectionError && retryCount < MAX_RETRIES - 1) {
2273
+ retryCount++;
2274
+ const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
2275
+ console.warn("Database connection error, retrying...");
2276
+ await new Promise(resolve => setTimeout(resolve, delay));
2277
+ continue;
2278
+ }
2279
+ // Log the error and rethrow
2280
+ console.error("Database error occurred:", error);
1893
2281
  throw error;
1894
2282
  }
1895
2283
  }
2284
+ // If we exhausted retries, throw the last error
2285
+ throw lastError;
1896
2286
  },
1897
2287
  /**
1898
2288
  * Find multiple NewsArticle records based on conditions.
2289
+ * Enhanced with connection resilience against Prisma connection errors.
1899
2290
  * @param props - Conditions to find records.
1900
2291
  * @param globalClient - Apollo Client instance.
2292
+ * @param whereInput - Optional custom where input.
1901
2293
  * @returns An array of found NewsArticle records or null.
1902
2294
  */
1903
2295
  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;
2296
+ // Maximum number of retries for database connection issues
2297
+ const MAX_RETRIES = 3;
2298
+ let retryCount = 0;
2299
+ let lastError = null;
2300
+ // Retry loop to handle potential database connection issues
2301
+ while (retryCount < MAX_RETRIES) {
2302
+ try {
2303
+ const [modules, client] = await Promise.all([
2304
+ getApolloModules(),
2305
+ globalClient
2306
+ ? Promise.resolve(globalClient)
2307
+ : importedClient
2308
+ ]);
2309
+ const { gql, ApolloError } = modules;
2310
+ const FIND_MANY_NEWSARTICLE = gql `
2311
+ query findManyNewsArticle($where: NewsArticleWhereInput!) {
2312
+ newsArticles(where: $where) {
2313
+ ${selectionSet}
1937
2314
  }
1938
- else {
1939
- return [];
1940
- }
1941
- }
1942
- catch (error) {
1943
- if (error instanceof ApolloError && error.message === 'No NewsArticle found') {
1944
- return null;
2315
+ }`;
2316
+ const variables = {
2317
+ where: whereInput ? whereInput : {
2318
+ id: props.id !== undefined ? props.id : undefined,
2319
+ title: props.title !== undefined ? props.title : undefined,
2320
+ content: props.content !== undefined ? {
2321
+ equals: props.content
2322
+ } : undefined,
2323
+ source: props.source !== undefined ? {
2324
+ equals: props.source
2325
+ } : undefined,
2326
+ sourceDomain: props.sourceDomain !== undefined ? {
2327
+ equals: props.sourceDomain
2328
+ } : undefined,
2329
+ url: props.url !== undefined ? props.url : undefined,
2330
+ sentiment: props.sentiment !== undefined ? {
2331
+ equals: props.sentiment
2332
+ } : undefined,
2333
+ authors: props.authors !== undefined ? {
2334
+ equals: props.authors
2335
+ } : undefined,
2336
+ summary: props.summary !== undefined ? {
2337
+ equals: props.summary
2338
+ } : undefined,
2339
+ bannerImage: props.bannerImage !== undefined ? {
2340
+ equals: props.bannerImage
2341
+ } : undefined,
2342
+ timePublished: props.timePublished !== undefined ? {
2343
+ equals: props.timePublished
2344
+ } : undefined,
2345
+ category: props.category !== undefined ? {
2346
+ equals: props.category
2347
+ } : undefined,
2348
+ topics: props.topics !== undefined ? {
2349
+ equals: props.topics
2350
+ } : undefined,
2351
+ logo: props.logo !== undefined ? {
2352
+ equals: props.logo
2353
+ } : undefined,
2354
+ createdAt: props.createdAt !== undefined ? {
2355
+ equals: props.createdAt
2356
+ } : undefined,
2357
+ updatedAt: props.updatedAt !== undefined ? {
2358
+ equals: props.updatedAt
2359
+ } : undefined,
2360
+ },
2361
+ };
2362
+ const filteredVariables = removeUndefinedProps(variables);
2363
+ const response = await client.query({
2364
+ query: FIND_MANY_NEWSARTICLE,
2365
+ variables: filteredVariables,
2366
+ fetchPolicy: 'network-only', // Force network request to avoid stale cache
2367
+ });
2368
+ if (response.errors && response.errors.length > 0)
2369
+ throw new Error(response.errors[0].message);
2370
+ if (response && response.data && response.data.newsarticles) {
2371
+ return response.data.newsArticles;
2372
+ }
2373
+ else {
2374
+ return [];
2375
+ }
1945
2376
  }
1946
- else {
1947
- console.error('Error in getNewsArticle:', error);
2377
+ catch (error) {
2378
+ lastError = error;
2379
+ // Check if this is a "No record found" error - this is an expected condition, not a failure
2380
+ if (error.message === 'No NewsArticle found') {
2381
+ return null;
2382
+ }
2383
+ // Check if this is a database connection error that we should retry
2384
+ const isConnectionError = error.message?.includes('Server has closed the connection') ||
2385
+ error.message?.includes('Cannot reach database server') ||
2386
+ error.message?.includes('Connection timed out') ||
2387
+ error.message?.includes('Accelerate') || // Prisma Accelerate proxy errors
2388
+ (error.networkError && error.networkError.message?.includes('Failed to fetch'));
2389
+ if (isConnectionError && retryCount < MAX_RETRIES - 1) {
2390
+ retryCount++;
2391
+ const delay = Math.pow(2, retryCount) * 100; // Exponential backoff: 200ms, 400ms, 800ms
2392
+ console.warn("Database connection error, retrying...");
2393
+ await new Promise(resolve => setTimeout(resolve, delay));
2394
+ continue;
2395
+ }
2396
+ // Log the error and rethrow
2397
+ console.error("Database error occurred:", error);
1948
2398
  throw error;
1949
2399
  }
1950
2400
  }
2401
+ // If we exhausted retries, throw the last error
2402
+ throw lastError;
1951
2403
  }
1952
2404
  };
1953
2405
  //# sourceMappingURL=NewsArticle.js.map