@oanda/labs-instruments-price-chart-widget 1.0.1

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 (150) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/codegen.ts +18 -0
  3. package/dist/main/InstrumentsPriceChartWidget/InstrumentsPriceChartWidget.js +40 -0
  4. package/dist/main/InstrumentsPriceChartWidget/InstrumentsPriceChartWidget.js.map +1 -0
  5. package/dist/main/InstrumentsPriceChartWidget/Main.js +52 -0
  6. package/dist/main/InstrumentsPriceChartWidget/Main.js.map +1 -0
  7. package/dist/main/InstrumentsPriceChartWidget/components/Chart.js +39 -0
  8. package/dist/main/InstrumentsPriceChartWidget/components/Chart.js.map +1 -0
  9. package/dist/main/InstrumentsPriceChartWidget/components/constants.js +12 -0
  10. package/dist/main/InstrumentsPriceChartWidget/components/constants.js.map +1 -0
  11. package/dist/main/InstrumentsPriceChartWidget/components/formatters.js +15 -0
  12. package/dist/main/InstrumentsPriceChartWidget/components/formatters.js.map +1 -0
  13. package/dist/main/InstrumentsPriceChartWidget/components/getOption.js +119 -0
  14. package/dist/main/InstrumentsPriceChartWidget/components/getOption.js.map +1 -0
  15. package/dist/main/InstrumentsPriceChartWidget/components/types.js +6 -0
  16. package/dist/main/InstrumentsPriceChartWidget/components/types.js.map +1 -0
  17. package/dist/main/InstrumentsPriceChartWidget/config.js +44 -0
  18. package/dist/main/InstrumentsPriceChartWidget/config.js.map +1 -0
  19. package/dist/main/InstrumentsPriceChartWidget/index.js +28 -0
  20. package/dist/main/InstrumentsPriceChartWidget/index.js.map +1 -0
  21. package/dist/main/InstrumentsPriceChartWidget/render.js +42 -0
  22. package/dist/main/InstrumentsPriceChartWidget/render.js.map +1 -0
  23. package/dist/main/InstrumentsPriceChartWidget/types.js +16 -0
  24. package/dist/main/InstrumentsPriceChartWidget/types.js.map +1 -0
  25. package/dist/main/gql/mock/getPriceCandles.js +30 -0
  26. package/dist/main/gql/mock/getPriceCandles.js.map +1 -0
  27. package/dist/main/gql/mock/handlers.js +62 -0
  28. package/dist/main/gql/mock/handlers.js.map +1 -0
  29. package/dist/main/gql/mock/schema.graphqls +59 -0
  30. package/dist/main/gql/types/fragment-masking.js +23 -0
  31. package/dist/main/gql/types/fragment-masking.js.map +1 -0
  32. package/dist/main/gql/types/gql.js +17 -0
  33. package/dist/main/gql/types/gql.js.map +1 -0
  34. package/dist/main/gql/types/graphql.js +438 -0
  35. package/dist/main/gql/types/graphql.js.map +1 -0
  36. package/dist/main/gql/types/index.js +28 -0
  37. package/dist/main/gql/types/index.js.map +1 -0
  38. package/dist/main/gql/validateInstruments.js +16 -0
  39. package/dist/main/gql/validateInstruments.js.map +1 -0
  40. package/dist/main/index.js +17 -0
  41. package/dist/main/index.js.map +1 -0
  42. package/dist/main/translations/index.js +27 -0
  43. package/dist/main/translations/index.js.map +1 -0
  44. package/dist/main/translations/sources/en.json +2 -0
  45. package/dist/main/translations/sources/es.json +2 -0
  46. package/dist/main/translations/sources/th.json +2 -0
  47. package/dist/main/translations/sources/zh_TW.json +2 -0
  48. package/dist/main/translations/translations.js +8 -0
  49. package/dist/main/translations/translations.js.map +1 -0
  50. package/dist/module/InstrumentsPriceChartWidget/InstrumentsPriceChartWidget.js +33 -0
  51. package/dist/module/InstrumentsPriceChartWidget/InstrumentsPriceChartWidget.js.map +1 -0
  52. package/dist/module/InstrumentsPriceChartWidget/Main.js +44 -0
  53. package/dist/module/InstrumentsPriceChartWidget/Main.js.map +1 -0
  54. package/dist/module/InstrumentsPriceChartWidget/components/Chart.js +29 -0
  55. package/dist/module/InstrumentsPriceChartWidget/components/Chart.js.map +1 -0
  56. package/dist/module/InstrumentsPriceChartWidget/components/constants.js +6 -0
  57. package/dist/module/InstrumentsPriceChartWidget/components/constants.js.map +1 -0
  58. package/dist/module/InstrumentsPriceChartWidget/components/formatters.js +8 -0
  59. package/dist/module/InstrumentsPriceChartWidget/components/formatters.js.map +1 -0
  60. package/dist/module/InstrumentsPriceChartWidget/components/getOption.js +112 -0
  61. package/dist/module/InstrumentsPriceChartWidget/components/getOption.js.map +1 -0
  62. package/dist/module/InstrumentsPriceChartWidget/components/types.js +2 -0
  63. package/dist/module/InstrumentsPriceChartWidget/components/types.js.map +1 -0
  64. package/dist/module/InstrumentsPriceChartWidget/config.js +39 -0
  65. package/dist/module/InstrumentsPriceChartWidget/config.js.map +1 -0
  66. package/dist/module/InstrumentsPriceChartWidget/index.js +3 -0
  67. package/dist/module/InstrumentsPriceChartWidget/index.js.map +1 -0
  68. package/dist/module/InstrumentsPriceChartWidget/render.js +39 -0
  69. package/dist/module/InstrumentsPriceChartWidget/render.js.map +1 -0
  70. package/dist/module/InstrumentsPriceChartWidget/types.js +10 -0
  71. package/dist/module/InstrumentsPriceChartWidget/types.js.map +1 -0
  72. package/dist/module/gql/mock/getPriceCandles.js +25 -0
  73. package/dist/module/gql/mock/getPriceCandles.js.map +1 -0
  74. package/dist/module/gql/mock/handlers.js +56 -0
  75. package/dist/module/gql/mock/handlers.js.map +1 -0
  76. package/dist/module/gql/mock/schema.graphqls +59 -0
  77. package/dist/module/gql/types/fragment-masking.js +15 -0
  78. package/dist/module/gql/types/fragment-masking.js.map +1 -0
  79. package/dist/module/gql/types/gql.js +9 -0
  80. package/dist/module/gql/types/gql.js.map +1 -0
  81. package/dist/module/gql/types/graphql.js +432 -0
  82. package/dist/module/gql/types/graphql.js.map +1 -0
  83. package/dist/module/gql/types/index.js +3 -0
  84. package/dist/module/gql/types/index.js.map +1 -0
  85. package/dist/module/gql/validateInstruments.js +10 -0
  86. package/dist/module/gql/validateInstruments.js.map +1 -0
  87. package/dist/module/index.js +2 -0
  88. package/dist/module/index.js.map +1 -0
  89. package/dist/module/translations/index.js +20 -0
  90. package/dist/module/translations/index.js.map +1 -0
  91. package/dist/module/translations/sources/en.json +2 -0
  92. package/dist/module/translations/sources/es.json +2 -0
  93. package/dist/module/translations/sources/th.json +2 -0
  94. package/dist/module/translations/sources/zh_TW.json +2 -0
  95. package/dist/module/translations/translations.js +2 -0
  96. package/dist/module/translations/translations.js.map +1 -0
  97. package/dist/types/InstrumentsPriceChartWidget/InstrumentsPriceChartWidget.d.ts +4 -0
  98. package/dist/types/InstrumentsPriceChartWidget/Main.d.ts +4 -0
  99. package/dist/types/InstrumentsPriceChartWidget/components/Chart.d.ts +3 -0
  100. package/dist/types/InstrumentsPriceChartWidget/components/constants.d.ts +5 -0
  101. package/dist/types/InstrumentsPriceChartWidget/components/formatters.d.ts +1 -0
  102. package/dist/types/InstrumentsPriceChartWidget/components/getOption.d.ts +2 -0
  103. package/dist/types/InstrumentsPriceChartWidget/components/types.d.ts +14 -0
  104. package/dist/types/InstrumentsPriceChartWidget/config.d.ts +10 -0
  105. package/dist/types/InstrumentsPriceChartWidget/index.d.ts +2 -0
  106. package/dist/types/InstrumentsPriceChartWidget/render.d.ts +1 -0
  107. package/dist/types/InstrumentsPriceChartWidget/types.d.ts +15 -0
  108. package/dist/types/gql/mock/getPriceCandles.d.ts +2 -0
  109. package/dist/types/gql/mock/handlers.d.ts +1 -0
  110. package/dist/types/gql/types/fragment-masking.d.ts +15 -0
  111. package/dist/types/gql/types/gql.d.ts +47 -0
  112. package/dist/types/gql/types/graphql.d.ts +468 -0
  113. package/dist/types/gql/types/index.d.ts +2 -0
  114. package/dist/types/gql/validateInstruments.d.ts +1 -0
  115. package/dist/types/index.d.ts +1 -0
  116. package/dist/types/translations/index.d.ts +4 -0
  117. package/dist/types/translations/translations.d.ts +1 -0
  118. package/index.ts +1 -0
  119. package/lokalise.config.json +18 -0
  120. package/package.json +24 -0
  121. package/src/InstrumentsPriceChartWidget/InstrumentsPriceChartWidget.tsx +40 -0
  122. package/src/InstrumentsPriceChartWidget/Main.tsx +59 -0
  123. package/src/InstrumentsPriceChartWidget/components/Chart.tsx +47 -0
  124. package/src/InstrumentsPriceChartWidget/components/constants.ts +5 -0
  125. package/src/InstrumentsPriceChartWidget/components/formatters.ts +7 -0
  126. package/src/InstrumentsPriceChartWidget/components/getOption.ts +127 -0
  127. package/src/InstrumentsPriceChartWidget/components/types.ts +19 -0
  128. package/src/InstrumentsPriceChartWidget/config.ts +47 -0
  129. package/src/InstrumentsPriceChartWidget/index.ts +2 -0
  130. package/src/InstrumentsPriceChartWidget/render.tsx +52 -0
  131. package/src/InstrumentsPriceChartWidget/types.ts +20 -0
  132. package/src/gql/mock/getPriceCandles.ts +26 -0
  133. package/src/gql/mock/handlers.ts +66 -0
  134. package/src/gql/mock/schema.graphqls +59 -0
  135. package/src/gql/types/fragment-masking.ts +86 -0
  136. package/src/gql/types/gql.ts +54 -0
  137. package/src/gql/types/graphql.ts +723 -0
  138. package/src/gql/types/index.ts +2 -0
  139. package/src/gql/validateInstruments.ts +10 -0
  140. package/src/index.ts +1 -0
  141. package/src/translations/index.ts +17 -0
  142. package/src/translations/sources/en.json +2 -0
  143. package/src/translations/sources/es.json +2 -0
  144. package/src/translations/sources/th.json +2 -0
  145. package/src/translations/sources/zh_TW.json +2 -0
  146. package/src/translations/translations.ts +1 -0
  147. package/test/Main.test.tsx +26 -0
  148. package/test/mocks/chartMock.ts +52 -0
  149. package/test/mocks/index.ts +1 -0
  150. package/tsconfig.types.json +12 -0
