@oanda/labs-currency-cross-table 1.0.6 → 1.0.8
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 +68 -0
- package/codegen.ts +15 -0
- package/dist/main/CurrencyCrossTableWidget/CurrencyCrossTableWidget.js +12 -4
- package/dist/main/CurrencyCrossTableWidget/CurrencyCrossTableWidget.js.map +1 -1
- package/dist/main/CurrencyCrossTableWidget/Main.js +19 -17
- package/dist/main/CurrencyCrossTableWidget/Main.js.map +1 -1
- package/dist/main/CurrencyCrossTableWidget/ValidationWrapper.js +2 -1
- package/dist/main/CurrencyCrossTableWidget/ValidationWrapper.js.map +1 -1
- package/dist/main/CurrencyCrossTableWidget/components/Cell.js +2 -4
- package/dist/main/CurrencyCrossTableWidget/components/Cell.js.map +1 -1
- package/dist/main/CurrencyCrossTableWidget/components/CellValidationWrapper.js +49 -0
- package/dist/main/CurrencyCrossTableWidget/components/CellValidationWrapper.js.map +1 -0
- package/dist/main/CurrencyCrossTableWidget/components/CellWithData.js +19 -13
- package/dist/main/CurrencyCrossTableWidget/components/CellWithData.js.map +1 -1
- package/dist/main/CurrencyCrossTableWidget/components/TextCell.js +7 -5
- package/dist/main/CurrencyCrossTableWidget/components/TextCell.js.map +1 -1
- package/dist/main/CurrencyCrossTableWidget/components/types.js.map +1 -1
- package/dist/main/CurrencyCrossTableWidget/render.js +7 -2
- package/dist/main/CurrencyCrossTableWidget/render.js.map +1 -1
- package/dist/main/CurrencyCrossTableWidget/types.js +0 -13
- package/dist/main/CurrencyCrossTableWidget/types.js.map +1 -1
- package/dist/main/CurrencyCrossTableWidget/utils.js +13 -30
- package/dist/main/CurrencyCrossTableWidget/utils.js.map +1 -1
- package/dist/main/gql/types/fragment-masking.js +23 -0
- package/dist/main/gql/types/fragment-masking.js.map +1 -0
- package/dist/main/gql/types/gql.js +16 -0
- package/dist/main/gql/types/gql.js.map +1 -0
- package/dist/main/gql/types/graphql.js +223 -0
- package/dist/main/gql/types/graphql.js.map +1 -0
- package/dist/main/gql/types/index.js +28 -0
- package/dist/main/gql/types/index.js.map +1 -0
- package/dist/main/gql/validateInstruments.js +16 -0
- package/dist/main/gql/validateInstruments.js.map +1 -0
- package/dist/module/CurrencyCrossTableWidget/CurrencyCrossTableWidget.js +10 -2
- package/dist/module/CurrencyCrossTableWidget/CurrencyCrossTableWidget.js.map +1 -1
- package/dist/module/CurrencyCrossTableWidget/Main.js +21 -19
- package/dist/module/CurrencyCrossTableWidget/Main.js.map +1 -1
- package/dist/module/CurrencyCrossTableWidget/ValidationWrapper.js +2 -1
- package/dist/module/CurrencyCrossTableWidget/ValidationWrapper.js.map +1 -1
- package/dist/module/CurrencyCrossTableWidget/components/Cell.js +2 -4
- package/dist/module/CurrencyCrossTableWidget/components/Cell.js.map +1 -1
- package/dist/module/CurrencyCrossTableWidget/components/CellValidationWrapper.js +42 -0
- package/dist/module/CurrencyCrossTableWidget/components/CellValidationWrapper.js.map +1 -0
- package/dist/module/CurrencyCrossTableWidget/components/CellWithData.js +20 -14
- package/dist/module/CurrencyCrossTableWidget/components/CellWithData.js.map +1 -1
- package/dist/module/CurrencyCrossTableWidget/components/TextCell.js +7 -5
- package/dist/module/CurrencyCrossTableWidget/components/TextCell.js.map +1 -1
- package/dist/module/CurrencyCrossTableWidget/components/types.js.map +1 -1
- package/dist/module/CurrencyCrossTableWidget/render.js +6 -1
- package/dist/module/CurrencyCrossTableWidget/render.js.map +1 -1
- package/dist/module/CurrencyCrossTableWidget/types.js +0 -12
- package/dist/module/CurrencyCrossTableWidget/types.js.map +1 -1
- package/dist/module/CurrencyCrossTableWidget/utils.js +10 -29
- package/dist/module/CurrencyCrossTableWidget/utils.js.map +1 -1
- package/dist/module/gql/types/fragment-masking.js +15 -0
- package/dist/module/gql/types/fragment-masking.js.map +1 -0
- package/dist/module/gql/types/gql.js +8 -0
- package/dist/module/gql/types/gql.js.map +1 -0
- package/dist/module/gql/types/graphql.js +217 -0
- package/dist/module/gql/types/graphql.js.map +1 -0
- package/dist/module/gql/types/index.js +3 -0
- package/dist/module/gql/types/index.js.map +1 -0
- package/dist/module/gql/validateInstruments.js +10 -0
- package/dist/module/gql/validateInstruments.js.map +1 -0
- package/dist/types/CurrencyCrossTableWidget/CurrencyCrossTableWidget.d.ts +1 -1
- package/dist/types/CurrencyCrossTableWidget/Main.d.ts +1 -1
- package/dist/types/CurrencyCrossTableWidget/components/Cell.d.ts +1 -1
- package/dist/types/CurrencyCrossTableWidget/components/CellValidationWrapper.d.ts +4 -0
- package/dist/types/CurrencyCrossTableWidget/components/CellWithData.d.ts +1 -1
- package/dist/types/CurrencyCrossTableWidget/components/TextCell.d.ts +1 -1
- package/dist/types/CurrencyCrossTableWidget/components/types.d.ts +15 -4
- package/dist/types/CurrencyCrossTableWidget/types.d.ts +3 -11
- package/dist/types/CurrencyCrossTableWidget/utils.d.ts +5 -6
- package/dist/types/gql/types/fragment-masking.d.ts +15 -0
- package/dist/types/gql/types/gql.d.ts +37 -0
- package/dist/types/gql/types/graphql.d.ts +384 -0
- package/dist/types/gql/types/index.d.ts +2 -0
- package/dist/types/gql/validateInstruments.d.ts +1 -0
- package/package.json +12 -4
- package/src/CurrencyCrossTableWidget/CurrencyCrossTableWidget.tsx +16 -6
- package/src/CurrencyCrossTableWidget/Main.tsx +23 -19
- package/src/CurrencyCrossTableWidget/ValidationWrapper.tsx +1 -0
- package/src/CurrencyCrossTableWidget/components/Cell.tsx +2 -4
- package/src/CurrencyCrossTableWidget/components/CellValidationWrapper.tsx +49 -0
- package/src/CurrencyCrossTableWidget/components/CellWithData.tsx +30 -16
- package/src/CurrencyCrossTableWidget/components/TextCell.tsx +6 -4
- package/src/CurrencyCrossTableWidget/components/types.ts +15 -4
- package/src/CurrencyCrossTableWidget/render.tsx +6 -2
- package/src/CurrencyCrossTableWidget/types.tsx +3 -12
- package/src/CurrencyCrossTableWidget/utils.ts +17 -37
- package/src/gql/types/fragment-masking.ts +66 -0
- package/src/gql/types/gql.ts +42 -0
- package/src/gql/types/graphql.ts +423 -0
- package/src/gql/types/index.ts +2 -0
- package/src/gql/validateInstruments.ts +10 -0
- package/test/Main.test.tsx +12 -6
- package/test/mocks.ts +225 -0
|
@@ -1,35 +1,45 @@
|
|
|
1
1
|
import React, { useState } from 'react';
|
|
2
|
-
import { Price } from '@oanda/labs-widget-common';
|
|
3
|
-
import { useRecords } from '../utils';
|
|
4
|
-
import { CellWithDataProps } from './types';
|
|
2
|
+
import { Price, useLiveRatesMessage } from '@oanda/labs-widget-common';
|
|
5
3
|
import { Cell } from './Cell';
|
|
4
|
+
import { CellWithDataProps } from './types';
|
|
5
|
+
import { getBuyPrice, getPriceMovement } from '../utils';
|
|
6
6
|
|
|
7
7
|
const CellWithData = ({
|
|
8
|
-
|
|
8
|
+
currency,
|
|
9
|
+
pair,
|
|
9
10
|
record,
|
|
11
|
+
instrumentForCalculations,
|
|
10
12
|
target,
|
|
11
|
-
additionalBorderBottom,
|
|
12
13
|
setSelectedCurrency,
|
|
13
14
|
setSelectedPair,
|
|
14
15
|
}: CellWithDataProps) => {
|
|
15
16
|
const [hovered, setHovered] = useState(false);
|
|
16
|
-
const { updatedRecord, error } = useRecords(record, record.instrument ? target : null);
|
|
17
17
|
|
|
18
|
-
const
|
|
18
|
+
const instrumentForUpdates = instrumentForCalculations || record.instrument;
|
|
19
19
|
|
|
20
|
-
const
|
|
21
|
-
|
|
20
|
+
const { update, error: liveRatesError } = useLiveRatesMessage(
|
|
21
|
+
instrumentForUpdates,
|
|
22
|
+
target,
|
|
23
|
+
);
|
|
22
24
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
+
const updatedRecord: Record<string, any> = {
|
|
26
|
+
displayName: record.displayName,
|
|
27
|
+
instrument: record.instrument,
|
|
28
|
+
buy: update?.ask,
|
|
29
|
+
buyPriceMovement: update?.askPriceMovement,
|
|
30
|
+
displayPrecision: update?.displayPrecision,
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const checkLoading = (id: string) => (!liveRatesError && updatedRecord?.[id] === undefined);
|
|
25
34
|
|
|
35
|
+
const handleMouseEnter = () => {
|
|
36
|
+
setHovered(true);
|
|
26
37
|
setSelectedCurrency(currency);
|
|
27
38
|
setSelectedPair(pair);
|
|
28
39
|
};
|
|
29
40
|
|
|
30
41
|
const handleMouseLeave = () => {
|
|
31
42
|
setHovered(false);
|
|
32
|
-
|
|
33
43
|
setSelectedCurrency('');
|
|
34
44
|
setSelectedPair('');
|
|
35
45
|
};
|
|
@@ -37,14 +47,18 @@ const CellWithData = ({
|
|
|
37
47
|
return (
|
|
38
48
|
<Cell
|
|
39
49
|
isLoading={checkLoading('buy')}
|
|
40
|
-
isError={!!
|
|
41
|
-
additionalBorderBottom={additionalBorderBottom}
|
|
50
|
+
isError={!!liveRatesError}
|
|
42
51
|
hovered={hovered}
|
|
43
52
|
mouseEnterHandler={handleMouseEnter}
|
|
44
53
|
mouseLeaveHandler={handleMouseLeave}
|
|
45
54
|
>
|
|
46
|
-
<Price priceMovement={updatedRecord.buyPriceMovement} movementIndicator="background">
|
|
47
|
-
<span>
|
|
55
|
+
<Price priceMovement={getPriceMovement(updatedRecord.buyPriceMovement, !!instrumentForCalculations)} movementIndicator="background">
|
|
56
|
+
<span>
|
|
57
|
+
{getBuyPrice(
|
|
58
|
+
updatedRecord.buy,
|
|
59
|
+
!!instrumentForCalculations,
|
|
60
|
+
).toFixed(updatedRecord.displayPrecision)}
|
|
61
|
+
</span>
|
|
48
62
|
</Price>
|
|
49
63
|
</Cell>
|
|
50
64
|
);
|
|
@@ -5,13 +5,15 @@ import { TextCellProps } from './types';
|
|
|
5
5
|
const TextCell = ({
|
|
6
6
|
label,
|
|
7
7
|
emptyIndicator,
|
|
8
|
-
additionalBorderBottom,
|
|
9
8
|
hovered,
|
|
9
|
+
sticky,
|
|
10
10
|
}: TextCellProps) => (
|
|
11
|
-
<span className={classnames('lw-flex-1 lw-border-r lw-border-solid lw-border-border-primary lw-py-3.5 lw-text-center', {
|
|
12
|
-
'lw-border-b': additionalBorderBottom,
|
|
11
|
+
<span className={classnames('lw-h-11 lw-min-w-[70px] lw-flex-1 lw-border-b lw-border-r lw-border-solid lw-border-border-primary lw-py-3.5 lw-text-center last:lw-border-r-[0px]', {
|
|
13
12
|
'lw-bg-border-primary': emptyIndicator,
|
|
14
|
-
'lw-
|
|
13
|
+
'lw-shadow-innerBorderBgColor': emptyIndicator && hovered,
|
|
14
|
+
'lw-bg-border-primary lw-font-semibold': hovered,
|
|
15
|
+
'lw-sticky lw-left-0 lw-z-10': sticky,
|
|
16
|
+
'lw-bg-bg-primary': sticky && !hovered,
|
|
15
17
|
})}
|
|
16
18
|
>
|
|
17
19
|
{label}
|
|
@@ -1,10 +1,22 @@
|
|
|
1
1
|
import { DataRecord, LoaderSize } from '@oanda/labs-widget-common';
|
|
2
|
+
import { Division } from '../../gql/types/graphql';
|
|
2
3
|
|
|
4
|
+
export interface CellValidationWrapperProps {
|
|
5
|
+
currency: string;
|
|
6
|
+
pair: string;
|
|
7
|
+
instrument: string;
|
|
8
|
+
target: EventTarget | null;
|
|
9
|
+
division: Division;
|
|
10
|
+
setSelectedCurrency: React.Dispatch<React.SetStateAction<string>>;
|
|
11
|
+
setSelectedPair: React.Dispatch<React.SetStateAction<string>>;
|
|
12
|
+
}
|
|
3
13
|
export interface CellWithDataProps {
|
|
4
|
-
|
|
14
|
+
currency: string;
|
|
15
|
+
pair: string;
|
|
16
|
+
instrumentForCalculations: string;
|
|
5
17
|
record: DataRecord;
|
|
6
18
|
target: EventTarget | null;
|
|
7
|
-
|
|
19
|
+
division: Division;
|
|
8
20
|
setSelectedCurrency: React.Dispatch<React.SetStateAction<string>>;
|
|
9
21
|
setSelectedPair: React.Dispatch<React.SetStateAction<string>>;
|
|
10
22
|
}
|
|
@@ -14,7 +26,6 @@ export interface CellProps {
|
|
|
14
26
|
isLoading?: boolean;
|
|
15
27
|
isError?: boolean;
|
|
16
28
|
loaderSize?: LoaderSize;
|
|
17
|
-
additionalBorderBottom? : boolean;
|
|
18
29
|
hovered: boolean;
|
|
19
30
|
mouseEnterHandler: () => void;
|
|
20
31
|
mouseLeaveHandler: () => void;
|
|
@@ -23,6 +34,6 @@ export interface CellProps {
|
|
|
23
34
|
export interface TextCellProps {
|
|
24
35
|
label?: string;
|
|
25
36
|
emptyIndicator?: boolean;
|
|
26
|
-
additionalBorderBottom? : boolean;
|
|
27
37
|
hovered?: boolean;
|
|
38
|
+
sticky?: boolean;
|
|
28
39
|
}
|
|
@@ -2,9 +2,10 @@ import React from 'react';
|
|
|
2
2
|
import { createRoot } from 'react-dom/client';
|
|
3
3
|
import { Theme, validateLocale, validateToolParams } from '@oanda/labs-widget-common';
|
|
4
4
|
import { CurrencyCrossTableWidget } from './CurrencyCrossTableWidget';
|
|
5
|
-
import { Division } from '
|
|
5
|
+
import { Division } from '../gql/types/graphql';
|
|
6
6
|
|
|
7
7
|
const {
|
|
8
|
+
graphqlUrl,
|
|
8
9
|
liveRatesUrl,
|
|
9
10
|
} = window.widgetsConfig || {};
|
|
10
11
|
|
|
@@ -19,7 +20,7 @@ currencyCrossTableElements.forEach((element) => {
|
|
|
19
20
|
} = JSON.parse(params as string);
|
|
20
21
|
|
|
21
22
|
const isParamError = validateToolParams({
|
|
22
|
-
division, locale, currencies, liveRatesUrl,
|
|
23
|
+
division, locale, currencies, graphqlUrl, liveRatesUrl,
|
|
23
24
|
}, [{
|
|
24
25
|
name: 'locale',
|
|
25
26
|
valueCheck: (value) => validateLocale(value),
|
|
@@ -29,12 +30,15 @@ currencyCrossTableElements.forEach((element) => {
|
|
|
29
30
|
}, {
|
|
30
31
|
name: 'currencies',
|
|
31
32
|
valueCheck: (value) => (value as string[]).length > 0 && (value as string[]).length <= 8,
|
|
33
|
+
}, {
|
|
34
|
+
name: 'graphqlUrl',
|
|
32
35
|
}, {
|
|
33
36
|
name: 'liveRatesUrl',
|
|
34
37
|
}]);
|
|
35
38
|
|
|
36
39
|
root.render(
|
|
37
40
|
<CurrencyCrossTableWidget
|
|
41
|
+
graphqlUrl={graphqlUrl}
|
|
38
42
|
liveRatesUrl={liveRatesUrl}
|
|
39
43
|
division={division}
|
|
40
44
|
currencies={currencies}
|
|
@@ -1,22 +1,12 @@
|
|
|
1
1
|
import { Locale } from '@oanda/mono-i18n';
|
|
2
2
|
import { Theme } from '@oanda/labs-widget-common';
|
|
3
|
+
import { Division } from '../gql/types/graphql';
|
|
3
4
|
|
|
4
5
|
export { Locale } from '@oanda/mono-i18n';
|
|
5
6
|
|
|
6
|
-
export enum Division {
|
|
7
|
-
Oap = 'OAP',
|
|
8
|
-
Oau = 'OAU',
|
|
9
|
-
Oc = 'OC',
|
|
10
|
-
Ocan = 'OCAN',
|
|
11
|
-
Oel = 'OEL',
|
|
12
|
-
Ogm = 'OGM',
|
|
13
|
-
Oj = 'OJ',
|
|
14
|
-
Opt = 'OPT',
|
|
15
|
-
Otms = 'OTMS',
|
|
16
|
-
}
|
|
17
|
-
|
|
18
7
|
export interface CurrencyCrossTableConfig {
|
|
19
8
|
division: Division;
|
|
9
|
+
graphqlUrl: string;
|
|
20
10
|
liveRatesUrl: string;
|
|
21
11
|
currencies: string[];
|
|
22
12
|
locale: Locale;
|
|
@@ -33,4 +23,5 @@ export interface ValidationWrapperProps {
|
|
|
33
23
|
export interface MainProps {
|
|
34
24
|
currencies: string[];
|
|
35
25
|
instruments: string[];
|
|
26
|
+
division: Division;
|
|
36
27
|
}
|
|
@@ -1,60 +1,40 @@
|
|
|
1
|
-
import { useEffect, useState } from 'react';
|
|
2
|
-
import { DataRecord, LiveRatesErrorMessage, useLiveRatesMessage } from '@oanda/labs-widget-common';
|
|
3
1
|
import { MAJOR_CURRENCIES } from './constant';
|
|
2
|
+
import { Division } from '../gql/types/graphql';
|
|
4
3
|
|
|
5
4
|
const validCurrencies = (currencies: string[]) => currencies
|
|
6
5
|
.every((currency) => MAJOR_CURRENCIES.includes(currency));
|
|
7
6
|
|
|
8
|
-
const
|
|
9
|
-
const divisionMapper = division === 'OGM' ? '' : '_';
|
|
7
|
+
const divisionMapper = (division: Division) => (division === 'OGM' ? '' : '_');
|
|
10
8
|
|
|
9
|
+
const currenciesToInstruments = (currencies: string[], division: any) => {
|
|
11
10
|
const pairs = currencies.reduce((acc, cV, index, array) => {
|
|
12
11
|
const unique = array.filter((_item, idx) => index !== idx);
|
|
13
12
|
|
|
14
13
|
return [
|
|
15
14
|
...acc,
|
|
16
|
-
...unique.map((el) => `${cV}${divisionMapper}${el}`),
|
|
15
|
+
...unique.map((el) => `${cV}${divisionMapper(division)}${el}`),
|
|
17
16
|
];
|
|
18
17
|
}, [] as string[]);
|
|
19
18
|
|
|
20
19
|
return pairs;
|
|
21
20
|
};
|
|
22
21
|
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
const { update, error: liveRatesError } = useLiveRatesMessage(
|
|
35
|
-
record.instrument,
|
|
36
|
-
target,
|
|
37
|
-
);
|
|
38
|
-
|
|
39
|
-
useEffect(() => {
|
|
40
|
-
setUpdatedRecord({
|
|
41
|
-
displayName: record.displayName,
|
|
42
|
-
instrument: record.instrument,
|
|
43
|
-
buy: update?.ask,
|
|
44
|
-
buyPriceMovement: update?.askPriceMovement,
|
|
45
|
-
displayPrecision: update?.displayPrecision,
|
|
46
|
-
});
|
|
47
|
-
setError(liveRatesError);
|
|
48
|
-
}, [update, record, liveRatesError]);
|
|
49
|
-
|
|
50
|
-
return {
|
|
51
|
-
updatedRecord,
|
|
52
|
-
error,
|
|
53
|
-
};
|
|
22
|
+
const getPriceMovement = (priceMovement: number | undefined, isReversed: boolean) => {
|
|
23
|
+
if (priceMovement === undefined) return 0;
|
|
24
|
+
|
|
25
|
+
return isReversed ? priceMovement * -1 : priceMovement;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const getBuyPrice = (price: number | undefined, isReversed: boolean) => {
|
|
29
|
+
if (price === undefined) return 0;
|
|
30
|
+
|
|
31
|
+
return isReversed ? 1 / price : price;
|
|
54
32
|
};
|
|
55
33
|
|
|
56
34
|
export {
|
|
57
35
|
validCurrencies,
|
|
58
36
|
currenciesToInstruments,
|
|
59
|
-
|
|
37
|
+
divisionMapper,
|
|
38
|
+
getPriceMovement,
|
|
39
|
+
getBuyPrice,
|
|
60
40
|
};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { ResultOf, DocumentTypeDecoration, TypedDocumentNode } from '@graphql-typed-document-node/core';
|
|
2
|
+
import { FragmentDefinitionNode } from 'graphql';
|
|
3
|
+
import { Incremental } from './graphql';
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
export type FragmentType<TDocumentType extends DocumentTypeDecoration<any, any>> = TDocumentType extends DocumentTypeDecoration<
|
|
7
|
+
infer TType,
|
|
8
|
+
any
|
|
9
|
+
>
|
|
10
|
+
? [TType] extends [{ ' $fragmentName'?: infer TKey }]
|
|
11
|
+
? TKey extends string
|
|
12
|
+
? { ' $fragmentRefs'?: { [key in TKey]: TType } }
|
|
13
|
+
: never
|
|
14
|
+
: never
|
|
15
|
+
: never;
|
|
16
|
+
|
|
17
|
+
// return non-nullable if `fragmentType` is non-nullable
|
|
18
|
+
export function useFragment<TType>(
|
|
19
|
+
_documentNode: DocumentTypeDecoration<TType, any>,
|
|
20
|
+
fragmentType: FragmentType<DocumentTypeDecoration<TType, any>>
|
|
21
|
+
): TType;
|
|
22
|
+
// return nullable if `fragmentType` is nullable
|
|
23
|
+
export function useFragment<TType>(
|
|
24
|
+
_documentNode: DocumentTypeDecoration<TType, any>,
|
|
25
|
+
fragmentType: FragmentType<DocumentTypeDecoration<TType, any>> | null | undefined
|
|
26
|
+
): TType | null | undefined;
|
|
27
|
+
// return array of non-nullable if `fragmentType` is array of non-nullable
|
|
28
|
+
export function useFragment<TType>(
|
|
29
|
+
_documentNode: DocumentTypeDecoration<TType, any>,
|
|
30
|
+
fragmentType: ReadonlyArray<FragmentType<DocumentTypeDecoration<TType, any>>>
|
|
31
|
+
): ReadonlyArray<TType>;
|
|
32
|
+
// return array of nullable if `fragmentType` is array of nullable
|
|
33
|
+
export function useFragment<TType>(
|
|
34
|
+
_documentNode: DocumentTypeDecoration<TType, any>,
|
|
35
|
+
fragmentType: ReadonlyArray<FragmentType<DocumentTypeDecoration<TType, any>>> | null | undefined
|
|
36
|
+
): ReadonlyArray<TType> | null | undefined;
|
|
37
|
+
export function useFragment<TType>(
|
|
38
|
+
_documentNode: DocumentTypeDecoration<TType, any>,
|
|
39
|
+
fragmentType: FragmentType<DocumentTypeDecoration<TType, any>> | ReadonlyArray<FragmentType<DocumentTypeDecoration<TType, any>>> | null | undefined
|
|
40
|
+
): TType | ReadonlyArray<TType> | null | undefined {
|
|
41
|
+
return fragmentType as any;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
export function makeFragmentData<
|
|
46
|
+
F extends DocumentTypeDecoration<any, any>,
|
|
47
|
+
FT extends ResultOf<F>
|
|
48
|
+
>(data: FT, _fragment: F): FragmentType<F> {
|
|
49
|
+
return data as FragmentType<F>;
|
|
50
|
+
}
|
|
51
|
+
export function isFragmentReady<TQuery, TFrag>(
|
|
52
|
+
queryNode: DocumentTypeDecoration<TQuery, any>,
|
|
53
|
+
fragmentNode: TypedDocumentNode<TFrag>,
|
|
54
|
+
data: FragmentType<TypedDocumentNode<Incremental<TFrag>, any>> | null | undefined
|
|
55
|
+
): data is FragmentType<typeof fragmentNode> {
|
|
56
|
+
const deferredFields = (queryNode as { __meta__?: { deferredFields: Record<string, (keyof TFrag)[]> } }).__meta__
|
|
57
|
+
?.deferredFields;
|
|
58
|
+
|
|
59
|
+
if (!deferredFields) return true;
|
|
60
|
+
|
|
61
|
+
const fragDef = fragmentNode.definitions[0] as FragmentDefinitionNode | undefined;
|
|
62
|
+
const fragName = fragDef?.name?.value;
|
|
63
|
+
|
|
64
|
+
const fields = (fragName && deferredFields[fragName]) || [];
|
|
65
|
+
return fields.length > 0 && fields.every(field => data && field in data);
|
|
66
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
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 validateInstruments($instruments: [String]!, $division: Division) {\n mapInstrumentNames(instruments: $instruments, division: $division) {\n name\n displayName\n }\n }\n": types.ValidateInstrumentsDocument,
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
|
|
21
|
+
*
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```ts
|
|
25
|
+
* const query = graphql(`query GetUser($id: ID!) { user(id: $id) { name } }`);
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* The query argument is unknown!
|
|
29
|
+
* Please regenerate the types.
|
|
30
|
+
*/
|
|
31
|
+
export function graphql(source: string): unknown;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
|
|
35
|
+
*/
|
|
36
|
+
export function graphql(source: "\n query validateInstruments($instruments: [String]!, $division: Division) {\n mapInstrumentNames(instruments: $instruments, division: $division) {\n name\n displayName\n }\n }\n"): (typeof documents)["\n query validateInstruments($instruments: [String]!, $division: Division) {\n mapInstrumentNames(instruments: $instruments, division: $division) {\n name\n displayName\n }\n }\n"];
|
|
37
|
+
|
|
38
|
+
export function graphql(source: string) {
|
|
39
|
+
return (documents as any)[source] ?? {};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export type DocumentType<TDocumentNode extends DocumentNode<any, any>> = TDocumentNode extends DocumentNode< infer TType, any> ? TType : never;
|