Skip to content

Commit

Permalink
Lint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
benjie committed Feb 1, 2024
1 parent c4389a4 commit af36a5e
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 28 deletions.
17 changes: 10 additions & 7 deletions postgraphile/postgraphile/graphile.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,13 +260,16 @@ const preset: GraphileConfig.Preset = {
},
Subscription: {
// Test via SQL: `NOTIFY test, '{"a":40}';`
sub: EXPORTABLE((context, jsonParse, listen, object) => (_$root, args) => {
const $topic = args.get("topic");
const $pgSubscriber = context().get("pgSubscriber");
return listen($pgSubscriber, $topic, ($payload) =>
object({ sub: jsonParse($payload).get("a" as never) }),
);
}, [context, jsonParse, listen, object]),
sub: EXPORTABLE(
(context, jsonParse, listen, object) => (_$root, args) => {
const $topic = args.get("topic");
const $pgSubscriber = context().get("pgSubscriber");
return listen($pgSubscriber, $topic, ($payload) =>
object({ sub: jsonParse($payload).get("a" as never) }),
);
},
[context, jsonParse, listen, object],
),
gql: {
resolve: EXPORTABLE(
() =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,28 @@ export const PgV4SimpleSubscriptionsPlugin = makeExtendSchemaPlugin((build) => {
},
},
ListenPayload: {
event: EXPORTABLE(() => ($event) => {
return $event.get("event");
}, []),
event: EXPORTABLE(
() => ($event) => {
return $event.get("event");
},
[],
),
...(nodeIdHandlerByTypeName
? {
relatedNodeId: EXPORTABLE((nodeIdFromEvent) => ($event) => {
return nodeIdFromEvent($event);
}, [nodeIdFromEvent]),
relatedNode: EXPORTABLE((node, nodeIdFromEvent, nodeIdHandlerByTypeName) => ($event) => {
const $nodeId = nodeIdFromEvent($event);
return node(nodeIdHandlerByTypeName, $nodeId);
}, [node, nodeIdFromEvent, nodeIdHandlerByTypeName]),
relatedNodeId: EXPORTABLE(
(nodeIdFromEvent) => ($event) => {
return nodeIdFromEvent($event);
},
[nodeIdFromEvent],
),
relatedNode: EXPORTABLE(
(node, nodeIdFromEvent, nodeIdHandlerByTypeName) =>
($event) => {
const $nodeId = nodeIdFromEvent($event);
return node(nodeIdHandlerByTypeName, $nodeId);
},
[node, nodeIdFromEvent, nodeIdHandlerByTypeName],
),
}
: null),
},
Expand All @@ -73,15 +83,22 @@ export const PgV4SimpleSubscriptionsPlugin = makeExtendSchemaPlugin((build) => {
}, "PgV4SimpleSubscriptionsPlugin");

// base64JSON codec copy
const nodeObjToNodeId = EXPORTABLE(() => function nodeObjToNodeId(obj: any[] | undefined): string | null {
if (!obj) return null;
return Buffer.from(JSON.stringify(obj), "utf8").toString("base64");
}, []);
const nodeObjToNodeId = EXPORTABLE(
() =>
function nodeObjToNodeId(obj: any[] | undefined): string | null {
if (!obj) return null;
return Buffer.from(JSON.stringify(obj), "utf8").toString("base64");
},
[],
);

// WARNING: this function assumes that you're using the `base64JSON` NodeID codec, which was the case for PostGraphile V4. If you are not doing so, YMMV.
const nodeIdFromEvent = EXPORTABLE((lambda, nodeObjToNodeId) => function nodeIdFromEvent($event: JSONParseStep<{ __node__?: any[] }>) {
const $nodeObj = $event.get("__node__");
const $nodeId = lambda($nodeObj, nodeObjToNodeId);
return $nodeId;
}, [lambda, nodeObjToNodeId]);

const nodeIdFromEvent = EXPORTABLE(
(lambda, nodeObjToNodeId) =>
function nodeIdFromEvent($event: JSONParseStep<{ __node__?: any[] }>) {
const $nodeObj = $event.get("__node__");
const $nodeId = lambda($nodeObj, nodeObjToNodeId);
return $nodeId;
},
[lambda, nodeObjToNodeId],
);
1 change: 0 additions & 1 deletion utils/graphile-export/src/exportSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import type { URL } from "node:url";
import { inspect } from "node:util";

import generate from "@babel/generator";
import type { ParseResult } from "@babel/parser";
import { parse } from "@babel/parser";
import type { TemplateBuilderOptions } from "@babel/template";
import template from "@babel/template";
Expand Down

0 comments on commit af36a5e

Please sign in to comment.