@apollo/client/core#NormalizedCacheObject TypeScript Examples
The following examples show how to use
@apollo/client/core#NormalizedCacheObject.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: entities-update.ts From amplication with Apache License 2.0 | 6 votes |
export async function updateEntity(
client: ApolloClient<NormalizedCacheObject>,
data: models.EntityUpdateInput,
where: models.WhereUniqueInput
): Promise<models.Entity> {
const { data: entityData } = await client.mutate<{
updateEntity: models.Entity;
}>({
mutation: UPDATE_ENTITY,
variables: {
data,
where,
},
});
if (!entityData) {
throw new Error('no data');
}
return entityData?.updateEntity;
}
Example #2
Source File: getTradingFeeApr.ts From beefy-api with MIT License | 6 votes |
getYearlyTradingFeesForSJOE = async (
client: ApolloClient<NormalizedCacheObject>,
liquidityProviderFee: number
) => {
let yearlyTradingFeesUsd = new BigNumber(0);
const [start0, end0] = getUtcSecondsFromDayRange(1, 8);
try {
let data = await client.query({ query: joeDayDataRangeQuery(start0, end0) });
const dayData = data.data.dayDatas.map(data => new BigNumber(data.volumeUSD));
const totalVolume = BigNumber.sum.apply(null, dayData);
const avgVolume = totalVolume.dividedBy(7);
const dailyTradingApr = avgVolume.times(liquidityProviderFee);
yearlyTradingFeesUsd = dailyTradingApr.times(365);
} catch (e) {
console.error('> getYearlyTradingFeesForSJOE error');
}
return yearlyTradingFeesUsd;
}
Example #3
Source File: getTradingFeeApr.ts From beefy-api with MIT License | 6 votes |
getYearlyJoePlatformTradingFees = async (
client: ApolloClient<NormalizedCacheObject>,
liquidityProviderFee: number
) => {
let yearlyTradingFeesUsd = new BigNumber(0);
const timestamp = Date.now();
try {
let data = await client.query({ query: joeDayDataQuery(timestamp) });
const dailyVolumeUSD = new BigNumber(data.data.dayData.volumeUSD);
yearlyTradingFeesUsd = dailyVolumeUSD.times(liquidityProviderFee).times(365);
} catch (e) {
console.error('> getYearlyJoePlatformTradingFees error');
}
return yearlyTradingFeesUsd;
}
Example #4
Source File: getTradingFeeApr.ts From beefy-api with MIT License | 6 votes |
getYearlyPlatformTradingFees = async (
client: ApolloClient<NormalizedCacheObject>,
liquidityProviderFee: number
) => {
let yearlyTradingFeesUsd = new BigNumber(0);
const timestamp = Date.now();
try {
let data = await client.query({ query: dayDataQuery(timestamp) });
const dailyVolumeUSD = new BigNumber(data.data.uniswapDayData.dailyVolumeUSD);
yearlyTradingFeesUsd = dailyVolumeUSD.times(liquidityProviderFee).times(365);
} catch (e) {
console.error('> getYearlyPlatformTradingFees error');
console.log(e);
}
return yearlyTradingFeesUsd;
}
Example #5
Source File: getTradingFeeApr.ts From beefy-api with MIT License | 6 votes |
getVariableTradingFeeApr = async (
client: ApolloClient<NormalizedCacheObject>,
pairAddresses: string[],
liquidityProviderFee: number[]
) => {
const [start, end] = getUtcSecondsFromDayRange(1, 2);
const pairAddressToAprMap: Record<string, BigNumber> = {};
try {
let {
data: { pairDayDatas },
}: { data: { pairDayDatas: PairDayData[] } } = await client.query({
query: pairDayDataQuery(addressesToLowercase(pairAddresses), start, end),
});
let i = 0;
for (const pairDayData of pairDayDatas) {
const pairAddress = pairDayData.id.split('-')[0].toLowerCase();
pairAddressToAprMap[pairAddress] = new BigNumber(pairDayData.dailyVolumeUSD)
.times(liquidityProviderFee[i])
.times(365)
.dividedBy(pairDayData.reserveUSD);
i++;
}
} catch (e) {
console.error('> getVariableTradingFeeApr error', pairAddresses[0]);
}
return pairAddressToAprMap;
}
Example #6
Source File: getTradingFeeApr.ts From beefy-api with MIT License | 6 votes |
getTradingFeeAprBalancer = async (
client: ApolloClient<NormalizedCacheObject>,
pairAddresses: string[],
liquidityProviderFee: number
) => {
const blockTime = await getBlockTime(250);
const currentBlock = await getBlockNumber(250);
const pastBlock = Math.floor(currentBlock - 86400 / blockTime);
const pairAddressesToAprMap: Record<string, BigNumber> = {};
try {
const queryCurrent = await client.query({
query: poolsDataQuery(addressesToLowercase(pairAddresses), currentBlock),
});
const queryPast = await client.query({
query: poolsDataQuery(addressesToLowercase(pairAddresses), pastBlock),
});
const poolDayDatas0 = queryCurrent.data.pools;
const poolDayDatas1 = queryPast.data.pools;
for (const pool of poolDayDatas0) {
const pair = pool.address.toLowerCase();
const pastPool = poolDayDatas1.filter(p => {
return p.address === pool.address;
})[0];
pairAddressesToAprMap[pair] = new BigNumber(pool.totalSwapFee)
.minus(pastPool.totalSwapFee)
.times(365)
.dividedBy(pool.totalLiquidity);
}
} catch (e) {
console.error('> getTradingFeeAprBalancer error', pairAddresses[0]);
}
return pairAddressesToAprMap;
}
Example #7
Source File: getTradingFeeApr.ts From beefy-api with MIT License | 6 votes |
getYearlyTradingFeesForProtocols = async (
client: ApolloClient<NormalizedCacheObject>,
liquidityProviderFee: number
) => {
let yearlyTradingFeesUsd = new BigNumber(0);
const [start0, end0] = getUtcSecondsFromDayRange(1, 8);
try {
let data = await client.query({ query: protocolDayDataRangeQuery(start0, end0) });
const dayData = data.data.uniswapDayDatas.map(data => new BigNumber(data.dailyVolumeUSD));
const totalVolume = BigNumber.sum.apply(null, dayData);
const avgVolume = totalVolume.dividedBy(7);
const dailyTradingApr = avgVolume.times(liquidityProviderFee);
yearlyTradingFeesUsd = dailyTradingApr.times(365);
} catch (e) {
console.error('> getYearlyTradingFeesForProtocols error');
}
return yearlyTradingFeesUsd;
}
Example #8
Source File: getTradingFeeApr.ts From beefy-api with MIT License | 6 votes |
getTradingFeeApr = async (
client: ApolloClient<NormalizedCacheObject>,
pairAddresses: string[],
liquidityProviderFee: number
) => {
const [start, end] = getUtcSecondsFromDayRange(1, 2);
const pairAddressToAprMap: Record<string, BigNumber> = {};
try {
let {
data: { pairDayDatas },
}: { data: { pairDayDatas: PairDayData[] } } = await client.query({
query: pairDayDataQuery(addressesToLowercase(pairAddresses), start, end),
});
for (const pairDayData of pairDayDatas) {
const pairAddress = pairDayData.id.split('-')[0].toLowerCase();
pairAddressToAprMap[pairAddress] = new BigNumber(pairDayData.dailyVolumeUSD)
.times(liquidityProviderFee)
.times(365)
.dividedBy(pairDayData.reserveUSD);
}
} catch (e) {
console.error('> getTradingFeeApr error', pairAddresses[0]);
}
return pairAddressToAprMap;
}
Example #9
Source File: fields-update.ts From amplication with Apache License 2.0 | 6 votes |
export async function updateField(
client: ApolloClient<NormalizedCacheObject>,
data: models.EntityFieldUpdateInput,
where: models.WhereUniqueInput,
relatedFieldName?: string | undefined,
relatedFieldDisplayName?: string | undefined
): Promise<models.EntityField> {
const { data: fieldData } = await client.mutate<{
updateEntityField: models.EntityField;
}>({
mutation: UPDATE_ENTITY_FIELD,
variables: {
data,
where,
relatedFieldName,
relatedFieldDisplayName,
},
});
if (!fieldData) {
throw new Error('no data');
}
return fieldData.updateEntityField;
}
Example #10
Source File: fields-list.ts From amplication with Apache License 2.0 | 6 votes |
export async function getFields(
client: ApolloClient<NormalizedCacheObject>,
entityId: string,
orderBy: string | undefined,
whereName: string | undefined
): Promise<models.EntityField[]> {
const { data } = await client.query<{
entity: models.Entity;
}>({
query: GET_FIELDS,
variables: {
entityId,
orderBy,
whereName,
},
});
return data.entity.fields || [];
}
Example #11
Source File: fields-create-by-display-name.ts From amplication with Apache License 2.0 | 6 votes |
export async function createFieldByDisplayName(
client: ApolloClient<NormalizedCacheObject>,
data: models.EntityFieldCreateByDisplayNameInput
): Promise<models.EntityField> {
const { data: fieldData } = await client.mutate<{
createEntityFieldByDisplayName: models.EntityField;
}>({
mutation: CREATE_ENTITY_FIELD,
variables: {
data,
},
});
if (!fieldData) {
throw new Error('no data');
}
return fieldData.createEntityFieldByDisplayName;
}
Example #12
Source File: entities-list.ts From amplication with Apache License 2.0 | 6 votes |
export async function getEntities(
client: ApolloClient<NormalizedCacheObject>,
appId: string,
orderBy: string | undefined,
whereName: string | undefined
): Promise<models.Entity[]> {
const { data } = await client.query<{ entities: models.Entity[] }>({
query: GET_ENTITIES,
variables: {
appId,
orderBy,
whereName,
},
});
return data.entities;
}
Example #13
Source File: entities-get.ts From amplication with Apache License 2.0 | 6 votes |
export async function getEntity(
client: ApolloClient<NormalizedCacheObject>,
id: string
): Promise<models.Entity> {
const { data } = await client.query<{
entity: models.Entity;
}>({
query: GET_ENTITY,
variables: {
id,
},
});
return data.entity;
}
Example #14
Source File: entities-create.ts From amplication with Apache License 2.0 | 6 votes |
export async function createEntity(
client: ApolloClient<NormalizedCacheObject>,
data: models.EntityCreateInput
): Promise<models.Entity> {
const { data: entityData } = await client.mutate<{
createOneEntity: models.Entity;
}>({
mutation: CREATE_ENTITY,
variables: {
data,
},
});
if (!entityData) {
throw new Error('no data');
}
return entityData?.createOneEntity;
}
Example #15
Source File: apps-update.ts From amplication with Apache License 2.0 | 6 votes |
export async function updateApp(
client: ApolloClient<NormalizedCacheObject>,
appId: string,
data: models.AppUpdateInput
): Promise<models.App> {
const { data: appData } = await client.mutate<{ updateApp: models.App }>({
mutation: UPDATE_APP,
variables: {
appId,
data,
},
});
if (!appData) {
throw new Error('no data');
}
return appData.updateApp;
}
Example #16
Source File: apps-list.ts From amplication with Apache License 2.0 | 6 votes |
export async function getApps(
client: ApolloClient<NormalizedCacheObject>
): Promise<models.App[]> {
const { data } = await client.query<{ apps: models.App[] }>({
query: GET_APPS,
});
return data.apps;
}
Example #17
Source File: apps-get.ts From amplication with Apache License 2.0 | 6 votes |
export async function getApp(
client: ApolloClient<NormalizedCacheObject>,
id: string
): Promise<models.App> {
const { data } = await client.query<{ app: models.App }>({
query: GET_APP,
variables: {
id,
},
});
return data.app;
}
Example #18
Source File: apps-create.ts From amplication with Apache License 2.0 | 6 votes |
export async function createApp(
client: ApolloClient<NormalizedCacheObject>,
name: string,
description: string
): Promise<models.App> {
const { data } = await client.mutate<{ createApp: models.App }>({
mutation: CREATE_APP,
variables: {
data: {
name,
description,
},
},
});
if (!data) {
throw new Error('no data');
}
return data.createApp;
}
Example #19
Source File: apps-commit.ts From amplication with Apache License 2.0 | 6 votes |
export async function commitChanges(
client: ApolloClient<NormalizedCacheObject>,
appId: string,
message: string
): Promise<models.Commit> {
const { data } = await client.mutate<{ commit: models.Commit }>({
mutation: COMMIT_CHANGES,
variables: {
message,
appId,
},
});
if (!data) {
throw new Error('no data');
}
return data.commit;
}
Example #20
Source File: getTradingFeeApr.ts From beefy-api with MIT License | 6 votes |
getYearlyBalancerPlatformTradingFees = async (
client: ApolloClient<NormalizedCacheObject>,
liquidityProviderFeeShare: number
) => {
const blockTime = await getBlockTime(250);
const currentBlock = await getBlockNumber(250);
const pastBlock = Math.floor(currentBlock - 86400 / blockTime);
let yearlyTradingFeesUsd = new BigNumber(0);
try {
const currentData = await client.query({ query: balancerDataQuery(currentBlock) });
const pastData = await client.query({ query: balancerDataQuery(pastBlock) });
const currentSwapFee = new BigNumber(currentData.data.balancers[0].totalSwapFee);
const pastSwapFee = new BigNumber(pastData.data.balancers[0].totalSwapFee);
const dailySwapFeeUsd = currentSwapFee.minus(pastSwapFee);
yearlyTradingFeesUsd = dailySwapFeeUsd.times(365).times(liquidityProviderFeeShare);
} catch (e) {
console.error('> getYearlyBalancerPlatformTradingFees error');
}
return yearlyTradingFeesUsd;
}
Example #21
Source File: InvalidationPolicyCache.ts From apollo-cache-policies with Apache License 2.0 | 6 votes |
extract(optimistic = false, withInvalidation = true): NormalizedCacheObject {
const extractedCache = super.extract(optimistic);
if (withInvalidation) {
// The entitiesById are sufficient alone for reconstructing the type map, so to
// minimize payload size only inject the entitiesById object into the extracted cache
extractedCache.invalidation = pick(
this.entityTypeMap.extract(),
"entitiesById"
);
}
return extractedCache;
}
Example #22
Source File: api.service.ts From etherspot-sdk with MIT License | 5 votes |
private apolloClient: ApolloClient<NormalizedCacheObject>;
Example #23
Source File: getTradingFeeApr.ts From beefy-api with MIT License | 5 votes |
getTradingFeeAprSushi = async (
client: ApolloClient<NormalizedCacheObject>,
pairAddresses: string[],
liquidityProviderFee: number
) => {
const [start0, end0] = getUtcSecondsFromDayRange(1, 2);
const [start1, end1] = getUtcSecondsFromDayRange(3, 4);
const pairAddressToAprMap: Record<string, BigNumber> = {};
try {
let queryResponse0 = await client.query({
query: pairDayDataSushiQuery(addressesToLowercase(pairAddresses), start0, end0),
});
let queryResponse1 = await client.query({
query: pairDayDataSushiQuery(addressesToLowercase(pairAddresses), start1, end1),
});
const pairDayDatas0 = queryResponse0.data.pairs.map(pair => pair.dayData[0]);
const pairDayDatas1 = queryResponse1.data.pairs.map(pair => pair.dayData[0]);
for (const pairDayData of zip([pairDayDatas0, pairDayDatas1])) {
if (pairDayData && pairDayData[0] && pairDayData[1]) {
const pairAddress = pairDayData[0].id.split('-')[0].toLowerCase();
const avgVol = new BigNumber(pairDayData[0].volumeUSD)
.plus(pairDayData[1].volumeUSD)
.dividedBy(2);
const avgReserve = new BigNumber(pairDayData[0].reserveUSD)
.plus(pairDayData[1].reserveUSD)
.dividedBy(2);
pairAddressToAprMap[pairAddress] = new BigNumber(avgVol)
.times(liquidityProviderFee)
.times(365)
.dividedBy(avgReserve);
}
}
} catch (e) {
console.error('> getTradingFeeAprSushi error', pairAddresses[0]);
}
return pairAddressToAprMap;
}
Example #24
Source File: nftx.service.ts From runebot with MIT License | 5 votes |
private readonly _sushiClient: ApolloClient<NormalizedCacheObject>;
Example #25
Source File: nftx.service.ts From runebot with MIT License | 5 votes |
private readonly _nftxClient: ApolloClient<NormalizedCacheObject>;