Skip to content

Commit

Permalink
feat: update indexer api resolvers
Browse files Browse the repository at this point in the history
  • Loading branch information
1Mateus committed Dec 20, 2023
1 parent 2b49dcc commit df0e3cf
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@
"S3Bucket": {
"Ref": "ServerlessDeploymentBucket"
},
"S3Key": "serverless/indexer-service/dev/1686664058542-2023-06-13T13:47:38.542Z/graphql.zip"
"S3Key": "serverless/indexer-service/dev/1703009758175-2023-12-19T18:15:58.175Z/graphql.zip"
},
"Handler": "src/server.graphqlHandler",
"Runtime": "nodejs18.x",
Expand All @@ -180,14 +180,14 @@
"GraphqlLogGroup"
]
},
"GraphqlLambdaVersion74MCfsupBmIT3WZ75E4TbDhGAdxGG9Ba4eJe7NH51U": {
"GraphqlLambdaVersionXRmIMURM2bS7toYWA4agCHBNaARirF4Xs6MZI6Q8": {
"Type": "AWS::Lambda::Version",
"DeletionPolicy": "Retain",
"Properties": {
"FunctionName": {
"Ref": "GraphqlLambdaFunction"
},
"CodeSha256": "Lylix922d6NhKaQRZnl4ybPUJSCSO698c1CQQJZwRco="
"CodeSha256": "r6vuxnvMUqMAjnDDDgzDzJVJco1mo8dQlE4YlN/tGTI="
}
},
"HttpApi": {
Expand Down Expand Up @@ -338,7 +338,7 @@
"GraphqlLambdaFunctionQualifiedArn": {
"Description": "Current Lambda function version",
"Value": {
"Ref": "GraphqlLambdaVersion74MCfsupBmIT3WZ75E4TbDhGAdxGG9Ba4eJe7NH51U"
"Ref": "GraphqlLambdaVersionXRmIMURM2bS7toYWA4agCHBNaARirF4Xs6MZI6Q8"
},
"Export": {
"Name": "sls-indexer-service-dev-GraphqlLambdaFunctionQualifiedArn"
Expand Down
16 changes: 8 additions & 8 deletions indexer/api/.serverless/serverless-state.json
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@
"S3Bucket": {
"Ref": "ServerlessDeploymentBucket"
},
"S3Key": "serverless/indexer-service/dev/1686664058542-2023-06-13T13:47:38.542Z/graphql.zip"
"S3Key": "serverless/indexer-service/dev/1703009758175-2023-12-19T18:15:58.175Z/graphql.zip"
},
"Handler": "src/server.graphqlHandler",
"Runtime": "nodejs18.x",
Expand All @@ -195,14 +195,14 @@
"GraphqlLogGroup"
]
},
"GraphqlLambdaVersion74MCfsupBmIT3WZ75E4TbDhGAdxGG9Ba4eJe7NH51U": {
"GraphqlLambdaVersionXRmIMURM2bS7toYWA4agCHBNaARirF4Xs6MZI6Q8": {
"Type": "AWS::Lambda::Version",
"DeletionPolicy": "Retain",
"Properties": {
"FunctionName": {
"Ref": "GraphqlLambdaFunction"
},
"CodeSha256": "Lylix922d6NhKaQRZnl4ybPUJSCSO698c1CQQJZwRco="
"CodeSha256": "r6vuxnvMUqMAjnDDDgzDzJVJco1mo8dQlE4YlN/tGTI="
}
},
"HttpApi": {
Expand Down Expand Up @@ -350,7 +350,7 @@
"GraphqlLambdaFunctionQualifiedArn": {
"Description": "Current Lambda function version",
"Value": {
"Ref": "GraphqlLambdaVersion74MCfsupBmIT3WZ75E4TbDhGAdxGG9Ba4eJe7NH51U"
"Ref": "GraphqlLambdaVersionXRmIMURM2bS7toYWA4agCHBNaARirF4Xs6MZI6Q8"
},
"Export": {
"Name": "sls-indexer-service-dev-GraphqlLambdaFunctionQualifiedArn"
Expand Down Expand Up @@ -500,13 +500,13 @@
],
"name": "indexer-service-dev-graphql",
"package": {
"artifact": "/Users/mateussantana/Projects/hackadena/indexer/api/.serverless/graphql.zip"
"artifact": "/Users/mateussantana/Projects/hackachain/wallet/indexer/api/.serverless/graphql.zip"
},
"memory": 1024,
"timeout": 6,
"runtime": "nodejs18.x",
"vpc": {},
"versionLogicalId": "GraphqlLambdaVersion74MCfsupBmIT3WZ75E4TbDhGAdxGG9Ba4eJe7NH51U"
"versionLogicalId": "GraphqlLambdaVersionXRmIMURM2bS7toYWA4agCHBNaARirF4Xs6MZI6Q8"
}
},
"configValidationMode": "warn",
Expand All @@ -528,15 +528,15 @@
"src/server.js"
],
"artifactsS3KeyDirname": "serverless/indexer-service/dev/code-artifacts",
"artifactDirectoryName": "serverless/indexer-service/dev/1686664058542-2023-06-13T13:47:38.542Z"
"artifactDirectoryName": "serverless/indexer-service/dev/1703009758175-2023-12-19T18:15:58.175Z"
}
},
"layers": {},
"isDashboardMonitoringPreconfigured": false
},
"package": {
"individually": true,
"artifactDirectoryName": "serverless/indexer-service/dev/1686664058542-2023-06-13T13:47:38.542Z",
"artifactDirectoryName": "serverless/indexer-service/dev/1703009758175-2023-12-19T18:15:58.175Z",
"artifact": ""
}
}
77 changes: 64 additions & 13 deletions indexer/api/src/resolvers.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,87 @@
import { baseRequest } from "./utils";

