fix(trading): error guards not working when poll interval is supplied (#5661)

Co-authored-by: Madalina Raicu <madalina@raygroup.uk>
Co-authored-by: Dariusz Majcherczyk <dariusz.majcherczyk@gmail.com>
This commit is contained in:
Matthew Russell 2024-01-25 02:59:40 -05:00 committed by GitHub
parent 6aea10c27b
commit 67d38ff03e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 87 additions and 133 deletions

View File

@ -10,15 +10,18 @@ import logging
logger = logging.getLogger() logger = logging.getLogger()
@pytest.fixture(scope="class") @pytest.fixture(scope="class")
def vega(): def vega():
with init_vega() as vega: with init_vega() as vega:
yield vega yield vega
@pytest.fixture(scope="class") @pytest.fixture(scope="class")
def simple_market(vega: VegaServiceNull): def simple_market(vega: VegaServiceNull):
return setup_simple_market(vega) return setup_simple_market(vega)
class TestGetStarted: class TestGetStarted:
def test_get_started_interactive(self, vega: VegaServiceNull, page: Page): def test_get_started_interactive(self, vega: VegaServiceNull, page: Page):
page.goto("/") page.goto("/")
@ -30,7 +33,8 @@ class TestGetStarted:
expect(page.locator(".list-none")).to_contain_text( expect(page.locator(".list-none")).to_contain_text(
"1.Connect2.Deposit funds3.Open a position" "1.Connect2.Deposit funds3.Open a position"
) )
DEFAULT_WALLET_NAME = "MarketSim" # This is the default wallet name within VegaServiceNull and CANNOT be changed # This is the default wallet name within VegaServiceNull and CANNOT be changed
DEFAULT_WALLET_NAME = "MarketSim"
# Calling get_keypairs will internally call _load_tokens for the given wallet # Calling get_keypairs will internally call _load_tokens for the given wallet
keypairs = vega.wallet.get_keypairs(DEFAULT_WALLET_NAME) keypairs = vega.wallet.get_keypairs(DEFAULT_WALLET_NAME)
@ -137,7 +141,8 @@ class TestGetStarted:
def test_get_started_seen_already(self, simple_market, page: Page): def test_get_started_seen_already(self, simple_market, page: Page):
page.goto(f"/#/markets/{simple_market}") page.goto(f"/#/markets/{simple_market}")
get_started_locator = page.get_by_test_id("connect-vega-wallet") get_started_locator = page.get_by_test_id("connect-vega-wallet")
page.wait_for_selector('[data-testid="connect-vega-wallet"]', state="attached") page.wait_for_selector(
'[data-testid="connect-vega-wallet"]', state="attached")
expect(get_started_locator).to_be_enabled expect(get_started_locator).to_be_enabled
expect(get_started_locator).to_be_visible expect(get_started_locator).to_be_visible
# 0007-FUGS-015 # 0007-FUGS-015

View File

@ -36,16 +36,19 @@ def validate_info_section(page: Page, fields: [[str, str]]):
for rowNumber, field in enumerate(fields): for rowNumber, field in enumerate(fields):
name, value = field name, value = field
expect( expect(
page.get_by_test_id("key-value-table-row").nth(rowNumber).locator("dt") page.get_by_test_id(
"key-value-table-row").nth(rowNumber).locator("dt")
).to_contain_text(name) ).to_contain_text(name)
expect( expect(
page.get_by_test_id("key-value-table-row").nth(rowNumber).locator("dd") page.get_by_test_id(
"key-value-table-row").nth(rowNumber).locator("dd")
).to_contain_text(value) ).to_contain_text(value)
@pytest.mark.skip("tbd-market-sim")
def test_market_info_current_fees(page: Page): def test_market_info_current_fees(page: Page):
# 6002-MDET-101 # 6002-MDET-101
page.get_by_test_id(market_title_test_id).get_by_text("Current fees").click() page.get_by_test_id(market_title_test_id).get_by_text(
"Current fees").click()
fields = [ fields = [
["Maker Fee", "10%"], ["Maker Fee", "10%"],
["Infrastructure Fee", "0.05%"], ["Infrastructure Fee", "0.05%"],
@ -54,10 +57,11 @@ def test_market_info_current_fees(page: Page):
] ]
validate_info_section(page, fields) validate_info_section(page, fields)
@pytest.mark.skip("tbd-market-sim")
def test_market_info_market_price(page: Page): def test_market_info_market_price(page: Page):
# 6002-MDET-102 # 6002-MDET-102
page.get_by_test_id(market_title_test_id).get_by_text("Market price").click() page.get_by_test_id(market_title_test_id).get_by_text(
"Market price").click()
fields = [ fields = [
["Mark Price", "107.50"], ["Mark Price", "107.50"],
["Best Bid Price", "101.50"], ["Best Bid Price", "101.50"],
@ -66,10 +70,11 @@ def test_market_info_market_price(page: Page):
] ]
validate_info_section(page, fields) validate_info_section(page, fields)
@pytest.mark.skip("tbd-market-sim")
def test_market_info_market_volume(page: Page): def test_market_info_market_volume(page: Page):
# 6002-MDET-103 # 6002-MDET-103
page.get_by_test_id(market_title_test_id).get_by_text("Market volume").click() page.get_by_test_id(market_title_test_id).get_by_text(
"Market volume").click()
fields = [ fields = [
["24 Hour Volume", "-"], ["24 Hour Volume", "-"],
["Open Interest", "1"], ["Open Interest", "1"],
@ -80,17 +85,19 @@ def test_market_info_market_volume(page: Page):
] ]
validate_info_section(page, fields) validate_info_section(page, fields)
@pytest.mark.skip("tbd-market-sim")
def test_market_info_insurance_pool(page: Page): def test_market_info_insurance_pool(page: Page):
# 6002-MDET-104 # 6002-MDET-104
page.get_by_test_id(market_title_test_id).get_by_text("Insurance pool").click() page.get_by_test_id(market_title_test_id).get_by_text(
"Insurance pool").click()
fields = [["Balance", "0.00 tDAI"]] fields = [["Balance", "0.00 tDAI"]]
validate_info_section(page, fields) validate_info_section(page, fields)
@pytest.mark.skip("tbd-market-sim")
def test_market_info_key_details(page: Page, vega: VegaServiceNull): def test_market_info_key_details(page: Page, vega: VegaServiceNull):
# 6002-MDET-201 # 6002-MDET-201
page.get_by_test_id(market_title_test_id).get_by_text("Key details").click() page.get_by_test_id(market_title_test_id).get_by_text(
"Key details").click()
market_id = vega.find_market_id("BTC:DAI_2023") market_id = vega.find_market_id("BTC:DAI_2023")
short_market_id = market_id[:6] + "" + market_id[-4:] short_market_id = market_id[:6] + "" + market_id[-4:]
fields = [ fields = [
@ -106,7 +113,7 @@ def test_market_info_key_details(page: Page, vega: VegaServiceNull):
] ]
validate_info_section(page, fields) validate_info_section(page, fields)
@pytest.mark.skip("tbd-market-sim")
def test_market_info_instrument(page: Page): def test_market_info_instrument(page: Page):
# 6002-MDET-202 # 6002-MDET-202
page.get_by_test_id(market_title_test_id).get_by_text("Instrument").click() page.get_by_test_id(market_title_test_id).get_by_text("Instrument").click()
@ -121,7 +128,7 @@ def test_market_info_instrument(page: Page):
# @pytest.mark.skip("oracle test to be fixed") # @pytest.mark.skip("oracle test to be fixed")
@pytest.mark.skip("tbd-market-sim")
def test_market_info_oracle(page: Page): def test_market_info_oracle(page: Page):
# 6002-MDET-203 # 6002-MDET-203
page.get_by_test_id(market_title_test_id).get_by_text("Oracle").click() page.get_by_test_id(market_title_test_id).get_by_text("Oracle").click()
@ -135,10 +142,11 @@ def test_market_info_oracle(page: Page):
# "href", re.compile(rf'(\/oracles\/{vega.find_market_id("BTC:DAI_2023")})') # "href", re.compile(rf'(\/oracles\/{vega.find_market_id("BTC:DAI_2023")})')
# ) # )
@pytest.mark.skip("tbd-market-sim")
def test_market_info_settlement_asset(page: Page, vega: VegaServiceNull): def test_market_info_settlement_asset(page: Page, vega: VegaServiceNull):
# 6002-MDET-206 # 6002-MDET-206
page.get_by_test_id(market_title_test_id).get_by_text("Settlement asset").click() page.get_by_test_id(market_title_test_id).get_by_text(
"Settlement asset").click()
tdai_id = vega.find_asset_id("tDAI") tdai_id = vega.find_asset_id("tDAI")
tdai_id_short = tdai_id[:6] + "" + tdai_id[-4:] tdai_id_short = tdai_id[:6] + "" + tdai_id[-4:]
fields = [ fields = [
@ -155,7 +163,7 @@ def test_market_info_settlement_asset(page: Page, vega: VegaServiceNull):
] ]
validate_info_section(page, fields) validate_info_section(page, fields)
@pytest.mark.skip("tbd-market-sim")
def test_market_info_metadata(page: Page): def test_market_info_metadata(page: Page):
# 6002-MDET-207 # 6002-MDET-207
page.get_by_test_id(market_title_test_id).get_by_text("Metadata").click() page.get_by_test_id(market_title_test_id).get_by_text("Metadata").click()
@ -164,7 +172,7 @@ def test_market_info_metadata(page: Page):
] ]
validate_info_section(page, fields) validate_info_section(page, fields)
@pytest.mark.skip("tbd-market-sim")
def test_market_info_risk_model(page: Page): def test_market_info_risk_model(page: Page):
# 6002-MDET-208 # 6002-MDET-208
page.get_by_test_id(market_title_test_id).get_by_text("Risk model").click() page.get_by_test_id(market_title_test_id).get_by_text("Risk model").click()
@ -175,7 +183,7 @@ def test_market_info_risk_model(page: Page):
] ]
validate_info_section(page, fields) validate_info_section(page, fields)
@pytest.mark.skip("tbd-market-sim")
def test_market_info_margin_scaling_factors(page: Page): def test_market_info_margin_scaling_factors(page: Page):
# 6002-MDET-209 # 6002-MDET-209
page.get_by_test_id(market_title_test_id).get_by_text( page.get_by_test_id(market_title_test_id).get_by_text(
@ -183,17 +191,17 @@ def test_market_info_margin_scaling_factors(page: Page):
).click() ).click()
fields = [ fields = [
["Linear Slippage Factor", "0.001"], ["Linear Slippage Factor", "0.001"],
["Quadratic Slippage Factor", "0"],
["Search Level", "1.1"], ["Search Level", "1.1"],
["Initial Margin", "1.5"], ["Initial Margin", "1.5"],
["Collateral Release", "1.7"], ["Collateral Release", "1.7"],
] ]
validate_info_section(page, fields) validate_info_section(page, fields)
@pytest.mark.skip("tbd-market-sim")
def test_market_info_risk_factors(page: Page): def test_market_info_risk_factors(page: Page):
# 6002-MDET-210 # 6002-MDET-210
page.get_by_test_id(market_title_test_id).get_by_text("Risk factors").click() page.get_by_test_id(market_title_test_id).get_by_text(
"Risk factors").click()
fields = [ fields = [
["Long", "0.05153"], ["Long", "0.05153"],
["Short", "0.05422"], ["Short", "0.05422"],
@ -204,7 +212,7 @@ def test_market_info_risk_factors(page: Page):
] ]
validate_info_section(page, fields) validate_info_section(page, fields)
@pytest.mark.skip("tbd-market-sim")
def test_market_info_price_monitoring_bounds(page: Page): def test_market_info_price_monitoring_bounds(page: Page):
# 6002-MDET-211 # 6002-MDET-211
page.get_by_test_id(market_title_test_id).get_by_text( page.get_by_test_id(market_title_test_id).get_by_text(
@ -213,27 +221,27 @@ def test_market_info_price_monitoring_bounds(page: Page):
expect(page.locator("p.col-span-1").nth(0)).to_contain_text( expect(page.locator("p.col-span-1").nth(0)).to_contain_text(
"99.9999% probability price bounds" "99.9999% probability price bounds"
) )
expect(page.locator("p.col-span-1").nth(1)).to_contain_text("Within 86,400 seconds") expect(page.locator("p.col-span-1").nth(1)
).to_contain_text("Within 86,400 seconds")
fields = [ fields = [
["Highest Price", "138.66685 BTC"], ["Highest Price", "138.66685 BTC"],
["Lowest Price", "83.11038 BTC"], ["Lowest Price", "83.11038 BTC"],
] ]
validate_info_section(page, fields) validate_info_section(page, fields)
@pytest.mark.skip("tbd-market-sim")
def test_market_info_liquidity_monitoring_parameters(page: Page): def test_market_info_liquidity_monitoring_parameters(page: Page):
# 6002-MDET-212 # 6002-MDET-212
page.get_by_test_id(market_title_test_id).get_by_text( page.get_by_test_id(market_title_test_id).get_by_text(
"Liquidity monitoring parameters" "Liquidity monitoring parameters"
).click() ).click()
fields = [ fields = [
["Triggering Ratio", "0.7"],
["Time Window", "3,600"], ["Time Window", "3,600"],
["Scaling Factor", "1"], ["Scaling Factor", "1"],
] ]
validate_info_section(page, fields) validate_info_section(page, fields)
@pytest.mark.skip("tbd-market-sim")
# Liquidity resolves to 3 results # Liquidity resolves to 3 results
def test_market_info_liquidit(page: Page): def test_market_info_liquidit(page: Page):
# 6002-MDET-213 # 6002-MDET-213
@ -246,7 +254,7 @@ def test_market_info_liquidit(page: Page):
] ]
validate_info_section(page, fields) validate_info_section(page, fields)
@pytest.mark.skip("tbd-market-sim")
def test_market_info_liquidity_price_range(page: Page): def test_market_info_liquidity_price_range(page: Page):
# 6002-MDET-214 # 6002-MDET-214
page.get_by_test_id(market_title_test_id).get_by_text( page.get_by_test_id(market_title_test_id).get_by_text(
@ -259,19 +267,22 @@ def test_market_info_liquidity_price_range(page: Page):
] ]
validate_info_section(page, fields) validate_info_section(page, fields)
@pytest.mark.skip("tbd-market-sim")
def test_market_info_proposal(page: Page, vega: VegaServiceNull): def test_market_info_proposal(page: Page, vega: VegaServiceNull):
# 6002-MDET-301 # 6002-MDET-301
page.get_by_test_id(market_title_test_id).get_by_text("Proposal").click() page.get_by_test_id(market_title_test_id).get_by_text("Proposal").click()
first_link = ( first_link = (
page.get_by_test_id("accordion-content").get_by_test_id("external-link").first page.get_by_test_id(
"accordion-content").get_by_test_id("external-link").first
) )
second_link = ( second_link = (
page.get_by_test_id("accordion-content").get_by_test_id("external-link").nth(1) page.get_by_test_id(
"accordion-content").get_by_test_id("external-link").nth(1)
) )
expect(first_link).to_have_text("View governance proposal") expect(first_link).to_have_text("View governance proposal")
expect(first_link).to_have_attribute( expect(first_link).to_have_attribute(
"href", re.compile(rf'(\/proposals\/{vega.find_market_id("BTC:DAI_2023")})') "href", re.compile(
rf'(\/proposals\/{vega.find_market_id("BTC:DAI_2023")})')
) )
expect(second_link).to_have_text("Propose a change to market") expect(second_link).to_have_text("Propose a change to market")
@ -280,13 +291,14 @@ def test_market_info_proposal(page: Page, vega: VegaServiceNull):
"href", re.compile(r"(\/proposals\/propose\/update-market)") "href", re.compile(r"(\/proposals\/propose\/update-market)")
) )
@pytest.mark.skip("tbd-market-sim")
def test_market_info_succession_line(page: Page, vega: VegaServiceNull): def test_market_info_succession_line(page: Page, vega: VegaServiceNull):
page.get_by_test_id(market_title_test_id).get_by_text("Succession line").click() page.get_by_test_id(market_title_test_id).get_by_text(
"Succession line").click()
market_id = vega.find_market_id("BTC:DAI_2023") market_id = vega.find_market_id("BTC:DAI_2023")
succession_line = page.get_by_test_id("succession-line-item") succession_line = page.get_by_test_id("succession-line-item")
expect(succession_line.get_by_test_id("external-link")).to_have_text("BTC:DAI_2023") expect(succession_line.get_by_test_id(
"external-link")).to_have_text("BTC:DAI_2023")
expect(succession_line.get_by_test_id("external-link")).to_have_attribute( expect(succession_line.get_by_test_id("external-link")).to_have_attribute(
"href", re.compile(rf"(\/proposals\/{market_id})") "href", re.compile(rf"(\/proposals\/{market_id})")
) )

