From 39cc5743bf7a7f28dab64966c561bd39b1cf5585 Mon Sep 17 00:00:00 2001 From: Matthew Russell Date: Mon, 19 Sep 2022 13:12:13 -0700 Subject: [PATCH] chore: fix candles queries --- .../page-query-container.tsx | 5 +- .../src/lib/__generated__/Candles.ts | 113 ------------------ .../src/lib/__generated__/Chart.ts | 55 --------- libs/candles-chart/src/lib/data-source.ts | 19 +-- libs/candles-chart/src/lib/index.ts | 4 +- 5 files changed, 14 insertions(+), 182 deletions(-) delete mode 100644 libs/candles-chart/src/lib/__generated__/Candles.ts delete mode 100644 libs/candles-chart/src/lib/__generated__/Chart.ts diff --git a/apps/trading/components/page-query-container/page-query-container.tsx b/apps/trading/components/page-query-container/page-query-container.tsx index 60454ff9e..8d566c9de 100644 --- a/apps/trading/components/page-query-container/page-query-container.tsx +++ b/apps/trading/components/page-query-container/page-query-container.tsx @@ -15,10 +15,7 @@ export const PageQueryContainer = ({ options, render, }: PageQueryContainerProps) => { - const { data, loading, error } = useQuery(query, { - ...options, - errorPolicy: 'ignore', - }); + const { data, loading, error } = useQuery(query, options); return ( diff --git a/libs/candles-chart/src/lib/__generated__/Candles.ts b/libs/candles-chart/src/lib/__generated__/Candles.ts deleted file mode 100644 index 623e2ef77..000000000 --- a/libs/candles-chart/src/lib/__generated__/Candles.ts +++ /dev/null @@ -1,113 +0,0 @@ -import { Schema as Types } from '@vegaprotocol/types'; - -import { gql } from '@apollo/client'; -import * as Apollo from '@apollo/client'; -const defaultOptions = {} as const; -export type CandleFieldsFragment = { __typename?: 'Candle', timestamp: string, high: string, low: string, open: string, close: string, volume: string }; - -export type CandlesQueryVariables = Types.Exact<{ - marketId: Types.Scalars['ID']; - interval: Types.Interval; - since: Types.Scalars['String']; -}>; - - -export type CandlesQuery = { __typename?: 'Query', market?: { __typename?: 'Market', id: string, decimalPlaces: number, tradableInstrument: { __typename?: 'TradableInstrument', instrument: { __typename?: 'Instrument', id: string, name: string, code: string } }, candles?: Array<{ __typename?: 'Candle', timestamp: string, high: string, low: string, open: string, close: string, volume: string } | null> | null } | null }; - -export type CandlesEventsSubscriptionVariables = Types.Exact<{ - marketId: Types.Scalars['ID']; - interval: Types.Interval; -}>; - - -export type CandlesEventsSubscription = { __typename?: 'Subscription', candles: { __typename?: 'Candle', timestamp: string, high: string, low: string, open: string, close: string, volume: string } }; - -export const CandleFieldsFragmentDoc = gql` - fragment CandleFields on Candle { - periodStart - high - low - open - close - volume -} - `; -export const CandlesDocument = gql` - query Candles($marketId: ID!, $interval: Interval!, $since: String!) { - market(id: $marketId) { - id - decimalPlaces - tradableInstrument { - instrument { - id - name - code - } - } - candles(interval: $interval, since: $since) { - ...CandleFields - } - } -} - ${CandleFieldsFragmentDoc}`; - -/** - * __useCandlesQuery__ - * - * To run a query within a React component, call `useCandlesQuery` and pass it any options that fit your needs. - * When your component renders, `useCandlesQuery` returns an object from Apollo Client that contains loading, error, and data properties - * you can use to render your UI. - * - * @param baseOptions options that will be passed into the query, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options; - * - * @example - * const { data, loading, error } = useCandlesQuery({ - * variables: { - * marketId: // value for 'marketId' - * interval: // value for 'interval' - * since: // value for 'since' - * }, - * }); - */ -export function useCandlesQuery(baseOptions: Apollo.QueryHookOptions) { - const options = {...defaultOptions, ...baseOptions} - return Apollo.useQuery(CandlesDocument, options); - } -export function useCandlesLazyQuery(baseOptions?: Apollo.LazyQueryHookOptions) { - const options = {...defaultOptions, ...baseOptions} - return Apollo.useLazyQuery(CandlesDocument, options); - } -export type CandlesQueryHookResult = ReturnType; -export type CandlesLazyQueryHookResult = ReturnType; -export type CandlesQueryResult = Apollo.QueryResult; -export const CandlesEventsDocument = gql` - subscription CandlesEvents($marketId: ID!, $interval: Interval!) { - candles(marketId: $marketId, interval: $interval) { - ...CandleFields - } -} - ${CandleFieldsFragmentDoc}`; - -/** - * __useCandlesEventsSubscription__ - * - * To run a query within a React component, call `useCandlesEventsSubscription` and pass it any options that fit your needs. - * When your component renders, `useCandlesEventsSubscription` returns an object from Apollo Client that contains loading, error, and data properties - * you can use to render your UI. - * - * @param baseOptions options that will be passed into the subscription, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options; - * - * @example - * const { data, loading, error } = useCandlesEventsSubscription({ - * variables: { - * marketId: // value for 'marketId' - * interval: // value for 'interval' - * }, - * }); - */ -export function useCandlesEventsSubscription(baseOptions: Apollo.SubscriptionHookOptions) { - const options = {...defaultOptions, ...baseOptions} - return Apollo.useSubscription(CandlesEventsDocument, options); - } -export type CandlesEventsSubscriptionHookResult = ReturnType; -export type CandlesEventsSubscriptionResult = Apollo.SubscriptionResult; \ No newline at end of file diff --git a/libs/candles-chart/src/lib/__generated__/Chart.ts b/libs/candles-chart/src/lib/__generated__/Chart.ts deleted file mode 100644 index fec36dd6f..000000000 --- a/libs/candles-chart/src/lib/__generated__/Chart.ts +++ /dev/null @@ -1,55 +0,0 @@ -import { Schema as Types } from '@vegaprotocol/types'; - -import { gql } from '@apollo/client'; -import * as Apollo from '@apollo/client'; -const defaultOptions = {} as const; -export type ChartQueryVariables = Types.Exact<{ - marketId: Types.Scalars['ID']; -}>; - - -export type ChartQuery = { __typename?: 'Query', market?: { __typename?: 'Market', decimalPlaces: number, data?: { __typename?: 'MarketData', priceMonitoringBounds?: Array<{ __typename?: 'PriceMonitoringBounds', minValidPrice: string, maxValidPrice: string, referencePrice: string }> | null } | null } | null }; - - -export const ChartDocument = gql` - query Chart($marketId: ID!) { - market(id: $marketId) { - decimalPlaces - data { - priceMonitoringBounds { - minValidPrice - maxValidPrice - referencePrice - } - } - } -} - `; - -/** - * __useChartQuery__ - * - * To run a query within a React component, call `useChartQuery` and pass it any options that fit your needs. - * When your component renders, `useChartQuery` returns an object from Apollo Client that contains loading, error, and data properties - * you can use to render your UI. - * - * @param baseOptions options that will be passed into the query, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options; - * - * @example - * const { data, loading, error } = useChartQuery({ - * variables: { - * marketId: // value for 'marketId' - * }, - * }); - */ -export function useChartQuery(baseOptions: Apollo.QueryHookOptions) { - const options = {...defaultOptions, ...baseOptions} - return Apollo.useQuery(ChartDocument, options); - } -export function useChartLazyQuery(baseOptions?: Apollo.LazyQueryHookOptions) { - const options = {...defaultOptions, ...baseOptions} - return Apollo.useLazyQuery(ChartDocument, options); - } -export type ChartQueryHookResult = ReturnType; -export type ChartLazyQueryHookResult = ReturnType; -export type ChartQueryResult = Apollo.QueryResult; \ No newline at end of file diff --git a/libs/candles-chart/src/lib/data-source.ts b/libs/candles-chart/src/lib/data-source.ts index f600f93a9..55adbe461 100644 --- a/libs/candles-chart/src/lib/data-source.ts +++ b/libs/candles-chart/src/lib/data-source.ts @@ -1,21 +1,22 @@ +import compact from 'lodash/compact'; import type { ApolloClient } from '@apollo/client'; import type { Candle, DataSource } from 'pennant'; import { Interval as PennantInterval } from 'pennant'; import { addDecimal } from '@vegaprotocol/react-helpers'; -import { ChartDocument } from './__generated__/Chart'; -import type { ChartQuery, ChartQueryVariables } from './__generated__/Chart'; +import { ChartDocument } from './__generated___/Chart'; +import type { ChartQuery, ChartQueryVariables } from './__generated___/Chart'; import { CandlesDocument, CandlesEventsDocument, -} from './__generated__/Candles'; +} from './__generated___/Candles'; import type { CandlesQuery, CandlesQueryVariables, CandleFieldsFragment, CandlesEventsSubscription, CandlesEventsSubscriptionVariables, -} from './__generated__/Candles'; +} from './__generated___/Candles'; import type { Subscription } from 'zen-observable-ts'; import { Interval } from '@vegaprotocol/types'; @@ -142,14 +143,15 @@ export class VegaDataSource implements DataSource { }, fetchPolicy: 'no-cache', }); + console.log(data); - if (data && data.market && data.market.candles) { + if (data && data.market && data.market.candlesConnection) { const decimalPlaces = data.market.decimalPlaces; - const candles = data.market.candles + const candles = compact(data.market.candlesConnection.edges) + .map((e) => e.node) .filter((d): d is CandleFieldsFragment => d !== null) .map((d) => parseCandle(d, decimalPlaces)); - return candles; } else { return []; @@ -198,8 +200,9 @@ function parseCandle( candle: CandleFieldsFragment, decimalPlaces: number ): Candle { + console.log(candle); return { - date: new Date(Number(candle.timestamp) / 1_000_000), + date: new Date(candle.periodStart), high: Number(addDecimal(candle.high, decimalPlaces)), low: Number(addDecimal(candle.low, decimalPlaces)), open: Number(addDecimal(candle.open, decimalPlaces)), diff --git a/libs/candles-chart/src/lib/index.ts b/libs/candles-chart/src/lib/index.ts index fec9df1f3..b09081938 100644 --- a/libs/candles-chart/src/lib/index.ts +++ b/libs/candles-chart/src/lib/index.ts @@ -1,4 +1,4 @@ -export * from './__generated__/Candles'; -export * from './__generated__/Chart'; +export * from './__generated___/Candles'; +export * from './__generated___/Chart'; export * from './candles-chart'; export * from './data-source';