const query = "SELECT * FROM events WHERE name = $1 AND module = $2 AND chainid = $3 LIMIT $4 OFFSET $5"

export const resolvers = {
Query: {
getEvents: async (_, args) => {
getCommitments: async (_, args) => {
const offset = (args.page - 1) * args.size;

const query = "SELECT * FROM events LIMIT $1 OFFSET $2;";
const result = await baseRequest(query, [
'new-commitment',
args.module,
args.chainId,
args.size,
offset,
]);

const events =
result?.rows.map(({ params }) => {
console.log('params', params)
const value = params[0]?.int;

const order = params[1]?.int;

const result = await baseRequest(query, [args.size, offset]);
return {
order,
value,
};
}) || [];

return result.rows;
const hasNextPage = events?.length === args.size;

return {
events,
hasNextPage,
currentPage: args.page,
itemCount: events.length,
};
},

getEventsByModule: async (_, args) => {
getNullifiers: async (_, args) => {
const offset = (args.page - 1) * args.size;

const query =
"SELECT * FROM events WHERE module = $1 LIMIT $2 OFFSET $3;";
const result = await baseRequest(query, [
'new-nullifier',
args.module,
args.chainId,
args.size,
offset,
]);

const events = result?.rows.map(({ params }) => params[0]?.int) || [];

const result = await baseRequest(query, [args.module, args.size, offset]);
const hasNextPage = events.length === args.size;

return result.rows;
return {
events,
hasNextPage,
currentPage: args.page,
itemCount: events.length,
};
},

getTransactions: async (_, args) => {
getUtxos: async (_, args) => {
const offset = (args.page - 1) * args.size;

const query = "SELECT * FROM transactions LIMIT $1 OFFSET $2;";
const result = await baseRequest(query, [
'new-encrypted-output',
args.module,
args.chainId,
args.size,
offset,
]);

const events = result?.rows.map(({ params }) => params[0]) || [];

const result = await baseRequest(query, [args.size, offset]);
const hasNextPage = events.length === args.size;

return result.rows;
return {
events,
hasNextPage,
currentPage: args.page,
itemCount: events.length,
};
},
},
};
38 changes: 10 additions & 28 deletions indexer/api/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Client } from "pg";

export const typeDefs = `#graphql
scalar JSON
type Event {
block: String!
chainid: Int!
Expand All @@ -14,37 +16,17 @@ export const typeDefs = `#graphql
requestkey: String!
}
type Transaction {
badresult: String
block: String!
chainid: Int!
code: String
continuation: String
creationtime: String!
data: String
gas: Int!
gaslimit: Int!
gasprice: Float!
goodresult: String
height: Int!
logs: String
metadata: String
nonce: String!
num_events: Int
pactid: String
proof: String
requestkey: String!
rollback: Boolean
sender: String!
step: Int
ttl: Int!
txid: Int
type PaginatedEvents {
events: [JSON]
itemCount: Int
currentPage: Int
hasNextPage: Boolean
}
type Query {
getEvents(page: Int!, size: Int!): [Event]
getEventsByModule(page: Int!, size: Int!, module: String!): [Event]
getTransactions(page: Int!, size: Int!): [Transaction]
getUtxos(page: Int!, size: Int!, module: String!, chainId: Int!): PaginatedEvents
getNullifiers(page: Int!, size: Int!, module: String!, chainId: Int!): PaginatedEvents
getCommitments(page: Int!, size: Int!, module: String!, chainId: Int!): PaginatedEvents
}
`;

Expand Down

0 comments on commit df0e3cf

Please sign in to comment.