Skip to content
This repository has been archived by the owner on Jul 20, 2023. It is now read-only.

Add SelectionResult type to make type alias extraction easier #111

Merged
merged 1 commit into from
Apr 29, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion codegen/src/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export const render = (sdl: string): string => {
selectionSet
} from '@timkendall/tql'

export type { Result, Variables } from '@timkendall/tql'
export type { Result, SelectionResult, Variables } from '@timkendall/tql'
export { $ } from '@timkendall/tql'

` +
Expand Down
8 changes: 8 additions & 0 deletions src/Result.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { ResultOf, TypedDocumentNode } from "@graphql-typed-document-node/core";
import { L, Test } from "ts-toolbelt";

import type { Field, InlineFragment, NamedType, Selection, SelectionSet } from "./AST";
import type { Selection as SchemaSelection } from "./Selection"

// @note `Result` takes a root `Type` (TS) and `SelectionSet` (GQL) and recursively walks the
// array of `Selection` nodes's (i.e `Field`, `InlineFragment`, or `FragmentSpread` nodes)
Expand Down Expand Up @@ -81,3 +83,9 @@ type HasInlineFragment<T extends SelectionSet<any> | undefined> = T extends Sele
: never;

type Merge<M, N> = Omit<M, keyof N> & N;

export type SelectionResult<TSelection> =
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yeah I was planning on actually making this the default for our standard Result type. Thoughts on renaming our existing Result to InnerResult instead (so we can export this higher-level API as Result)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, that sounds better.

I wanted to avoid a breaking change, but I can update that if you prefer exposing as Result.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True. Let's go with this for now.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And as always thank you for your contribution!

TSelection extends { toQuery(opts: any): TypedDocumentNode<infer ResultType, infer _VariablesType> }
? ResultType
: never;