Skip to content

Commit

Permalink
Make type of step used in specFromNodeId more flexible (#465)
Browse files Browse the repository at this point in the history
  • Loading branch information
benjie committed Aug 10, 2023
2 parents b92d596 + f9cc88d commit 1650336
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/dull-guests-kneel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"grafast": patch
---

Make type of step in specFromNodeId more flexible.
8 changes: 6 additions & 2 deletions grafast/grafast/src/steps/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { GraphQLObjectType } from "graphql";
import { isDev } from "../dev.js";
import { inspect } from "../inspect.js";
import type {
AnyInputStep,
ExecutionExtra,
NodeIdCodec,
NodeIdHandler,
Expand Down Expand Up @@ -121,7 +122,7 @@ export function node(

export function specFromNodeId(
handler: NodeIdHandler<any>,
$id: ExecutableStep<string>,
$id: ExecutableStep<string> | AnyInputStep,
) {
function decodeWithCodecAndHandler(raw: string) {
try {
Expand All @@ -136,6 +137,9 @@ export function specFromNodeId(
}
decodeWithCodecAndHandler.displayName = `decode_${handler.typeName}_${handler.codec.name}`;
decodeWithCodecAndHandler.isSyncAndSafe = true; // Optimization
const $decoded = lambda($id, decodeWithCodecAndHandler);
const $decoded = lambda(
$id as ExecutableStep<string>,
decodeWithCodecAndHandler,
);
return handler.getSpec($decoded);
}
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ spec will resolve to null-ish values (or maybe raise an error).
```ts
function specFromNodeId(
handler: NodeIdHandler<any>,
$id: ExecutableStep<string>,
$id: ExecutableStep<string> | AnyInputStep,
): any;
```

Expand Down

0 comments on commit 1650336

Please sign in to comment.