Skip to content

Commit

Permalink
Merge branch 'develop' into feature/tx-validation
Browse files Browse the repository at this point in the history
# Conflicts:
#	packages/sequencer/src/mempool/private/PrivateMempool.ts
  • Loading branch information
rpanic committed Nov 2, 2023
2 parents 5a0b67f + 8d51b8b commit cf3dc89
Show file tree
Hide file tree
Showing 28 changed files with 654 additions and 266 deletions.
84 changes: 75 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"graphql-scalars": "^1.22.4",
"humanize-duration": "^3.30.0",
"lodash": "^4.17.21",
"koa": "^2.14.2",
"reflect-metadata": "^0.1.13",
"type-graphql": "2.0.0-beta.1"
},
Expand All @@ -36,6 +37,7 @@
"devDependencies": {
"@jest/globals": "^29.5.0",
"@types/lodash": "^4.14.194",
"@types/koa": "^2.13.10",
"@types/ws": "^8.5.4"
},
"gitHead": "b2528538c73747d000cc3ea99ee26ee415d8248d"
Expand Down
7 changes: 2 additions & 5 deletions packages/api/src/graphql/GraphqlModule.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import {
ConfigurableModule,
TypedClass,
} from "@proto-kit/common";
import { ConfigurableModule, TypedClass } from "@proto-kit/common";
import { GraphQLSchema } from "graphql/type";
import { injectable, Lifecycle, scoped } from "tsyringe";
import { Resolver } from "type-graphql";
Expand Down Expand Up @@ -31,7 +28,7 @@ export abstract class SchemaGeneratingGraphqlModule<
export function graphqlModule() {
return (
/**
* Check if the target class extends RuntimeModule, while
* Check if the target class extends GraphqlModule, while
* also providing static config presets
*/
target: TypedClass<GraphqlModule<unknown>>
Expand Down
15 changes: 10 additions & 5 deletions packages/api/src/graphql/GraphqlSequencerModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ import {
} from "@proto-kit/common";

import { GraphqlServer } from "./GraphqlServer";
import { SchemaGeneratingGraphqlModule } from "./GraphqlModule";
import { GraphqlModule, SchemaGeneratingGraphqlModule } from "./GraphqlModule";

export type GraphqlModulesRecord = ModulesRecord<any>;
export type GraphqlModulesRecord = ModulesRecord<
TypedClass<GraphqlModule<unknown>>
>;

export interface GraphqlModulesDefintion<
GraphQLModules extends GraphqlModulesRecord
Expand Down Expand Up @@ -48,7 +50,7 @@ export class GraphqlSequencerModule<GraphQLModules extends GraphqlModulesRecord>
public async start(): Promise<void> {
assert(this.graphqlServer !== undefined);

this.graphqlServer.setContext(this.container);
this.graphqlServer.setContainer(this.container);

// eslint-disable-next-line guard-for-in
for (const moduleName in this.definition.modules) {
Expand All @@ -62,8 +64,11 @@ export class GraphqlSequencerModule<GraphQLModules extends GraphqlModulesRecord>
)
) {
log.debug(`Registering manual schema for ${moduleName}`);
const module: SchemaGeneratingGraphqlModule<unknown> =
this.resolve(moduleName);
// eslint-disable-next-line max-len
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
const module = this.resolve(
moduleName
) as SchemaGeneratingGraphqlModule<unknown>;
this.graphqlServer.registerSchema(module.generateSchema());
}
}
Expand Down
13 changes: 11 additions & 2 deletions packages/api/src/graphql/GraphqlServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import type { GraphqlModule } from "./GraphqlModule";
interface GraphqlServerOptions {
host: string;
port: number;
graphiql: boolean;
}

function assertArrayIsNotEmpty<T>(
Expand All @@ -31,7 +32,7 @@ export class GraphqlServer extends SequencerModule<GraphqlServerOptions> {

private dependencyContainer?: DependencyContainer;

public setContext(container: DependencyContainer) {
public setContainer(container: DependencyContainer) {
this.dependencyContainer = container;
}

Expand Down Expand Up @@ -78,6 +79,14 @@ export class GraphqlServer extends SequencerModule<GraphqlServerOptions> {
},
});

// eslint-disable-next-line no-warning-comments
// TODO Injection token of Graphql Container not respected atm, only class is used

// Instantiate all modules at startup
modules.forEach((module) => {
dependencyContainer?.resolve(module);
});

const schema = [resolverSchema, ...this.schemas].reduce(
(schema1, schema2) =>
stitchSchemas({
Expand All @@ -89,7 +98,7 @@ export class GraphqlServer extends SequencerModule<GraphqlServerOptions> {

const yoga = createYoga<Koa.ParameterizedContext>({
schema,
graphiql: true,
graphiql: this.config.graphiql,
});

// Bind GraphQL Yoga to `/graphql` endpoint
Expand Down
5 changes: 1 addition & 4 deletions packages/api/src/graphql/modules/MempoolResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,8 @@ export class TransactionObject {

@graphqlModule()
export class MempoolResolver extends GraphqlModule<object> {
private readonly mempool: Mempool;

public constructor(@inject("Mempool") mempool: Mempool) {
public constructor(@inject("Mempool") private readonly mempool: Mempool) {
super();
this.mempool = mempool;
}

@Mutation(() => String)
Expand Down
Loading

0 comments on commit cf3dc89

Please sign in to comment.