Skip to content

Commit

Permalink
feat: working on adding types everywhere possible
Browse files Browse the repository at this point in the history
  • Loading branch information
Siddharth9890 committed Oct 30, 2023
1 parent 54e59e8 commit 2cc363d
Show file tree
Hide file tree
Showing 8 changed files with 132 additions and 17 deletions.
27 changes: 19 additions & 8 deletions custom-fetch.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
import { MeshContext } from "@graphql-mesh/runtime";
import { fetch } from "@whatwg-node/fetch";
import { Headers, fetch } from "@whatwg-node/fetch";
import { MeshContext } from "./.mesh";

type ContextModified = MeshContext & {
token: string;
apiKey: string;
};

export default function patchedFetch(
url: string,
init: any,
context: MeshContext
init: RequestInit,
context: ContextModified
) {
console.debug(url, init.headers);
init.headers["Authorization"] =
"Bearer your-token";

const headers = new Headers();
headers.set(
"accept",
"application/graphql-response+json application/json multipart/mixed"
);
headers.set("content-type", "application/json");
headers.set("Authorization", `Bearer ${context.token}`);
headers.set("X-Api-Key", context.apiKey);
init.headers = headers;
console.log(url, init);
return fetch(url, init);
}
27 changes: 22 additions & 5 deletions index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,29 @@
import { getMeshSDK } from "./.mesh/index";
import { Gateway } from "./src/Gateway";
import { UserIdentifierType } from "./types";

async function test() {
const sdk = getMeshSDK();
const api = new Gateway({
apiKey: "m9Y5ntNcTlwQ2LbRpYr6K_VhxJXuZJ6Q",
token:
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJwcm90b2NvbF9pZCI6IjkwNzcwODA2LWFlMGMtNGExNS05MjYzLWU5MWJhYWY1ZDkzZiIsImF1dGgiOnsiaWQiOiJlMjJiOWZkNi05NjgzLTRjZDgtOGZlOS1lZWU0YzFmYTJjZjciLCJ0eXBlIjoiV0FMTEVUIn0sImNyeXB0byI6eyJwdWJsaWNQZW0iOiItLS0tLUJFR0lOIFBVQkxJQyBLRVktLS0tLVxyXG5NSUlDSWpBTkJna3Foa2lHOXcwQkFRRUZBQU9DQWc4QU1JS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YXV0aF90b2tlbiIsImlhdCI6MTY5ODIxMTg0N30.zUxmPhnrQlIEZ5pMzHBMFkcqPvjsIfs0er9Dylw5olE",
});

let obj = {
dataModelId: "f4014d53-b30f-4490-9812-cea379a1b398",
description: "test",
title: "test",
claim: {
gatewayUse: "test",
},
owner: {
type: UserIdentifierType.EMAIL,
value: "sid",
},
};
try {
const { me } = await sdk.me_query();
console.log(me.createdAt);
} catch (error) {
const { createPDA } = await api.pda.createPDA(obj);
console.log(createPDA.id, createPDA.issuerHash);
} catch (error: any) {
console.log(error);
}
}
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"@graphql-mesh/cli": "^0.87.14",
"@graphql-mesh/graphql": "^0.95.7",
"@graphql-mesh/runtime": "^0.96.11",
"@graphql-mesh/transform-naming-convention": "^0.95.8",
"@types/node": "^20.8.4",
"@whatwg-node/fetch": "^0.9.13",
"graphql": "^16.8.1"
Expand Down
39 changes: 35 additions & 4 deletions pnpm-lock.yaml

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

15 changes: 15 additions & 0 deletions src/Auth.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { createWalletNonce_mutationMutation } from "../.mesh";

export class Auth {
private sdk: any;

constructor(sdk: any) {
this.sdk = sdk;
}

async createWalletNounce(
wallet: string
): Promise<createWalletNonce_mutationMutation> {
return await this.sdk.createWalletNonce_mutation({ input: { wallet } });
}
}
19 changes: 19 additions & 0 deletions src/Gateway.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Auth } from "./Auth";
import { PDA } from "./PDA";
import { getMeshSDK, MeshContext } from "../.mesh";

export class Gateway {
// public auth: Auth;
public pda: PDA;
private sdk: any;

constructor({ apiKey, token }: { apiKey: string; token: string }) {
if (!apiKey && !token) throw new Error("No token found");
this.sdk = getMeshSDK({
apiKey,
token,
});
// this.auth = new Auth();
this.pda = new PDA(this.sdk);
}
}
14 changes: 14 additions & 0 deletions src/PDA.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { CreatePDAInput, createPDA_mutationMutation } from "../.mesh";

export class PDA {
private sdk: any;

constructor(sdk: any) {
this.sdk = sdk;
}
async createPDA(
pdaInput: CreatePDAInput
): Promise<createPDA_mutationMutation> {
return await this.sdk.createPDA_mutation({ input: pdaInput });
}
}
7 changes: 7 additions & 0 deletions types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export enum UserIdentifierType {
EMAIL,
EVM,
GATEWAY_ID,
SOLANA,
USER_ID,
}

0 comments on commit 2cc363d

Please sign in to comment.