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

Added graphql client modules #69

Merged
merged 6 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
52 changes: 52 additions & 0 deletions package-lock.json

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

8 changes: 8 additions & 0 deletions packages/api/src/graphql/GraphqlServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,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
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
1 change: 1 addition & 0 deletions packages/sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"access": "public"
},
"dependencies": {
"@urql/core": "^4.1.4",
"comlink": "^4.4.1",
"lodash": "^4.17.21",
"loglevel": "^1.8.1"
Expand Down
15 changes: 7 additions & 8 deletions packages/sdk/src/appChain/AppChain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ import {
Sequencer,
SequencerModulesRecord,
UnsignedTransaction,
MockStorageDependencyFactory
MockStorageDependencyFactory,
QueryTransportModule,
} from "@proto-kit/sequencer";
import {
NetworkState,
Expand All @@ -35,7 +36,6 @@ import { Field, FlexibleProvable, PublicKey, UInt64 } from "o1js";
import { AppChainTransaction } from "../transaction/AppChainTransaction";
import { Signer } from "../transaction/InMemorySigner";
import { TransactionSender } from "../transaction/InMemoryTransactionSender";
import { StateServiceQueryModule } from "../query/StateServiceQueryModule";

import { AppChainModule } from "./AppChainModule";
import { AreProofsEnabledFactory } from "./AreProofsEnabledFactory";
Expand Down Expand Up @@ -190,9 +190,8 @@ export class AppChain<
protocol: Query<ProtocolModule<unknown>, ProtocolModules>;
network: NetworkStateQuery;
} {
const queryTransportModule = this.resolveOrFail(
"QueryTransportModule",
StateServiceQueryModule
const queryTransportModule = this.container.resolve<QueryTransportModule>(
"QueryTransportModule"
);

const network = new NetworkStateQuery(
Expand Down Expand Up @@ -283,7 +282,7 @@ export class AppChain<
const runtimeModule = this.runtime.resolve(moduleName as any);

// find types of args for the runtime method thats being called
const paramTypes: FlexibleProvable<unknown>[] = Reflect.getMetadata(
const parameterTypes: FlexibleProvable<unknown>[] = Reflect.getMetadata(
"design:paramtypes",
runtimeModule,
methodName
Expand All @@ -293,8 +292,8 @@ export class AppChain<
* Use the type info obtained previously to convert
* the args passed to fields
*/
const argsFields = args.flatMap((arg, index) =>
paramTypes[index].toFields(arg)
const argsFields = args.flatMap((argument, index) =>
parameterTypes[index].toFields(argument)
);

const unsignedTransaction = new UnsignedTransaction({
Expand Down
Loading
Loading