Skip to content

Commit

Permalink
graphql test
Browse files Browse the repository at this point in the history
  • Loading branch information
bob2402 committed Apr 29, 2024
1 parent 9ae1685 commit 45bfe4d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
15 changes: 10 additions & 5 deletions main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ import {
} from "./resolvers/event.ts";
import Landing from "./routes/landing.tsx";
import Error404 from "./routes/_404.tsx";
import { RelayInformation, RelayInformationStore, RelayInformationStringify, informationPubkeyStringify } from "./resolvers/nip11.ts";
import {
informationPubkeyStringify,
RelayInformation,
RelayInformationStore,
RelayInformationStringify,
} from "./resolvers/nip11.ts";
import {
EventStore,
func_GetEventsByFilter,
Expand Down Expand Up @@ -230,7 +235,7 @@ export const software = "https://github.com/BlowaterNostr/relayed";

const landing_handler = async (args: { relayInformationStore: RelayInformationStore }) => {
const storeInformation = await args.relayInformationStore.resolveRelayInformation();
if(storeInformation instanceof Error) {
if (storeInformation instanceof Error) {
return new Response(render(Error404()), { status: 404 });
}
const resp = new Response(
Expand All @@ -242,10 +247,10 @@ const landing_handler = async (args: { relayInformationStore: RelayInformationSt

const information_handler = async (args: { relayInformationStore: RelayInformationStore }) => {
const storeInformation = await args.relayInformationStore.resolveRelayInformation();
if(storeInformation instanceof Error) {
if (storeInformation instanceof Error) {
return new Response(render(Error404()), { status: 404 });
}
const information = informationPubkeyStringify(storeInformation)
const information = informationPubkeyStringify(storeInformation);
const resp = new Response(JSON.stringify(information), {
status: 200,
});
Expand All @@ -266,7 +271,7 @@ async function verifyToken(event: NostrEvent, relayInformationStore: RelayInform
throw new Error("pubkey not valid");
}
const storeInformation = await relayInformationStore.resolveRelayInformation();
if(storeInformation instanceof Error) {
if (storeInformation instanceof Error) {
throw new Error("store pubkey not valid");
}
if (pubkey.hex !== storeInformation.pubkey.hex) {
Expand Down
5 changes: 3 additions & 2 deletions resolvers/nip11.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ type RelayInfomationBase = {
description?: string;
contact?: string;
icon?: string;
}
};

export type RelayInformationStringify = {
pubkey?: string;
Expand Down Expand Up @@ -47,7 +47,8 @@ export class RelayInformationStore {
}

resolveRelayInformation = async (): Promise<RelayInformation | Error> => {
const store_information_i = (await this.kv.get<RelayInformationStringify>(["relay_information"])).value;
const store_information_i =
(await this.kv.get<RelayInformationStringify>(["relay_information"])).value;
if (!store_information_i) {
return { ...this.default_information, ...not_modifiable_information };
}
Expand Down
2 changes: 1 addition & 1 deletion test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ async function queryGql(relay: Relay, query: string, variables?: object) {
const res = await fetch(`http://${hostname}:${port}/api`, {
method: "POST",
headers: {
"cookie": `token="${test_auth_event()}`,
"cookie": `token="${await test_auth_event()}`,
"Content-Type": "application/json",
},
body: JSON.stringify({ query, variables }),
Expand Down

0 comments on commit 45bfe4d

Please sign in to comment.