-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add block dataloader and rename types to improve readability
- Loading branch information
Showing
14 changed files
with
156 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
> Why do I have a folder named ".vercel" in my project? | ||
The ".vercel" folder is created when you link a directory to a Vercel project. | ||
|
||
> What does the "project.json" file contain? | ||
The "project.json" file contains: | ||
- The ID of the Vercel project that you linked ("projectId") | ||
- The ID of the user or team your Vercel project is owned by ("orgId") | ||
|
||
> Should I commit the ".vercel" folder? | ||
No, you should not share the ".vercel" folder with anyone. | ||
Upon creation, it will be automatically added to your ".gitignore" file. |
6 changes: 6 additions & 0 deletions
6
backend/.vercel/cache/node/src/main.ts/tsconfig-with-tsconfig-json.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"extends": "../../../../../tsconfig.json", | ||
"include": [ | ||
"../../../../../src/main.ts" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"projectId":"prj_XBfS7RIGQLWKOZBjUV6VpbXY9qkT","orgId":"team_BHVHlLGzAXdFN0HU9HDLZzOh"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { Injectable, Logger } from '@nestjs/common'; | ||
import { NestDataLoader } from '@applifting-io/nestjs-dataloader'; | ||
import { BaseTransaction } from '../transaction/transaction.model'; | ||
import { BlockService } from './block.service'; | ||
import { BaseBlock } from './block.model'; | ||
|
||
@Injectable() | ||
export class BlockLoader implements NestDataLoader<string, BaseBlock> { | ||
private logger = new Logger(BlockLoader.name); | ||
|
||
constructor(private readonly blockService: BlockService) { } | ||
|
||
public getBatchFunction() { | ||
return (heightOrHashList: string[]) => { | ||
this.logger.debug(`Loading blocks: ${heightOrHashList.join(', ')}`); | ||
return Promise.all( | ||
heightOrHashList.map((heightOrHash) => this.blockService.getBlock(heightOrHash)), | ||
); | ||
}; | ||
} | ||
} | ||
|
||
@Injectable() | ||
export class BlockTransactionsLoader | ||
implements NestDataLoader<string, BaseTransaction[]> { | ||
private logger = new Logger(BlockTransactionsLoader.name); | ||
|
||
constructor(private readonly blockService: BlockService) { } | ||
|
||
public getBatchFunction() { | ||
return (hashs: string[]) => { | ||
this.logger.debug(`Loading transactions for blocks: ${hashs.join(', ')}`); | ||
return Promise.all(hashs.map((key) => this.blockService.getBlockTransactions(key))); | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,19 @@ | ||
import { Resolver } from '@nestjs/graphql'; | ||
import { Transaction } from './transaction.model'; | ||
import DataLoader from 'dataloader'; | ||
import { Parent, ResolveField, Resolver } from '@nestjs/graphql'; | ||
import { Transaction, BaseTransaction } from './transaction.model'; | ||
import { Block, BaseBlock } from '../block/block.model'; | ||
import { Loader } from '@applifting-io/nestjs-dataloader'; | ||
import { BlockLoader } from '../block/block.dataloader'; | ||
|
||
@Resolver(() => Transaction) | ||
export class TransactionResolver {} | ||
export class TransactionResolver { | ||
@ResolveField(() => Block) | ||
public async block( | ||
@Parent() transaction: BaseTransaction, | ||
@Loader(BlockLoader) | ||
blockLoader: DataLoader<string, BaseBlock>, | ||
): Promise<BaseBlock> { | ||
const block = await blockLoader.load(transaction.blockNumber.toString()); | ||
return block; | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.