Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

apollo v4 #1497

Merged
merged 2 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/cool-houses-grab.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'backend': minor
---

apollo v4
54 changes: 54 additions & 0 deletions apps/api/apollo/sentry-plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { captureException } from '@sentry/node';
import { ApolloServerPlugin } from '@apollo/server';
import { ResolverContext } from '../gql/resolver-context';

export const apolloSentryPlugin: ApolloServerPlugin<ResolverContext> = {
async requestDidStart({ request }) {
return {
// This will send any errors captured by Apollo Server to Sentry
async didEncounterErrors(ctx) {
for (const err of ctx.errors) {
// Ignore syntax errors
if (
[
'GRAPHQL_PARSE_FAILED',
'GRAPHQL_VALIDATION_FAILED',
'BAD_USER_INPUT',
'ACCOUNT_ADDRESS_REQUIRED',
'ACCESS_DENIED',
'NOT_FOUND',
].includes(err.extensions?.code as string)
) {
continue;
}

// Ignore specific errors
if (err.message && err.message === 'SOR queryBatchSwap failed') {
continue;
}

// Potentially set transaction name to the operation name,
// add tags and fingerprint to group errors

// Sentry.withScope((scope) => {
// let name = request.operationName;
// if (!name) {
// name = request.query
// ?.substring(
// request.query?.indexOf('{') + 1,
// request.query?.indexOf('(') || request.query?.length,
// )
// .replace(/\n/g, '')
// .replace(/\s/g, '');
// }
// scope.setTransactionName(`POST /graphql ${name}`);
// Sentry.captureException(err);
// });

captureException(err);
}
},
async willSendResponse({}) {},
};
},
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { gql } from 'apollo-server-express';
import { gql } from 'graphql-request';
export const schema = gql`
#
# THIS FILE IS AUTOGENERATED — DO NOT EDIT IT
Expand Down
2 changes: 1 addition & 1 deletion schema.ts → apps/api/gql/generated-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* THIS FILE IS AUTOGENERATED — DO NOT EDIT IT
*/
import { GraphQLResolveInfo, GraphQLScalarType, GraphQLScalarTypeConfig } from 'graphql';
import { ResolverContext } from './apps/api/gql/resolver-context';
import { ResolverContext } from './resolver-context';
export type Maybe<T> = T | null;
export type InputMaybe<T> = Maybe<T>;
export type Exact<T extends { [key: string]: unknown }> = { [K in keyof T]: T[K] };
Expand Down
2 changes: 1 addition & 1 deletion apps/api/gql/resolvers/beets.resolvers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Resolvers } from '../../../../schema';
import { Resolvers } from '../generated-schema';
import { beetsService } from '../../../../modules/beets/beets.service';
import { getRequiredAccountAddress, isAdminRoute } from '../../../../modules/auth/auth-context';
import { userService } from '../../../../modules/user/user.service';
Expand Down
2 changes: 1 addition & 1 deletion apps/api/gql/resolvers/blocks.resolvers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Resolvers } from '../../../../schema';
import { Resolvers } from '../generated-schema';
import { isAdminRoute } from '../../../../modules/auth/auth-context';
import { blocksSubgraphService } from '../../../../modules/subgraphs/blocks-subgraph/blocks-subgraph.service';

Expand Down
7 changes: 5 additions & 2 deletions apps/api/gql/resolvers/content.resolvers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Resolvers } from '../../../../schema';
import { Resolvers } from '../generated-schema';
import { headerChain } from '../../../../modules/context/header-chain';
import { SanityContentService } from '../../../../modules/content/sanity-content.service';
import { GraphQLError } from 'graphql';

const contentResolvers: Resolvers = {
Query: {
Expand All @@ -9,7 +10,9 @@ const contentResolvers: Resolvers = {
if (!chain && currentChain) {
chain = currentChain;
} else if (!chain) {
throw new Error('contentGetNewsItems error: Provide "chain" param');
throw new GraphQLError('Provide "chain" param', {
extensions: { code: 'GRAPHQL_VALIDATION_FAILED' },
});
}
const sanityContent = new SanityContentService();
return sanityContent.getNewsItems(chain);
Expand Down
35 changes: 26 additions & 9 deletions apps/api/gql/resolvers/pool.resolvers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { poolService } from '../../../../modules/pool/pool.service';
import { GqlChain, Resolvers } from '../../../../schema';
import { GqlChain, Resolvers } from '../generated-schema';
import { isAdminRoute } from '../../../../modules/auth/auth-context';
import { networkContext } from '../../../../modules/network/network-context.service';
import { headerChain } from '../../../../modules/context/header-chain';
Expand All @@ -11,6 +11,7 @@ import {
FXPoolsController,
} from '../../../../modules/controllers';
import { chainIdToChain } from '../../../../modules/network/chain-id-to-chain';
import { GraphQLError } from 'graphql';

const balancerResolvers: Resolvers = {
Query: {
Expand All @@ -19,7 +20,9 @@ const balancerResolvers: Resolvers = {
if (!chain && currentChain) {
chain = currentChain;
} else if (!chain) {
throw new Error('poolGetPool error: Provide "chain" param');
throw new GraphQLError('Provide "chain" param', {
extensions: { code: 'GRAPHQL_VALIDATION_FAILED' },
});
}
return poolService.getGqlPool(id, chain, userAddress ? userAddress : undefined);
},
Expand All @@ -38,7 +41,9 @@ const balancerResolvers: Resolvers = {
if (!args.where?.chainIn && currentChain) {
args.where = { ...args.where, chainIn: [currentChain] };
} else if (!args.where?.chainIn) {
throw new Error('poolGetSwaps error: Provide "where.chainIn" param');
throw new GraphQLError('Provide "chainIn" param', {
extensions: { code: 'GRAPHQL_VALIDATION_FAILED' },
});
}
return poolService.getPoolSwaps(args);
},
Expand All @@ -48,7 +53,9 @@ const balancerResolvers: Resolvers = {
if (!args.where?.chainIn && currentChain) {
args.where = { ...args.where, chainIn: [currentChain] };
} else if (!args.where?.chainIn) {
throw new Error('poolGetBatchSwaps error: Provide "where.chainIn" param');
throw new GraphQLError('Provide "chainIn" param', {
extensions: { code: 'GRAPHQL_VALIDATION_FAILED' },
});
}
return poolService.getPoolBatchSwaps(args);
},
Expand All @@ -58,7 +65,9 @@ const balancerResolvers: Resolvers = {
if (!args.where?.chainIn && currentChain) {
args.where = { ...args.where, chainIn: [currentChain] };
} else if (!args.where?.chainIn) {
throw new Error('poolGetJoinExits error: Provide "where.chainIn" param');
throw new GraphQLError('Provide "chainIn" param', {
extensions: { code: 'GRAPHQL_VALIDATION_FAILED' },
});
}
return poolService.getPoolJoinExits(args);
},
Expand All @@ -80,7 +89,9 @@ const balancerResolvers: Resolvers = {
if (!chains && currentChain) {
chains = [currentChain];
} else if (!chains) {
throw new Error('poolGetFeaturedPoolGroups error: Provide "chains" param');
throw new GraphQLError('Provide "chains" param', {
extensions: { code: 'GRAPHQL_VALIDATION_FAILED' },
});
}
return poolService.getFeaturedPoolGroups(chains);
},
Expand All @@ -92,7 +103,9 @@ const balancerResolvers: Resolvers = {
if (!chain && currentChain) {
chain = currentChain;
} else if (!chain) {
throw new Error('poolGetSnapshots error: Provide "chain" param');
throw new GraphQLError('Provide "chain" param', {
extensions: { code: 'GRAPHQL_VALIDATION_FAILED' },
});
}
const snapshots = await poolService.getSnapshotsForPool(id, chain, range);

Expand All @@ -118,7 +131,9 @@ const balancerResolvers: Resolvers = {
const chain = headerChain();

if (!chain) {
throw new Error('poolSyncAllPoolsFromSubgraph error: Provide chain header');
throw new GraphQLError('Provide "chainId" header', {
extensions: { code: 'GRAPHQL_VALIDATION_FAILED' },
});
}

return PoolController().addPoolsV2(chain);
Expand All @@ -135,7 +150,9 @@ const balancerResolvers: Resolvers = {

const currentChain = headerChain();
if (!currentChain) {
throw new Error('poolReloadStakingForAllPools error: Provide chain header');
throw new GraphQLError('Provide "chainId" header', {
extensions: { code: 'GRAPHQL_VALIDATION_FAILED' },
});
}

await poolService.reloadStakingForAllPools(args.stakingTypes, currentChain);
Expand Down
11 changes: 8 additions & 3 deletions apps/api/gql/resolvers/protocol.resolvers.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { GqlLatestSyncedBlocks, Resolvers } from '../../../../schema';
import { GqlLatestSyncedBlocks, Resolvers } from '../generated-schema';
import { protocolService } from '../../../../modules/protocol/protocol.service';
import { networkContext } from '../../../../modules/network/network-context.service';
import { headerChain } from '../../../../modules/context/header-chain';
import { GraphQLError } from 'graphql';

const protocolResolvers: Resolvers = {
Query: {
Expand All @@ -10,7 +11,9 @@ const protocolResolvers: Resolvers = {
if (!chain && currentChain) {
chain = currentChain;
} else if (!chain) {
throw new Error('poolGetPool error: Provide "chain" param');
throw new GraphQLError('Provide "chain" param', {
extensions: { code: 'GRAPHQL_VALIDATION_FAILED' },
});
}
return protocolService.getMetrics(chain);
},
Expand All @@ -19,7 +22,9 @@ const protocolResolvers: Resolvers = {
if (!chains && currentChain) {
chains = [currentChain];
} else if (!chains) {
throw new Error('tokenGetTokens error: Provide "chains" param');
throw new GraphQLError('Provide "chains" param', {
extensions: { code: 'GRAPHQL_VALIDATION_FAILED' },
});
}
return protocolService.getAggregatedMetrics(chains);
},
Expand Down
2 changes: 1 addition & 1 deletion apps/api/gql/resolvers/scalar.resolvers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Resolvers } from '../../../../schema';
import { Resolvers } from '../generated-schema';
import { GraphQLScalarType, Kind } from 'graphql';

const dateScalar = new GraphQLScalarType<Date | null, string | null>({
Expand Down
2 changes: 1 addition & 1 deletion apps/api/gql/resolvers/sftmx.resolvers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Resolvers } from '../../../../schema';
import { Resolvers } from '../generated-schema';
import { SftmxController } from '../../../../modules/controllers';

const resolvers: Resolvers = {
Expand Down
7 changes: 5 additions & 2 deletions apps/api/gql/resolvers/sor.resolvers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Resolvers } from '../../../../schema';
import { Resolvers } from '../generated-schema';
import { sorService } from '../../../../modules/sor/sor.service';
import { headerChain } from '../../../../modules/context/header-chain';
import { GraphQLError } from 'graphql';

const balancerSdkResolvers: Resolvers = {
Query: {
Expand All @@ -9,7 +10,9 @@ const balancerSdkResolvers: Resolvers = {
if (!args.chain && currentChain) {
args.chain = currentChain;
} else if (!args.chain) {
throw new Error('sorGetSwaps error: Provide "chain" param');
throw new GraphQLError('Provide "chain" param', {
extensions: { code: 'GRAPHQL_VALIDATION_FAILED' },
});
}

return sorService.getSorSwaps(args);
Expand Down
2 changes: 1 addition & 1 deletion apps/api/gql/resolvers/sts.resolvers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Resolvers } from '../../../../schema';
import { Resolvers } from '../generated-schema';
import { StakedSonicController } from '../../../../modules/controllers';

const resolvers: Resolvers = {
Expand Down
39 changes: 29 additions & 10 deletions apps/api/gql/resolvers/token.resolvers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { GqlChain, GqlHistoricalTokenPrice, Resolvers } from '../../../../schema';
import { GqlChain, GqlHistoricalTokenPrice, Resolvers } from '../generated-schema';
import _ from 'lodash';
import { isAdminRoute } from '../../../../modules/auth/auth-context';
import { tokenService } from '../../../../modules/token/token.service';
Expand All @@ -7,6 +7,7 @@ import { syncLatestFXPrices } from '../../../../modules/token/latest-fx-price';
import moment from 'moment';
import { TokenController } from '../../../../modules/controllers/token-controller';
import config from '../../../../config';
import { GraphQLError } from 'graphql';

const resolvers: Resolvers = {
Query: {
Expand All @@ -15,7 +16,9 @@ const resolvers: Resolvers = {
if (!args.chains && currentChain) {
args.chains = [currentChain];
} else if (!args.chains) {
throw new Error('tokenGetTokens error: Provide "chains" param');
throw new GraphQLError('Provide "chains" param', {
extensions: { code: 'GRAPHQL_VALIDATION_FAILED' },
});
}
return tokenService.getTokenDefinitions(args);
},
Expand All @@ -24,7 +27,9 @@ const resolvers: Resolvers = {
if (!chains && currentChain) {
chains = [currentChain];
} else if (!chains) {
throw new Error('tokenGetCurrentPrices error: Provide "chains" param');
throw new GraphQLError('Provide "chains" param', {
extensions: { code: 'GRAPHQL_VALIDATION_FAILED' },
});
}
const prices = await tokenService.getCurrentTokenPrices(chains);

Expand Down Expand Up @@ -61,7 +66,9 @@ const resolvers: Resolvers = {
if (!chain && currentChain) {
chain = currentChain;
} else if (!chain) {
throw new Error('tokenGetTokenDynamicData error: Provide "chain" param');
throw new GraphQLError('Provide "chain" param', {
extensions: { code: 'GRAPHQL_VALIDATION_FAILED' },
});
}
const data = await tokenService.getTokenDynamicData(address, chain);

Expand All @@ -80,7 +87,9 @@ const resolvers: Resolvers = {
if (!chain && currentChain) {
chain = currentChain;
} else if (!chain) {
throw new Error('tokenGetTokensDynamicData error: Provide "chain" param');
throw new GraphQLError('Provide "chain" param', {
extensions: { code: 'GRAPHQL_VALIDATION_FAILED' },
});
}
const items = await tokenService.getTokensDynamicData(addresses, chain);

Expand All @@ -97,7 +106,9 @@ const resolvers: Resolvers = {
if (!chain && currentChain) {
chain = currentChain;
} else if (!chain) {
throw new Error('tokenGetPriceChartData error: Provide "chain" param');
throw new GraphQLError('Provide "chain" param', {
extensions: { code: 'GRAPHQL_VALIDATION_FAILED' },
});
}
const data = await tokenService.getTokenPriceForRange(address, range, chain);

Expand All @@ -112,7 +123,9 @@ const resolvers: Resolvers = {
if (!chain && currentChain) {
chain = currentChain;
} else if (!chain) {
throw new Error('tokenGetRelativePriceChartData error: Provide "chain" param');
throw new GraphQLError('Provide "chain" param', {
extensions: { code: 'GRAPHQL_VALIDATION_FAILED' },
});
}
const data = await tokenService.getRelativeDataForRange(tokenIn, tokenOut, range, chain);

Expand All @@ -127,7 +140,9 @@ const resolvers: Resolvers = {
if (!chain && currentChain) {
chain = currentChain;
} else if (!chain) {
throw new Error('tokenGetCandlestickChartData error: Provide "chain" param');
throw new GraphQLError('Provide "chain" param', {
extensions: { code: 'GRAPHQL_VALIDATION_FAILED' },
});
}
const data = await tokenService.getTokenPriceForRange(address, range, chain);

Expand All @@ -145,7 +160,9 @@ const resolvers: Resolvers = {
if (!chain && currentChain) {
chain = currentChain;
} else if (!chain) {
throw new Error('tokenGetTokenData error: Provide "chain" param');
throw new GraphQLError('Provide "chain" param', {
extensions: { code: 'GRAPHQL_VALIDATION_FAILED' },
});
}
const token = await tokenService.getToken(address, chain);
if (token) {
Expand All @@ -167,7 +184,9 @@ const resolvers: Resolvers = {
if (!chain && currentChain) {
chain = currentChain;
} else if (!chain) {
throw new Error('tokenGetProtocolTokenPrice error: Provide "chain" param');
throw new GraphQLError('Provide "chain" param', {
extensions: { code: 'GRAPHQL_VALIDATION_FAILED' },
});
}
return tokenService.getProtocolTokenPrice(chain);
},
Expand Down
Loading
Loading