@@ -0,0 +1,127 @@
1
+ import {
2
+ colorPalette,
3
+ getGridLines,
4
+ getLineCommons,
5
+ } from '@oanda/labs-widget-common';
6
+
7
+ import {
8
+ CHART_HEIGHT,
9
+ CHART_INTERVAL,
10
+ CHART_WIDTH,
11
+ X_LABEL_SIZE,
12
+ Y_LABEL_SIZE_DESKTOP,
13
+ } from './constants';
14
+ import { dailyFormatter } from './formatters';
15
+ import type { ChartValue, GetOptionType } from './types';
16
+
17
+ export const getOption: GetOptionType = ({ values, isDark }) => {
18
+ const priceValues = values.map((d) => d.candle.high);
19
+
20
+ const timestamps = values.map((d) => dailyFormatter(d.time));
21
+
22
+ const labelInterval = Math.max(1, Math.floor(timestamps.length / 6));
23
+
24
+ const gridLines = getGridLines({
25
+ isDark,
26
+ chartWidth: CHART_WIDTH,
27
+ chartHeight: CHART_HEIGHT,
28
+ xLabelsSize: X_LABEL_SIZE,
29
+ yLabelSize: Y_LABEL_SIZE_DESKTOP,
30
+ bottomLeftBox: false,
31
+ });
32
+
33
+ return {
34
+ xAxis: {
35
+ type: 'category',
36
+ boundaryGap: false,
37
+ data: timestamps,
38
+ axisTick: {
39
+ show: false,
40
+ },
41
+ axisLabel: {
42
+ margin: 10,
43
+ interval: (index: number) => index % labelInterval === 0,
44
+ formatter: (value: string, index: number) =>
45
+ index % labelInterval === 0 ? value : '',
46
+ },
47
+ splitLine: {
48
+ show: true,
49
+ interval: (index: number) => index % labelInterval === 0,
50
+ },
51
+ },
52
+ yAxis: {
53
+ type: 'value',
54
+ position: 'right',
55
+ min: (value: ChartValue) =>
56
+ Math.floor(value.min * 100) / 100 - CHART_INTERVAL,
57
+ max: (value: ChartValue) =>
58
+ Math.ceil(value.max * 100) / 100 + CHART_INTERVAL,
59
+ interval: CHART_INTERVAL,
60
+ axisLine: { show: false },
61
+ axisTick: { show: false },
62
+ axisLabel: {
63
+ margin: 8,
64
+ formatter: (value: number) => {
65
+ const dataMin = Math.floor(Math.min(...priceValues) * 100) / 100;
66
+ const dataMax = Math.ceil(Math.max(...priceValues) * 100) / 100;
67
+ if (value < dataMin || value > dataMax) {
68
+ return '';
69
+ }
70
+ return value.toFixed(2);
71
+ },
72
+ },
73
+ splitLine: {
74
+ show: true,
75
+ },
76
+ },
77
+ series: [
78
+ {
79
+ name: 'price-close',
80
+ type: 'line',
81
+ data: priceValues,
82
+ smooth: true,
83
+ symbol: 'none',
84
+ lineStyle: {
85
+ color: colorPalette.navyBlue,
86
+ width: 2,
87
+ },
88
+ areaStyle: {
89
+ color: {
90
+ type: 'linear',
91
+ x: 0,
92
+ y: 0,
93
+ x2: 0,
94
+ y2: 1,
95
+ colorStops: [
96
+ { offset: 0, color: colorPalette.brightBlue30 },
97
+ { offset: 1, color: colorPalette.brightBlue },
98
+ ],
99
+ },
100
+ },
101
+ },
102
+ ],
103
+ grid: [
104
+ {
105
+ name: 'main-grid',
106
+ top: 0,
107
+ left: 0,
108
+ right: `${Y_LABEL_SIZE_DESKTOP}px`,
109
+ bottom: `${X_LABEL_SIZE}px`,
110
+ },
111
+ ],
112
+ graphic: [
113
+ ...gridLines,
114
+ {
115
+ ...getLineCommons(isDark),
116
+ top: 0,
117
+ right: 0,
118
+ shape: {
119
+ x1: 0,
120
+ y1: 0,
121
+ x2: 0,
122
+ y2: 0,
123
+ },
124
+ },
125
+ ],
126
+ };
127
+ };
@@ -0,0 +1,19 @@
1
+ import type { EChartsOption } from 'echarts';
2
+
3
+ import type { CandlesData } from '../../gql/types/graphql';
4
+
5
+ export interface ChartProps {
6
+ values: CandlesData[];
7
+ }
8
+
9
+ export interface GetOptionProps {
10
+ values: CandlesData[];
11
+ isDark: boolean;
12
+ }
13
+
14
+ export type GetOptionType = (props: GetOptionProps) => EChartsOption;
15
+
16
+ export interface ChartValue {
17
+ min: number;
18
+ max: number;
19
+ }
@@ -0,0 +1,47 @@
1
+ import { TimeSpanSubset } from './types';
2
+
3
+ const timeUnitConfig = [
4
+ {
5
+ value: TimeSpanSubset.Day_1,
6
+ label: '1d',
7
+ tooltipLabel: {
8
+ translationKey: 'day',
9
+ count: 1,
10
+ },
11
+ },
12
+ {
13
+ value: TimeSpanSubset.Week_1,
14
+ label: '1w',
15
+ tooltipLabel: {
16
+ translationKey: 'week',
17
+ count: 1,
18
+ },
19
+ },
20
+ {
21
+ value: TimeSpanSubset.Month_1,
22
+ label: '1m',
23
+ tooltipLabel: {
24
+ translationKey: 'month',
25
+ count: 1,
26
+ },
27
+ },
28
+
29
+ {
30
+ value: TimeSpanSubset.Month_6,
31
+ label: '6m',
32
+ tooltipLabel: {
33
+ translationKey: 'month',
34
+ count: 6,
35
+ },
36
+ },
37
+ {
38
+ value: TimeSpanSubset.Year_1,
39
+ label: '1y',
40
+ tooltipLabel: {
41
+ translationKey: 'year',
42
+ count: 1,
43
+ },
44
+ },
45
+ ];
46
+
47
+ export { timeUnitConfig };
@@ -0,0 +1,2 @@
1
+ export * from './InstrumentsPriceChartWidget';
2
+ export * from './types';
@@ -0,0 +1,52 @@
1
+ import type { Theme } from '@oanda/labs-widget-common';
2
+ import { validateLocale, validateToolParams } from '@oanda/labs-widget-common';
3
+ import React from 'react';
4
+ import { createRoot } from 'react-dom/client';
5
+
6
+ import { Division } from '../gql/types/graphql';
7
+ import { InstrumentsPriceChartWidget } from './InstrumentsPriceChartWidget';
8
+
9
+ const { graphqlUrl } = window.widgetsConfig || {};
10
+
11
+ const dataInstrumentsPriceChartParamsElements = document.querySelectorAll(
12
+ 'div[data-instruments-price-chart-params]'
13
+ );
14
+
15
+ dataInstrumentsPriceChartParamsElements.forEach((element) => {
16
+ const root = createRoot(element);
17
+ const params = element.getAttribute('data-instruments-price-chart-params');
18
+ const mode = element.getAttribute('data-mode');
19
+ const { division, locale } = JSON.parse(params as string);
20
+
21
+ const isParamError = validateToolParams(
22
+ {
23
+ division,
24
+ locale,
25
+ graphqlUrl,
26
+ },
27
+ [
28
+ {
29
+ name: 'locale',
30
+ valueCheck: (value: string | undefined) => validateLocale(value),
31
+ },
32
+ {
33
+ name: 'division',
34
+ valueCheck: (value: Division) =>
35
+ Object.values(Division).includes(value),
36
+ },
37
+ {
38
+ name: 'graphqlUrl',
39
+ },
40
+ ]
41
+ );
42
+
43
+ root.render(
44
+ <InstrumentsPriceChartWidget
45
+ division={division}
46
+ graphqlUrl={graphqlUrl}
47
+ isParamError={isParamError}
48
+ locale={locale}
49
+ theme={mode as Theme}
50
+ />
51
+ );
52
+ });
@@ -0,0 +1,20 @@
1
+ import type { WidgetConfig } from '@oanda/labs-widget-common';
2
+
3
+ import type { Division } from '../gql/types/graphql';
4
+ import { TimeSpan } from '../gql/types/graphql';
5
+
6
+ export interface InstrumentsPriceChartConfig extends WidgetConfig {
7
+ division: Division;
8
+ }
9
+
10
+ export interface MainProps {
11
+ division: Division;
12
+ }
13
+
14
+ export enum TimeSpanSubset {
15
+ Day_1 = TimeSpan.Day_1,
16
+ Week_1 = TimeSpan.Week_1,
17
+ Month_1 = TimeSpan.Month_1,
18
+ Month_6 = TimeSpan.Month_6,
19
+ Year_1 = TimeSpan.Year_1,
20
+ }
@@ -0,0 +1,26 @@
1
+ import { gql } from '@apollo/client';
2
+
3
+ const getPriceCandles = gql`
4
+ query GetPriceCandles(
5
+ $division: Division
6
+ $instrument: String!
7
+ $granularity: Granularity!
8
+ $timeSpan: TimeSpan!
9
+ ) {
10
+ getPriceCandles(
11
+ division: $division
12
+ instrument: $instrument
13
+ granularity: $granularity
14
+ timeSpan: $timeSpan
15
+ ) {
16
+ time
17
+ unixTime
18
+ candle {
19
+ high
20
+ }
21
+ timeSpan
22
+ }
23
+ }
24
+ `;
25
+
26
+ export { getPriceCandles };
@@ -0,0 +1,66 @@
1
+ import { graphql, HttpResponse } from 'msw';
2
+
3
+ import type { CandlesData, TimeSpan } from '../types/graphql';
4
+
5
+ export const handlers = [
6
+ graphql.query('GetPriceCandles', ({ variables }) => {
7
+ const { timeSpan } = variables;
8
+
9
+ const rawCandles = generateMockCandleData(30);
10
+
11
+ const candles: CandlesData[] = rawCandles.map((candle) => ({
12
+ __typename: 'CandlesData',
13
+ time: new Date(candle.timestamp).toISOString(),
14
+ unixTime: Math.floor(candle.timestamp / 1000),
15
+ candle: {
16
+ __typename: 'Candle',
17
+ high: candle.max,
18
+ },
19
+ timeSpan: timeSpan as TimeSpan,
20
+ }));
21
+
22
+ return HttpResponse.json({
23
+ data: {
24
+ getPriceCandles: candles,
25
+ },
26
+ });
27
+ }),
28
+ ];
29
+
30
+ const generateMockCandleData = (count: number = 30) => {
31
+ const now = Date.now();
32
+ const candleInterval = 30 * 60 * 1000;
33
+
34
+ let currentPrice = 1.045;
35
+ const spikeIndex = Math.floor(count * 0.6);
36
+
37
+ return Array.from({ length: count }, (_, i) => {
38
+ let trend = i < spikeIndex ? 0.0005 : -0.001;
39
+
40
+ if (i === spikeIndex) {
41
+ trend = 0.03;
42
+ }
43
+
44
+ if (i > spikeIndex + 3) {
45
+ trend = 0;
46
+ }
47
+
48
+ currentPrice += trend;
49
+
50
+ currentPrice = Math.max(1.03, Math.min(1.09, currentPrice));
51
+
52
+ const noise = (Math.random() - 0.5) * 0.0005;
53
+ currentPrice += noise;
54
+
55
+ const open = currentPrice;
56
+ const high = open + Math.random() * 0.0008;
57
+ const close = open + (Math.random() - 0.5) * 0.0005;
58
+
59
+ const finalHigh = Math.max(open, close, high);
60
+
61
+ return {
62
+ timestamp: now - (count - i) * candleInterval,
63
+ max: finalHigh,
64
+ };
65
+ });
66
+ };
@@ -0,0 +1,59 @@
1
+ enum TimeSpan {
2
+ HOUR_1
3
+ HOUR_12
4
+ DAY_1
5
+ DAY_2
6
+ WEEK_1
7
+ WEEK_2
8
+ WEEK_3
9
+ MONTH_1
10
+ MONTH_3
11
+ MONTH_6
12
+ YEAR_1
13
+ }
14
+
15
+ enum Granularity {
16
+ MINUTE_5
17
+ MINUTE_15
18
+ MINUTE_30
19
+ HOUR_1
20
+ HOUR_4
21
+ DAY_1
22
+ }
23
+
24
+ enum Division {
25
+ OAP
26
+ OAU
27
+ OC
28
+ OCAN
29
+ OEL
30
+ OGM
31
+ OJ
32
+ OPT
33
+ OTMS
34
+ }
35
+
36
+ type Candle {
37
+ high: Float!
38
+ }
39
+
40
+ type Instrument {
41
+ name: String!
42
+ displayName: String!
43
+ }
44
+
45
+ type CandlesData {
46
+ time: String!
47
+ unixTime: Int!
48
+ candle: Candle!
49
+ timeSpan: TimeSpan!
50
+ }
51
+
52
+ type Query {
53
+ getPriceCandles(
54
+ division: Division
55
+ instrument: String!
56
+ granularity: Granularity!
57
+ timeSpan: TimeSpan!
58
+ ): [CandlesData!]!
59
+ }
@@ -0,0 +1,86 @@
1
+ import {
2
+ ResultOf,
3
+ DocumentTypeDecoration,
4
+ TypedDocumentNode,
5
+ } from '@graphql-typed-document-node/core';
6
+ import { FragmentDefinitionNode } from 'graphql';
7
+ import { Incremental } from './graphql';
8
+
9
+ export type FragmentType<
10
+ TDocumentType extends DocumentTypeDecoration<any, any>,
11
+ > =
12
+ TDocumentType extends DocumentTypeDecoration<infer TType, any>
13
+ ? [TType] extends [{ ' $fragmentName'?: infer TKey }]
14
+ ? TKey extends string
15
+ ? { ' $fragmentRefs'?: { [key in TKey]: TType } }
16
+ : never
17
+ : never
18
+ : never;
19
+
20
+ // return non-nullable if `fragmentType` is non-nullable
21
+ export function useFragment<TType>(
22
+ _documentNode: DocumentTypeDecoration<TType, any>,
23
+ fragmentType: FragmentType<DocumentTypeDecoration<TType, any>>
24
+ ): TType;
25
+ // return nullable if `fragmentType` is nullable
26
+ export function useFragment<TType>(
27
+ _documentNode: DocumentTypeDecoration<TType, any>,
28
+ fragmentType:
29
+ | FragmentType<DocumentTypeDecoration<TType, any>>
30
+ | null
31
+ | undefined
32
+ ): TType | null | undefined;
33
+ // return array of non-nullable if `fragmentType` is array of non-nullable
34
+ export function useFragment<TType>(
35
+ _documentNode: DocumentTypeDecoration<TType, any>,
36
+ fragmentType: ReadonlyArray<FragmentType<DocumentTypeDecoration<TType, any>>>
37
+ ): ReadonlyArray<TType>;
38
+ // return array of nullable if `fragmentType` is array of nullable
39
+ export function useFragment<TType>(
40
+ _documentNode: DocumentTypeDecoration<TType, any>,
41
+ fragmentType:
42
+ | ReadonlyArray<FragmentType<DocumentTypeDecoration<TType, any>>>
43
+ | null
44
+ | undefined
45
+ ): ReadonlyArray<TType> | null | undefined;
46
+ export function useFragment<TType>(
47
+ _documentNode: DocumentTypeDecoration<TType, any>,
48
+ fragmentType:
49
+ | FragmentType<DocumentTypeDecoration<TType, any>>
50
+ | ReadonlyArray<FragmentType<DocumentTypeDecoration<TType, any>>>
51
+ | null
52
+ | undefined
53
+ ): TType | ReadonlyArray<TType> | null | undefined {
54
+ return fragmentType as any;
55
+ }
56
+
57
+ export function makeFragmentData<
58
+ F extends DocumentTypeDecoration<any, any>,
59
+ FT extends ResultOf<F>,
60
+ >(data: FT, _fragment: F): FragmentType<F> {
61
+ return data as FragmentType<F>;
62
+ }
63
+ export function isFragmentReady<TQuery, TFrag>(
64
+ queryNode: DocumentTypeDecoration<TQuery, any>,
65
+ fragmentNode: TypedDocumentNode<TFrag>,
66
+ data:
67
+ | FragmentType<TypedDocumentNode<Incremental<TFrag>, any>>
68
+ | null
69
+ | undefined
70
+ ): data is FragmentType<typeof fragmentNode> {
71
+ const deferredFields = (
72
+ queryNode as {
73
+ __meta__?: { deferredFields: Record<string, (keyof TFrag)[]> };
74
+ }
75
+ ).__meta__?.deferredFields;
76
+
77
+ if (!deferredFields) return true;
78
+
79
+ const fragDef = fragmentNode.definitions[0] as
80
+ | FragmentDefinitionNode
81
+ | undefined;
82
+ const fragName = fragDef?.name?.value;
83
+
84
+ const fields = (fragName && deferredFields[fragName]) || [];
85
+ return fields.length > 0 && fields.every((field) => data && field in data);
86
+ }
@@ -0,0 +1,54 @@
1
+ /* eslint-disable */
2
+ import * as types from './graphql';
3
+ import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/core';
4
+
5
+ /**
6
+ * Map of all GraphQL operations in the project.
7
+ *
8
+ * This map has several performance disadvantages:
9
+ * 1. It is not tree-shakeable, so it will include all operations in the project.
10
+ * 2. It is not minifiable, so the string of a GraphQL query will be multiple times inside the bundle.
11
+ * 3. It does not support dead code elimination, so it will add unused operations.
12
+ *
13
+ * Therefore it is highly recommended to use the babel or swc plugin for production.
14
+ */
15
+ const documents = {
16
+ '\n query GetPriceCandles(\n $division: Division\n $instrument: String!\n $granularity: Granularity!\n $timeSpan: TimeSpan!\n ) {\n getPriceCandles(\n division: $division\n instrument: $instrument\n granularity: $granularity\n timeSpan: $timeSpan\n ) {\n time\n unixTime\n candle {\n high\n }\n timeSpan\n }\n }\n':
17
+ types.GetPriceCandlesDocument,
18
+ '\n query validateInstruments($instruments: [String]!, $division: Division) {\n mapInstrumentNames(instruments: $instruments, division: $division) {\n name\n displayName\n }\n }\n':
19
+ types.ValidateInstrumentsDocument,
20
+ };
21
+
22
+ /**
23
+ * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
24
+ *
25
+ *
26
+ * @example
27
+ * ```ts
28
+ * const query = graphql(`query GetUser($id: ID!) { user(id: $id) { name } }`);
29
+ * ```
30
+ *
31
+ * The query argument is unknown!
32
+ * Please regenerate the types.
33
+ */
34
+ export function graphql(source: string): unknown;
35
+
36
+ /**
37
+ * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
38
+ */
39
+ export function graphql(
40
+ source: '\n query GetPriceCandles(\n $division: Division\n $instrument: String!\n $granularity: Granularity!\n $timeSpan: TimeSpan!\n ) {\n getPriceCandles(\n division: $division\n instrument: $instrument\n granularity: $granularity\n timeSpan: $timeSpan\n ) {\n time\n unixTime\n candle {\n high\n }\n timeSpan\n }\n }\n'
41
+ ): (typeof documents)['\n query GetPriceCandles(\n $division: Division\n $instrument: String!\n $granularity: Granularity!\n $timeSpan: TimeSpan!\n ) {\n getPriceCandles(\n division: $division\n instrument: $instrument\n granularity: $granularity\n timeSpan: $timeSpan\n ) {\n time\n unixTime\n candle {\n high\n }\n timeSpan\n }\n }\n'];
42
+ /**
43
+ * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
44
+ */
45
+ export function graphql(
46
+ source: '\n query validateInstruments($instruments: [String]!, $division: Division) {\n mapInstrumentNames(instruments: $instruments, division: $division) {\n name\n displayName\n }\n }\n'
47
+ ): (typeof documents)['\n query validateInstruments($instruments: [String]!, $division: Division) {\n mapInstrumentNames(instruments: $instruments, division: $division) {\n name\n displayName\n }\n }\n'];
48
+
49
+ export function graphql(source: string) {
50
+ return (documents as any)[source] ?? {};
51
+ }
52
+
53
+ export type DocumentType<TDocumentNode extends DocumentNode<any, any>> =
54
+ TDocumentNode extends DocumentNode<infer TType, any> ? TType : never;