Skip to content

Commit

Permalink
Merge pull request #69 from proto-kit/feature/graphql-client
Browse files Browse the repository at this point in the history
Added graphql client modules
  • Loading branch information
maht0rz authored Nov 2, 2023
2 parents 52b50d0 + 8d3613d commit 8d51b8b
Show file tree
Hide file tree
Showing 23 changed files with 638 additions and 261 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
8 changes: 8 additions & 0 deletions packages/api/src/graphql/GraphqlServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,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 Down
12 changes: 9 additions & 3 deletions packages/api/src/graphql/modules/QueryGraphqlModule.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// eslint-disable-next-line max-len
/* eslint-disable @typescript-eslint/no-explicit-any,@typescript-eslint/no-unsafe-argument,@typescript-eslint/no-unsafe-assignment,putout/putout,max-lines,guard-for-in,@typescript-eslint/consistent-type-assertions */
import { inject, injectable } from "tsyringe";
import { Resolver } from "type-graphql";
import { inject } from "tsyringe";
import { Arg, Query as GraphqlQuery } from "type-graphql";
import {
GraphQLBoolean,
GraphQLFieldConfig,
Expand Down Expand Up @@ -35,7 +35,7 @@ import {
QueryGetterStateMap,
QueryTransportModule,
NetworkStateQuery,
BlockStorage
BlockStorage,
} from "@proto-kit/sequencer";
import { graphqlModule, SchemaGeneratingGraphqlModule } from "../GraphqlModule";
import {
Expand Down Expand Up @@ -78,6 +78,12 @@ export class QueryGraphqlModule<
super();
}

@GraphqlQuery(() => [String], { nullable: true })
public async state(@Arg("path") path: string): Promise<string[] | undefined> {
const value = await this.queryTransportModule.get(Field(path));
return value?.map((field) => field.toString());
}

private jsonPrimitiveToGraphqlType(value: any): GraphQLScalarType {
switch (typeof value) {
case "symbol":
Expand Down
17 changes: 0 additions & 17 deletions packages/api/test/compile.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/common/src/dependencyFactory/DependencyFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ export abstract class DependencyFactory {
public initDependencies(container: DependencyContainer) {
const dependencies =
globalFactoryDependencies.get(this.constructor.name) ?? {};
globalFactoryDependencies.delete(this.constructor.name);

for (const [key, useFactory] of Object.entries(dependencies)) {
container.register(`${key}_singleton-prototype`, {
Expand Down
5 changes: 5 additions & 0 deletions packages/common/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,8 @@ export function noop(): void {}
export interface ToFieldable {
toFields: () => Field[];
}

export async function sleep(ms: number) {
// eslint-disable-next-line promise/avoid-new,no-promise-executor-return
await new Promise((resolve) => setTimeout(resolve, ms));
}
8 changes: 4 additions & 4 deletions packages/module/src/runtime/MethodIdResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ export class MethodIdResolver {
}

public getMethodNameFromId(methodId: bigint): [string, string] | undefined {
const { moduleName, methodName } = this.dictionary[methodId.toString()];
const methodPath = this.dictionary[methodId.toString()];

// eslint-disable-next-line no-warning-comments
// TODO Replace by throwing exception?
if (moduleName === undefined || methodName === undefined) {
if (methodPath === undefined) {
return undefined;
}

const { moduleName, methodName } = methodPath;

this.runtime.assertIsValidModuleName(this.modules, moduleName);

return [moduleName, methodName];
Expand Down
3 changes: 2 additions & 1 deletion packages/sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@
"test:file": "node --experimental-vm-modules --experimental-wasm-modules --experimental-wasm-threads ../../node_modules/jest/bin/jest.js",
"test": "npm run test:file -- ./src/** ./test/**",
"test:watch": "npm run test:file -- ./src/** ./test/** --watch",
"graphql": "cd ../api && npm run build && cd ../sdk && npm run build && node --experimental-vm-modules --experimental-wasm-modules --experimental-wasm-threads --es-module-specifier-resolution=node ./dist/graphql.js"
"graphql": "cd ../api && npm run build && cd ../sdk && npm run test:file -- test/graphql/run-graphql.test.ts"
},
"main": "dist/index.js",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@urql/core": "^4.1.4",
"comlink": "^4.4.1",
"lodash": "^4.17.21",
"loglevel": "^1.8.1"
Expand Down
Loading

0 comments on commit 8d51b8b

Please sign in to comment.