View File

@ -8,7 +8,7 @@ from actions.utils import next_epoch
market_banner = "market-banner" market_banner = "market-banner"
@pytest.mark.skip("tbd")
@pytest.mark.usefixtures("risk_accepted") @pytest.mark.usefixtures("risk_accepted")
def test_succession_line(vega: VegaServiceNull, page: Page): def test_succession_line(vega: VegaServiceNull, page: Page):
parent_market_id = setup_continuous_market(vega) parent_market_id = setup_continuous_market(vega)
@ -20,12 +20,14 @@ def test_succession_line(vega: VegaServiceNull, page: Page):
expect(page.get_by_test_id(market_banner)).not_to_be_attached() expect(page.get_by_test_id(market_banner)).not_to_be_attached()
successor_name = "successor market name" successor_name = "successor market name"
successor_id = propose_successor(vega, parent_market_id, tdai_id, successor_name) successor_id = propose_successor(
vega, parent_market_id, tdai_id, successor_name)
# Check that the banner notifying about the successor proposal is shown # Check that the banner notifying about the successor proposal is shown
banner = page.get_by_test_id(market_banner) banner = page.get_by_test_id(market_banner)
expect(banner).to_be_attached() expect(banner).to_be_attached()
expect(banner.get_by_text("A successor to this market has been proposed")).to_be_visible() expect(banner.get_by_text(
"A successor to this market has been proposed")).to_be_visible()
next_epoch(vega) next_epoch(vega)
@ -45,7 +47,6 @@ def test_succession_line(vega: VegaServiceNull, page: Page):
# the succession line # the succession line
page.reload() page.reload()
#tbd issue - 5546
page.get_by_test_id("Info").click() page.get_by_test_id("Info").click()
page.get_by_role("button", name="Succession line").click() page.get_by_role("button", name="Succession line").click()
@ -78,6 +79,7 @@ def test_succession_line(vega: VegaServiceNull, page: Page):
page.wait_for_selector('[data-testid="market-banner"]', state="attached") page.wait_for_selector('[data-testid="market-banner"]', state="attached")
expect(banner.get_by_text("This market has been succeeded")).to_be_visible() expect(banner.get_by_text("This market has been succeeded")).to_be_visible()
@pytest.mark.usefixtures("risk_accepted") @pytest.mark.usefixtures("risk_accepted")
def test_banners(vega: VegaServiceNull, page: Page): def test_banners(vega: VegaServiceNull, page: Page):
@ -91,9 +93,9 @@ def test_banners(vega: VegaServiceNull, page: Page):
expect(page.get_by_test_id(market_banner)).not_to_be_attached() expect(page.get_by_test_id(market_banner)).not_to_be_attached()
vega.submit_termination_and_settlement_data( vega.submit_termination_and_settlement_data(
settlement_key=GOVERNANCE_WALLET.name, settlement_key=GOVERNANCE_WALLET.name,
settlement_price=100, settlement_price=100,
market_id=parent_market_id, market_id=parent_market_id,
) )
successor_name = "successor market name" successor_name = "successor market name"
@ -108,7 +110,7 @@ def test_banners(vega: VegaServiceNull, page: Page):
# Check that the banner notifying about the successor proposal and market has been settled are shown still after reload # Check that the banner notifying about the successor proposal and market has been settled are shown still after reload
page.reload() page.reload()
expect(banner.get_by_text(banner_successor_text)).to_be_visible() expect(banner.get_by_text(banner_successor_text)).to_be_visible()
expect(banner.get_by_text("1/2")).to_be_visible() expect(banner.get_by_text("1/2")).to_be_visible()
# Check that the banner notifying about the successor proposal is not visible after close those banners # Check that the banner notifying about the successor proposal is not visible after close those banners
banner.get_by_test_id("icon-cross").click() banner.get_by_test_id("icon-cross").click()
expect(banner.get_by_text("This market has been settled")).to_be_visible() expect(banner.get_by_text("This market has been settled")).to_be_visible()
@ -119,7 +121,8 @@ def test_banners(vega: VegaServiceNull, page: Page):
expect(page.get_by_test_id(market_banner)).not_to_be_attached() expect(page.get_by_test_id(market_banner)).not_to_be_attached()
page.reload() page.reload()
expect(banner).to_be_attached() expect(banner).to_be_attached()
expect(banner.get_by_text(banner_successor_text)).to_be_visible() expect(banner.get_by_text(banner_successor_text)).to_be_visible()
def propose_successor( def propose_successor(
vega: VegaServiceNull, parent_market_id, tdai_id, market_name vega: VegaServiceNull, parent_market_id, tdai_id, market_name
@ -137,6 +140,7 @@ def propose_successor(
) )
return market_id return market_id
def provide_successor_liquidity( def provide_successor_liquidity(
vega: VegaServiceNull, market_id vega: VegaServiceNull, market_id
): ):

View File

@ -29,6 +29,7 @@ export const assetsProvider = makeDataProvider<
>({ >({
query: AssetsDocument, query: AssetsDocument,
getData, getData,
errorPolicy: 'all',
}); });
export const assetsMapProvider = makeDerivedDataProvider< export const assetsMapProvider = makeDerivedDataProvider<

View File

@ -22,11 +22,9 @@ import {
type QueryOptions, type QueryOptions,
type ApolloClient, type ApolloClient,
} from '@apollo/client'; } from '@apollo/client';
import { ApolloError } from '@apollo/client'; import { type ApolloError } from '@apollo/client';
import type { GraphQLErrors } from '@apollo/client/errors';
import { GraphQLError } from 'graphql'; import { GraphQLError } from 'graphql';
import { type Subscription, type Observable } from 'zen-observable-ts'; import { type Subscription, type Observable } from 'zen-observable-ts';
import { waitFor } from '@testing-library/react';
type Item = { type Item = {
cursor: string; cursor: string;
@ -117,24 +115,6 @@ const paginatedSubscribe = makeDataProvider<
}, },
}); });
const mockErrorPolicyGuard: (errors: GraphQLErrors) => boolean = jest
.fn()
.mockImplementation(() => true);
const errorGuardedSubscribe = makeDataProvider<
QueryData,
Data,
SubscriptionData,
Delta,
Variables
>({
query,
subscriptionQuery,
update,
getData,
getDelta,
errorPolicyGuard: mockErrorPolicyGuard,
});
const derivedSubscribe = makeDerivedDataProvider( const derivedSubscribe = makeDerivedDataProvider(
[paginatedSubscribe, subscribe], [paginatedSubscribe, subscribe],
combineData, combineData,
@ -404,34 +384,6 @@ describe('data provider', () => {
subscription.unsubscribe(); subscription.unsubscribe();
}); });
it('should retry with ignore error policy if errorPolicyGuard returns true', async () => {
const subscription = errorGuardedSubscribe(callback, client, variables);
const graphQLError = new GraphQLError(
'',
undefined,
undefined,
undefined,
['market', 'data'],
undefined,
{
type: 'Internal',
}
);
const graphQLErrors = [graphQLError];
const error = new ApolloError({ graphQLErrors });
await rejectQuery(error);
const data = generateData(0, 5);
await resolveQuery({
data,
});
expect(mockErrorPolicyGuard).toHaveBeenNthCalledWith(1, graphQLErrors);
await waitFor(() =>
expect(getData).toHaveBeenCalledWith({ data }, variables)
);
subscription.unsubscribe();
});
}); });
describe('derived data provider', () => { describe('derived data provider', () => {

View File

@ -9,7 +9,6 @@ import type {
ApolloQueryResult, ApolloQueryResult,
QueryOptions, QueryOptions,
} from '@apollo/client'; } from '@apollo/client';
import type { GraphQLErrors } from '@apollo/client/errors';
import type { Subscription } from 'zen-observable-ts'; import type { Subscription } from 'zen-observable-ts';
import isEqualWith from 'lodash/isEqualWith'; import isEqualWith from 'lodash/isEqualWith';
import { isNotFoundGraphQLError } from './helpers'; import { isNotFoundGraphQLError } from './helpers';
@ -161,7 +160,7 @@ interface DataProviderParams<
resetDelay?: number; resetDelay?: number;
pollInterval?: number; pollInterval?: number;
additionalContext?: Record<string, unknown>; additionalContext?: Record<string, unknown>;
errorPolicyGuard?: (graphqlErrors: GraphQLErrors) => boolean; errorPolicy?: ErrorPolicy;
getQueryVariables?: (variables: Variables) => QueryVariables; getQueryVariables?: (variables: Variables) => QueryVariables;
getSubscriptionVariables?: ( getSubscriptionVariables?: (
variables: Variables variables: Variables
@ -176,7 +175,7 @@ interface DataProviderParams<
* @param fetchPolicy * @param fetchPolicy
* @param resetDelay * @param resetDelay
* @param additionalContext add property to the context of the query, ie. 'isEnlargedTimeout' * @param additionalContext add property to the context of the query, ie. 'isEnlargedTimeout'
* @param errorPolicyGuard indicate which gql errors can be tolerate * @param errorPolicy Apollos error policy, will be used when querying
* @returns subscribe function * @returns subscribe function
*/ */
function makeDataProviderInternal< function makeDataProviderInternal<
@ -197,7 +196,7 @@ function makeDataProviderInternal<
fetchPolicy, fetchPolicy,
resetDelay, resetDelay,
additionalContext, additionalContext,
errorPolicyGuard, errorPolicy = 'none',
getQueryVariables, getQueryVariables,
getSubscriptionVariables, getSubscriptionVariables,
pollInterval, pollInterval,
@ -331,20 +330,10 @@ function makeDataProviderInternal<
const callQuery = ( const callQuery = (
pagination?: Pagination, pagination?: Pagination,
policy?: ErrorPolicy policy?: ErrorPolicy
): Promise<ApolloQueryResult<QueryData>> => ): Promise<ApolloQueryResult<QueryData>> => {
client const options = getQueryOptions(pagination, policy);
.query<QueryData>(getQueryOptions(pagination, policy)) return client.query<QueryData>(options);
.catch((err) => { };
if (
err.graphQLErrors &&
errorPolicyGuard &&
errorPolicyGuard(err.graphQLErrors)
) {
return callQuery(pagination, 'ignore');
} else {
throw err;
}
});
const load = async () => { const load = async () => {
if (!pagination) { if (!pagination) {
@ -364,7 +353,7 @@ function makeDataProviderInternal<
} }
} }
const res = await callQuery(paginationVariables); const res = await callQuery(paginationVariables, errorPolicy);
const insertionData = getData(res.data, variables); const insertionData = getData(res.data, variables);
const insertionPageInfo = pagination.getPageInfo(res.data); const insertionPageInfo = pagination.getPageInfo(res.data);
@ -417,12 +406,14 @@ function makeDataProviderInternal<
const paginationVariables = pagination const paginationVariables = pagination
? { first: pagination.first } ? { first: pagination.first }
: undefined; : undefined;
if (pollInterval) { if (pollInterval) {
callWatchQuery(); callWatchQuery(paginationVariables, errorPolicy);
return; return;
} }
try { try {
onNext(await callQuery(paginationVariables)); onNext(await callQuery(paginationVariables, errorPolicy));
} catch (e) { } catch (e) {
onError(e as Error); onError(e as Error);
} finally { } finally {

View File

@ -27,10 +27,3 @@ const hasNotFoundGraphQLErrors = (errors: GraphQLErrors, path?: string[]) => {
(!path || path.every((item, i) => item === e?.path?.[i])) (!path || path.every((item, i) => item === e?.path?.[i]))
); );
}; };
export const marketDataErrorPolicyGuard = (errors: GraphQLErrors) =>
errors.every(
(e) =>
e.message.match(/no market data for market:/i) ||
e.message.match(/Conditions list is empty/)
);

View File

@ -1,7 +1,6 @@
import { import {
makeDataProvider, makeDataProvider,
makeDerivedDataProvider, makeDerivedDataProvider,
marketDataErrorPolicyGuard,
} from '@vegaprotocol/data-provider'; } from '@vegaprotocol/data-provider';
import { import {
MarketInfoDocument, MarketInfoDocument,
@ -33,7 +32,7 @@ export const marketInfoProvider = makeDataProvider<
>({ >({
query: MarketInfoDocument, query: MarketInfoDocument,
getData, getData,
errorPolicyGuard: marketDataErrorPolicyGuard, errorPolicy: 'all',
pollInterval: 5000, pollInterval: 5000,
}); });

View File

@ -1,4 +1,3 @@
import { marketDataErrorPolicyGuard } from '@vegaprotocol/data-provider';
import { makeDataProvider } from '@vegaprotocol/data-provider'; import { makeDataProvider } from '@vegaprotocol/data-provider';
import { import {
MarketsDataDocument, MarketsDataDocument,
@ -54,7 +53,7 @@ export const marketsDataProvider = makeDataProvider<
>({ >({
query: MarketsDataDocument, query: MarketsDataDocument,
getData, getData,
errorPolicyGuard: marketDataErrorPolicyGuard, errorPolicy: 'all',
}); });
type Variables = { marketIds: string[] }; type Variables = { marketIds: string[] };
@ -73,7 +72,7 @@ export const marketsLiveDataProvider = makeDataProvider<
getData, getData,
getDelta, getDelta,
update, update,
errorPolicyGuard: marketDataErrorPolicyGuard, errorPolicy: 'all',
getQueryVariables: () => ({}), getQueryVariables: () => ({}),
getSubscriptionVariables: ({ marketIds }: Variables) => getSubscriptionVariables: ({ marketIds }: Variables) =>
marketIds.map((marketId) => ({ marketId })), marketIds.map((marketId) => ({ marketId })),

View File

@ -2,7 +2,6 @@ import { useYesterday } from '@vegaprotocol/react-helpers';
import { import {
makeDataProvider, makeDataProvider,
makeDerivedDataProvider, makeDerivedDataProvider,
marketDataErrorPolicyGuard,
useDataProvider, useDataProvider,
} from '@vegaprotocol/data-provider'; } from '@vegaprotocol/data-provider';
import { import {
@ -45,7 +44,7 @@ export const marketsProvider = makeDataProvider<
query: MarketsDocument, query: MarketsDocument,
getData, getData,
fetchPolicy: 'cache-first', fetchPolicy: 'cache-first',
errorPolicyGuard: marketDataErrorPolicyGuard, errorPolicy: 'all',
}); });
export const marketsMapProvider = makeDerivedDataProvider< export const marketsMapProvider = makeDerivedDataProvider<

View File

@ -39,8 +39,7 @@ export const proposalsDataProvider = makeDataProvider<
* *
* GQL Path: `terms.change.instrument.futureProduct.settlementAsset` * GQL Path: `terms.change.instrument.futureProduct.settlementAsset`
*/ */
errorPolicyGuard: (errors) => errorPolicy: 'all',
errors.every((e) => e.message.match(/failed to get asset for ID/)),
}); });
const ProposalTypeMap: Record< const ProposalTypeMap: Record<