@oanda/labs-value-at-risk-widget 1.0.65 → 1.0.67
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.
- package/CHANGELOG.md +540 -0
- package/dist/main/ValueAtRiskWidget/ChartWithData.js +7 -6
- package/dist/main/ValueAtRiskWidget/ChartWithData.js.map +1 -1
- package/dist/main/ValueAtRiskWidget/Tool.js +12 -12
- package/dist/main/ValueAtRiskWidget/Tool.js.map +1 -1
- package/dist/main/ValueAtRiskWidget/ToolWithData.js +3 -3
- package/dist/main/ValueAtRiskWidget/ToolWithData.js.map +1 -1
- package/dist/main/ValueAtRiskWidget/ValueAtRiskWidget.js +8 -8
- package/dist/main/ValueAtRiskWidget/ValueAtRiskWidget.js.map +1 -1
- package/dist/main/ValueAtRiskWidget/Widget.js +9 -9
- package/dist/main/ValueAtRiskWidget/Widget.js.map +1 -1
- package/dist/main/ValueAtRiskWidget/components/Chart/Chart.js +11 -11
- package/dist/main/ValueAtRiskWidget/components/Chart/Chart.js.map +1 -1
- package/dist/main/ValueAtRiskWidget/components/Chart/getOption.js +11 -7
- package/dist/main/ValueAtRiskWidget/components/Chart/getOption.js.map +1 -1
- package/dist/main/ValueAtRiskWidget/components/Chart/types.js.map +1 -1
- package/dist/main/ValueAtRiskWidget/components/Legend/DashedLine.js +7 -7
- package/dist/main/ValueAtRiskWidget/components/Legend/DashedLine.js.map +1 -1
- package/dist/main/ValueAtRiskWidget/components/Legend/DesktopLegend.js +5 -5
- package/dist/main/ValueAtRiskWidget/components/Legend/DesktopLegend.js.map +1 -1
- package/dist/main/ValueAtRiskWidget/components/Legend/Legend.js +15 -15
- package/dist/main/ValueAtRiskWidget/components/Legend/Legend.js.map +1 -1
- package/dist/main/ValueAtRiskWidget/components/Legend/MobileLegend.js +8 -8
- package/dist/main/ValueAtRiskWidget/components/Legend/MobileLegend.js.map +1 -1
- package/dist/main/ValueAtRiskWidget/components/Legend/constants.js.map +1 -1
- package/dist/main/ValueAtRiskWidget/components/Legend/types.js.map +1 -1
- package/dist/main/ValueAtRiskWidget/render.js +9 -9
- package/dist/main/ValueAtRiskWidget/render.js.map +1 -1
- package/dist/main/ValueAtRiskWidget/types.js.map +1 -1
- package/dist/main/ValueAtRiskWidget/utils.js +1 -1
- package/dist/main/ValueAtRiskWidget/utils.js.map +1 -1
- package/dist/main/gql/getValueAtRiskAssetClasses.js +3 -11
- package/dist/main/gql/getValueAtRiskAssetClasses.js.map +1 -1
- package/dist/main/gql/getValueAtRiskChart.js +3 -26
- package/dist/main/gql/getValueAtRiskChart.js.map +1 -1
- package/dist/main/gql/types/fragment-masking.js +3 -2
- package/dist/main/gql/types/fragment-masking.js.map +1 -1
- package/dist/main/gql/types/gql.js +4 -3
- package/dist/main/gql/types/gql.js.map +1 -1
- package/dist/main/gql/types/graphql.js +241 -241
- package/dist/main/gql/types/graphql.js.map +1 -1
- package/dist/main/gql/types/index.js.map +1 -1
- package/dist/main/translations/index.js +1 -1
- package/dist/main/translations/index.js.map +1 -1
- package/dist/main/translations/translations.js.map +1 -1
- package/dist/module/ValueAtRiskWidget/ChartWithData.js +7 -6
- package/dist/module/ValueAtRiskWidget/ChartWithData.js.map +1 -1
- package/dist/module/ValueAtRiskWidget/Tool.js +12 -12
- package/dist/module/ValueAtRiskWidget/Tool.js.map +1 -1
- package/dist/module/ValueAtRiskWidget/ToolWithData.js +3 -3
- package/dist/module/ValueAtRiskWidget/ToolWithData.js.map +1 -1
- package/dist/module/ValueAtRiskWidget/ValueAtRiskWidget.js +8 -8
- package/dist/module/ValueAtRiskWidget/ValueAtRiskWidget.js.map +1 -1
- package/dist/module/ValueAtRiskWidget/Widget.js +9 -9
- package/dist/module/ValueAtRiskWidget/Widget.js.map +1 -1
- package/dist/module/ValueAtRiskWidget/components/Chart/Chart.js +9 -9
- package/dist/module/ValueAtRiskWidget/components/Chart/Chart.js.map +1 -1
- package/dist/module/ValueAtRiskWidget/components/Chart/getOption.js +12 -8
- package/dist/module/ValueAtRiskWidget/components/Chart/getOption.js.map +1 -1
- package/dist/module/ValueAtRiskWidget/components/Chart/types.js.map +1 -1
- package/dist/module/ValueAtRiskWidget/components/Legend/DashedLine.js +7 -7
- package/dist/module/ValueAtRiskWidget/components/Legend/DashedLine.js.map +1 -1
- package/dist/module/ValueAtRiskWidget/components/Legend/DesktopLegend.js +5 -5
- package/dist/module/ValueAtRiskWidget/components/Legend/DesktopLegend.js.map +1 -1
- package/dist/module/ValueAtRiskWidget/components/Legend/Legend.js +15 -15
- package/dist/module/ValueAtRiskWidget/components/Legend/Legend.js.map +1 -1
- package/dist/module/ValueAtRiskWidget/components/Legend/MobileLegend.js +8 -8
- package/dist/module/ValueAtRiskWidget/components/Legend/MobileLegend.js.map +1 -1
- package/dist/module/ValueAtRiskWidget/components/Legend/constants.js.map +1 -1
- package/dist/module/ValueAtRiskWidget/components/Legend/types.js.map +1 -1
- package/dist/module/ValueAtRiskWidget/render.js +9 -9
- package/dist/module/ValueAtRiskWidget/render.js.map +1 -1
- package/dist/module/ValueAtRiskWidget/types.js.map +1 -1
- package/dist/module/ValueAtRiskWidget/utils.js +2 -2
- package/dist/module/ValueAtRiskWidget/utils.js.map +1 -1
- package/dist/module/gql/getValueAtRiskAssetClasses.js +3 -11
- package/dist/module/gql/getValueAtRiskAssetClasses.js.map +1 -1
- package/dist/module/gql/getValueAtRiskChart.js +3 -26
- package/dist/module/gql/getValueAtRiskChart.js.map +1 -1
- package/dist/module/gql/types/fragment-masking.js +3 -2
- package/dist/module/gql/types/fragment-masking.js.map +1 -1
- package/dist/module/gql/types/gql.js +4 -3
- package/dist/module/gql/types/gql.js.map +1 -1
- package/dist/module/gql/types/graphql.js +241 -241
- package/dist/module/gql/types/graphql.js.map +1 -1
- package/dist/module/gql/types/index.js +2 -2
- package/dist/module/gql/types/index.js.map +1 -1
- package/dist/module/translations/index.js +1 -1
- package/dist/module/translations/index.js.map +1 -1
- package/dist/module/translations/translations.js.map +1 -1
- package/dist/types/ValueAtRiskWidget/ChartWithData.d.ts +1 -1
- package/dist/types/ValueAtRiskWidget/Tool.d.ts +1 -1
- package/dist/types/ValueAtRiskWidget/ToolWithData.d.ts +1 -1
- package/dist/types/ValueAtRiskWidget/ValueAtRiskWidget.d.ts +1 -1
- package/dist/types/ValueAtRiskWidget/Widget.d.ts +2 -2
- package/dist/types/ValueAtRiskWidget/components/Chart/Chart.d.ts +1 -1
- package/dist/types/ValueAtRiskWidget/components/Chart/getOption.d.ts +1 -1
- package/dist/types/ValueAtRiskWidget/components/Chart/types.d.ts +2 -2
- package/dist/types/ValueAtRiskWidget/components/Legend/DashedLine.d.ts +2 -2
- package/dist/types/ValueAtRiskWidget/components/Legend/DesktopLegend.d.ts +1 -1
- package/dist/types/ValueAtRiskWidget/components/Legend/Legend.d.ts +1 -1
- package/dist/types/ValueAtRiskWidget/components/Legend/MobileLegend.d.ts +1 -1
- package/dist/types/ValueAtRiskWidget/components/Legend/constants.d.ts +1 -1
- package/dist/types/ValueAtRiskWidget/components/Legend/types.d.ts +1 -1
- package/dist/types/ValueAtRiskWidget/types.d.ts +2 -2
- package/dist/types/ValueAtRiskWidget/utils.d.ts +2 -2
- package/dist/types/gql/types/gql.d.ts +4 -4
- package/dist/types/gql/types/index.d.ts +2 -2
- package/dist/types/translations/index.d.ts +2 -2
- package/package.json +3 -3
- package/src/ValueAtRiskWidget/ChartWithData.tsx +45 -26
- package/src/ValueAtRiskWidget/Tool.tsx +42 -28
- package/src/ValueAtRiskWidget/ToolWithData.tsx +29 -23
- package/src/ValueAtRiskWidget/ValueAtRiskWidget.tsx +16 -16
- package/src/ValueAtRiskWidget/Widget.tsx +7 -11
- package/src/ValueAtRiskWidget/components/Chart/Chart.tsx +20 -19
- package/src/ValueAtRiskWidget/components/Chart/getOption.ts +4 -4
- package/src/ValueAtRiskWidget/components/Chart/types.ts +4 -3
- package/src/ValueAtRiskWidget/components/Legend/DashedLine.tsx +18 -8
- package/src/ValueAtRiskWidget/components/Legend/DesktopLegend.tsx +28 -19
- package/src/ValueAtRiskWidget/components/Legend/Legend.tsx +11 -14
- package/src/ValueAtRiskWidget/components/Legend/MobileLegend.tsx +40 -22
- package/src/ValueAtRiskWidget/components/Legend/constants.tsx +1 -1
- package/src/ValueAtRiskWidget/components/Legend/types.tsx +9 -9
- package/src/ValueAtRiskWidget/render.tsx +22 -24
- package/src/ValueAtRiskWidget/types.ts +7 -3
- package/src/ValueAtRiskWidget/utils.ts +18 -10
- package/src/gql/getValueAtRiskAssetClasses.ts +1 -1
- package/src/gql/getValueAtRiskChart.ts +12 -2
- package/src/gql/types/fragment-masking.ts +41 -21
- package/src/gql/types/gql.ts +12 -5
- package/src/gql/types/graphql.ts +339 -47
- package/src/gql/types/index.ts +2 -2
- package/src/translations/index.ts +4 -4
- package/src/translations/translations.ts +1 -3
- package/test/ChartWithData.test.tsx +21 -13
- package/test/Tool.test.tsx +35 -21
- package/test/ToolWithData.test.tsx +18 -7
- package/test/Widget.test.tsx +13 -8
- package/test/getPercentValueByPips.test.ts +15 -3
- package/test/mocks/assetClassesMock.ts +1 -3
- package/test/mocks/responsesMocks.ts +6 -2
- package/test/utils.test.ts +14 -7
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { GetValueAtRiskChartQuery } from '../../../gql/types/graphql';
|
|
1
|
+
import type { GetValueAtRiskChartQuery } from '../../../gql/types/graphql';
|
|
2
2
|
|
|
3
3
|
export enum DataNames {
|
|
4
4
|
MIN = 'min',
|
|
@@ -14,8 +14,8 @@ export interface DesktopLegendProps {
|
|
|
14
14
|
label: string;
|
|
15
15
|
value: number;
|
|
16
16
|
}[];
|
|
17
|
-
isDark: boolean
|
|
18
|
-
lang: (key: string) => string
|
|
17
|
+
isDark: boolean;
|
|
18
|
+
lang: (key: string) => string;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
export interface MobileLegendProps {
|
|
@@ -25,16 +25,16 @@ export interface MobileLegendProps {
|
|
|
25
25
|
valueUp: number;
|
|
26
26
|
valueDown: number;
|
|
27
27
|
}[];
|
|
28
|
-
isDark: boolean
|
|
29
|
-
lang: (key: string) => string
|
|
28
|
+
isDark: boolean;
|
|
29
|
+
lang: (key: string) => string;
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
export interface LegendProps {
|
|
33
|
-
data: GetValueAtRiskChartQuery
|
|
33
|
+
data: GetValueAtRiskChartQuery;
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
export interface DashedLineProps {
|
|
37
|
-
strokeDasharray?: string
|
|
38
|
-
width?: string
|
|
39
|
-
isDark: boolean
|
|
37
|
+
strokeDasharray?: string;
|
|
38
|
+
width?: string;
|
|
39
|
+
isDark: boolean;
|
|
40
40
|
}
|
|
@@ -1,52 +1,50 @@
|
|
|
1
|
+
import type { Theme } from '@oanda/labs-widget-common';
|
|
2
|
+
import { validateLocale, validateToolParams } from '@oanda/labs-widget-common';
|
|
1
3
|
import React from 'react';
|
|
2
4
|
import { createRoot } from 'react-dom/client';
|
|
3
|
-
|
|
4
|
-
import { ValueAtRiskWidget } from './ValueAtRiskWidget';
|
|
5
|
+
|
|
5
6
|
import { Division } from '../gql/types/graphql';
|
|
7
|
+
import { ValueAtRiskWidget } from './ValueAtRiskWidget';
|
|
6
8
|
|
|
7
|
-
const {
|
|
8
|
-
graphqlUrl,
|
|
9
|
-
} = window.widgetsConfig || {};
|
|
9
|
+
const { graphqlUrl } = window.widgetsConfig || {};
|
|
10
10
|
|
|
11
|
-
const valueAtRiskParamsElements = document.querySelectorAll(
|
|
11
|
+
const valueAtRiskParamsElements = document.querySelectorAll(
|
|
12
|
+
'div[data-value-at-risk-params]'
|
|
13
|
+
);
|
|
12
14
|
|
|
13
15
|
valueAtRiskParamsElements.forEach((element) => {
|
|
14
16
|
const root = createRoot(element);
|
|
15
17
|
const params = element.getAttribute('data-value-at-risk-params');
|
|
16
18
|
const mode = element.getAttribute('data-mode');
|
|
17
|
-
const {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
instrument,
|
|
21
|
-
duration,
|
|
22
|
-
bars,
|
|
23
|
-
logoLink,
|
|
24
|
-
} = JSON.parse(params as string);
|
|
19
|
+
const { division, locale, instrument, duration, bars, logoLink } = JSON.parse(
|
|
20
|
+
params as string
|
|
21
|
+
);
|
|
25
22
|
|
|
26
23
|
const isParamError = validateToolParams({ locale, division, graphqlUrl }, [
|
|
27
24
|
{
|
|
28
25
|
name: 'locale',
|
|
29
|
-
valueCheck: (value) => validateLocale(value),
|
|
26
|
+
valueCheck: (value: string | undefined) => validateLocale(value),
|
|
30
27
|
},
|
|
31
28
|
{
|
|
32
29
|
name: 'division',
|
|
33
|
-
valueCheck: (value) => Object.values(Division).includes(value),
|
|
30
|
+
valueCheck: (value: Division) => Object.values(Division).includes(value),
|
|
34
31
|
},
|
|
35
32
|
{
|
|
36
33
|
name: 'graphqlUrl',
|
|
37
|
-
}
|
|
34
|
+
},
|
|
35
|
+
]);
|
|
38
36
|
|
|
39
37
|
root.render(
|
|
40
38
|
<ValueAtRiskWidget
|
|
41
|
-
|
|
42
|
-
locale={locale}
|
|
39
|
+
bars={bars}
|
|
43
40
|
division={division}
|
|
44
|
-
theme={mode as Theme}
|
|
45
|
-
isParamError={isParamError}
|
|
46
|
-
instrument={instrument}
|
|
47
41
|
duration={duration}
|
|
48
|
-
|
|
42
|
+
graphqlUrl={graphqlUrl}
|
|
43
|
+
instrument={instrument}
|
|
44
|
+
isParamError={isParamError}
|
|
45
|
+
locale={locale}
|
|
49
46
|
logoLink={logoLink}
|
|
50
|
-
|
|
47
|
+
theme={mode as Theme}
|
|
48
|
+
/>
|
|
51
49
|
);
|
|
52
50
|
});
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
import { WidgetConfig } from '@oanda/labs-widget-common';
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import type { WidgetConfig } from '@oanda/labs-widget-common';
|
|
2
|
+
|
|
3
|
+
import type {
|
|
4
|
+
Division,
|
|
5
|
+
GetValueAtRiskAssetClassesQuery,
|
|
6
|
+
ValueAtRiskBars,
|
|
7
|
+
ValueAtRiskDuration,
|
|
4
8
|
} from '../gql/types/graphql';
|
|
5
9
|
|
|
6
10
|
export interface ValueAtRiskConfig extends WidgetConfig {
|
|
@@ -1,24 +1,32 @@
|
|
|
1
|
-
import { AssetClass, Instrument } from '../gql/types/graphql';
|
|
1
|
+
import type { AssetClass, Instrument } from '../gql/types/graphql';
|
|
2
2
|
|
|
3
|
-
const capitalize = (name: string) =>
|
|
3
|
+
const capitalize = (name: string) =>
|
|
4
|
+
`${name[0].toUpperCase()}${name.substring(1)}`;
|
|
4
5
|
|
|
5
6
|
function sortAlphabetically<T extends Record<string, string>>(
|
|
6
7
|
paramName: keyof T,
|
|
7
|
-
items: T[]
|
|
8
|
+
items: T[]
|
|
8
9
|
): T[] {
|
|
9
|
-
return [...items]
|
|
10
|
-
|
|
10
|
+
return [...items].sort((itemA, itemB) =>
|
|
11
|
+
itemA[paramName].localeCompare(itemB[paramName], 'en', {
|
|
12
|
+
sensitivity: 'base',
|
|
13
|
+
})
|
|
14
|
+
);
|
|
11
15
|
}
|
|
12
16
|
|
|
13
17
|
const getAssetClassesList = (data: AssetClass[]) => {
|
|
14
|
-
const list = data
|
|
15
|
-
|
|
18
|
+
const list = data.map(({ name }) => ({
|
|
19
|
+
id: name.toLowerCase(),
|
|
20
|
+
label: capitalize(name),
|
|
21
|
+
}));
|
|
16
22
|
|
|
17
23
|
return sortAlphabetically('label', list);
|
|
18
24
|
};
|
|
19
25
|
|
|
20
|
-
const mapInstrumentsList = (data: Instrument[]) =>
|
|
21
|
-
|
|
26
|
+
const mapInstrumentsList = (data: Instrument[]) =>
|
|
27
|
+
sortAlphabetically('displayName', data).map(
|
|
28
|
+
({ name: id, displayName: label }) => ({ id, label })
|
|
29
|
+
);
|
|
22
30
|
|
|
23
31
|
const getInstrumentsByAssetClassId = (data: AssetClass[], id: string) => {
|
|
24
32
|
const [{ instruments }] = data.filter(({ name }) => id === name);
|
|
@@ -28,6 +36,6 @@ const getInstrumentsByAssetClassId = (data: AssetClass[], id: string) => {
|
|
|
28
36
|
|
|
29
37
|
export {
|
|
30
38
|
getAssetClassesList,
|
|
31
|
-
sortAlphabetically,
|
|
32
39
|
getInstrumentsByAssetClassId,
|
|
40
|
+
sortAlphabetically,
|
|
33
41
|
};
|
|
@@ -2,7 +2,7 @@ import { gql } from '@apollo/client';
|
|
|
2
2
|
|
|
3
3
|
export const getValueAtRiskAssetClasses = gql`
|
|
4
4
|
query GetValueAtRiskAssetClasses($division: Division) {
|
|
5
|
-
|
|
5
|
+
valueAtRiskAssetClasses(division: $division) {
|
|
6
6
|
name
|
|
7
7
|
instruments {
|
|
8
8
|
name
|
|
@@ -1,8 +1,18 @@
|
|
|
1
1
|
import { gql } from '@apollo/client';
|
|
2
2
|
|
|
3
3
|
export const getValueAtRiskChart = gql`
|
|
4
|
-
query getValueAtRiskChart(
|
|
5
|
-
|
|
4
|
+
query getValueAtRiskChart(
|
|
5
|
+
$instrument: String!
|
|
6
|
+
$division: Division!
|
|
7
|
+
$duration: ValueAtRiskDuration!
|
|
8
|
+
$bars: ValueAtRiskBars!
|
|
9
|
+
) {
|
|
10
|
+
valueAtRiskChart(
|
|
11
|
+
instrument: $instrument
|
|
12
|
+
division: $division
|
|
13
|
+
duration: $duration
|
|
14
|
+
bars: $bars
|
|
15
|
+
) {
|
|
6
16
|
up {
|
|
7
17
|
points {
|
|
8
18
|
pips
|
|
@@ -1,18 +1,21 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
ResultOf,
|
|
3
|
+
DocumentTypeDecoration,
|
|
4
|
+
TypedDocumentNode,
|
|
5
|
+
} from '@graphql-typed-document-node/core';
|
|
2
6
|
import { FragmentDefinitionNode } from 'graphql';
|
|
3
7
|
import { Incremental } from './graphql';
|
|
4
8
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
any
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
|
13
17
|
: never
|
|
14
|
-
: never
|
|
15
|
-
: never;
|
|
18
|
+
: never;
|
|
16
19
|
|
|
17
20
|
// return non-nullable if `fragmentType` is non-nullable
|
|
18
21
|
export function useFragment<TType>(
|
|
@@ -22,7 +25,10 @@ export function useFragment<TType>(
|
|
|
22
25
|
// return nullable if `fragmentType` is nullable
|
|
23
26
|
export function useFragment<TType>(
|
|
24
27
|
_documentNode: DocumentTypeDecoration<TType, any>,
|
|
25
|
-
fragmentType:
|
|
28
|
+
fragmentType:
|
|
29
|
+
| FragmentType<DocumentTypeDecoration<TType, any>>
|
|
30
|
+
| null
|
|
31
|
+
| undefined
|
|
26
32
|
): TType | null | undefined;
|
|
27
33
|
// return array of non-nullable if `fragmentType` is array of non-nullable
|
|
28
34
|
export function useFragment<TType>(
|
|
@@ -32,35 +38,49 @@ export function useFragment<TType>(
|
|
|
32
38
|
// return array of nullable if `fragmentType` is array of nullable
|
|
33
39
|
export function useFragment<TType>(
|
|
34
40
|
_documentNode: DocumentTypeDecoration<TType, any>,
|
|
35
|
-
fragmentType:
|
|
41
|
+
fragmentType:
|
|
42
|
+
| ReadonlyArray<FragmentType<DocumentTypeDecoration<TType, any>>>
|
|
43
|
+
| null
|
|
44
|
+
| undefined
|
|
36
45
|
): ReadonlyArray<TType> | null | undefined;
|
|
37
46
|
export function useFragment<TType>(
|
|
38
47
|
_documentNode: DocumentTypeDecoration<TType, any>,
|
|
39
|
-
fragmentType:
|
|
48
|
+
fragmentType:
|
|
49
|
+
| FragmentType<DocumentTypeDecoration<TType, any>>
|
|
50
|
+
| ReadonlyArray<FragmentType<DocumentTypeDecoration<TType, any>>>
|
|
51
|
+
| null
|
|
52
|
+
| undefined
|
|
40
53
|
): TType | ReadonlyArray<TType> | null | undefined {
|
|
41
54
|
return fragmentType as any;
|
|
42
55
|
}
|
|
43
56
|
|
|
44
|
-
|
|
45
57
|
export function makeFragmentData<
|
|
46
58
|
F extends DocumentTypeDecoration<any, any>,
|
|
47
|
-
FT extends ResultOf<F
|
|
59
|
+
FT extends ResultOf<F>,
|
|
48
60
|
>(data: FT, _fragment: F): FragmentType<F> {
|
|
49
61
|
return data as FragmentType<F>;
|
|
50
62
|
}
|
|
51
63
|
export function isFragmentReady<TQuery, TFrag>(
|
|
52
64
|
queryNode: DocumentTypeDecoration<TQuery, any>,
|
|
53
65
|
fragmentNode: TypedDocumentNode<TFrag>,
|
|
54
|
-
data:
|
|
66
|
+
data:
|
|
67
|
+
| FragmentType<TypedDocumentNode<Incremental<TFrag>, any>>
|
|
68
|
+
| null
|
|
69
|
+
| undefined
|
|
55
70
|
): data is FragmentType<typeof fragmentNode> {
|
|
56
|
-
const deferredFields = (
|
|
57
|
-
|
|
71
|
+
const deferredFields = (
|
|
72
|
+
queryNode as {
|
|
73
|
+
__meta__?: { deferredFields: Record<string, (keyof TFrag)[]> };
|
|
74
|
+
}
|
|
75
|
+
).__meta__?.deferredFields;
|
|
58
76
|
|
|
59
77
|
if (!deferredFields) return true;
|
|
60
78
|
|
|
61
|
-
const fragDef = fragmentNode.definitions[0] as
|
|
79
|
+
const fragDef = fragmentNode.definitions[0] as
|
|
80
|
+
| FragmentDefinitionNode
|
|
81
|
+
| undefined;
|
|
62
82
|
const fragName = fragDef?.name?.value;
|
|
63
83
|
|
|
64
84
|
const fields = (fragName && deferredFields[fragName]) || [];
|
|
65
|
-
return fields.length > 0 && fields.every(field => data && field in data);
|
|
85
|
+
return fields.length > 0 && fields.every((field) => data && field in data);
|
|
66
86
|
}
|
package/src/gql/types/gql.ts
CHANGED
|
@@ -13,8 +13,10 @@ import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/
|
|
|
13
13
|
* Therefore it is highly recommended to use the babel or swc plugin for production.
|
|
14
14
|
*/
|
|
15
15
|
const documents = {
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
'\n query GetValueAtRiskAssetClasses($division: Division) {\n valueAtRiskAssetClasses(division: $division) {\n name\n instruments {\n name\n displayName\n }\n }\n }\n':
|
|
17
|
+
types.GetValueAtRiskAssetClassesDocument,
|
|
18
|
+
'\n query getValueAtRiskChart($instrument: String!, $division: Division!, $duration: ValueAtRiskDuration!, $bars: ValueAtRiskBars!) {\n valueAtRiskChart(instrument: $instrument, division: $division, duration: $duration, bars: $bars) {\n up {\n points {\n pips\n percent\n }\n average\n median\n max\n threshold\n }\n down {\n points {\n pips\n percent\n }\n average\n median\n max\n threshold\n }\n }\n }\n':
|
|
19
|
+
types.GetValueAtRiskChartDocument,
|
|
18
20
|
};
|
|
19
21
|
|
|
20
22
|
/**
|
|
@@ -34,14 +36,19 @@ export function graphql(source: string): unknown;
|
|
|
34
36
|
/**
|
|
35
37
|
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
|
|
36
38
|
*/
|
|
37
|
-
export function graphql(
|
|
39
|
+
export function graphql(
|
|
40
|
+
source: '\n query GetValueAtRiskAssetClasses($division: Division) {\n valueAtRiskAssetClasses(division: $division) {\n name\n instruments {\n name\n displayName\n }\n }\n }\n'
|
|
41
|
+
): (typeof documents)['\n query GetValueAtRiskAssetClasses($division: Division) {\n valueAtRiskAssetClasses(division: $division) {\n name\n instruments {\n name\n displayName\n }\n }\n }\n'];
|
|
38
42
|
/**
|
|
39
43
|
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
|
|
40
44
|
*/
|
|
41
|
-
export function graphql(
|
|
45
|
+
export function graphql(
|
|
46
|
+
source: '\n query getValueAtRiskChart($instrument: String!, $division: Division!, $duration: ValueAtRiskDuration!, $bars: ValueAtRiskBars!) {\n valueAtRiskChart(instrument: $instrument, division: $division, duration: $duration, bars: $bars) {\n up {\n points {\n pips\n percent\n }\n average\n median\n max\n threshold\n }\n down {\n points {\n pips\n percent\n }\n average\n median\n max\n threshold\n }\n }\n }\n'
|
|
47
|
+
): (typeof documents)['\n query getValueAtRiskChart($instrument: String!, $division: Division!, $duration: ValueAtRiskDuration!, $bars: ValueAtRiskBars!) {\n valueAtRiskChart(instrument: $instrument, division: $division, duration: $duration, bars: $bars) {\n up {\n points {\n pips\n percent\n }\n average\n median\n max\n threshold\n }\n down {\n points {\n pips\n percent\n }\n average\n median\n max\n threshold\n }\n }\n }\n'];
|
|
42
48
|
|
|
43
49
|
export function graphql(source: string) {
|
|
44
50
|
return (documents as any)[source] ?? {};
|
|
45
51
|
}
|
|
46
52
|
|
|
47
|
-
export type DocumentType<TDocumentNode extends DocumentNode<any, any>> =
|
|
53
|
+
export type DocumentType<TDocumentNode extends DocumentNode<any, any>> =
|
|
54
|
+
TDocumentNode extends DocumentNode<infer TType, any> ? TType : never;
|