add support for fetch (naive) response type

This commit is contained in:
DrakeTDL 2023-10-21 13:18:37 -07:00
parent 4a64fa6df5
commit f7627a1caa
No known key found for this signature in database
2 changed files with 24 additions and 3 deletions

View File

@ -1,5 +1,26 @@
import { type AuthorizationError } from "../utils/AuthorizationError.ts"
import { ResponseError } from "../utils/ResponseError.ts"
import { Mutation, Query } from "./generated/graphql.ts"
type Primitive = string | Function | number | boolean | Symbol | undefined | null
/** Deeply omit members of an array of interface or array of type. */
export type DeepOmitArray<T extends any[], K> = {
[P in keyof T]: DeepOmit<T[P], K>
}
/**
* Deeply omit members of an interface or type.
* https://gist.github.com/ahuggins-nhs/826906a58e4c1e59306bc0792e7826d1?permalink_comment_id=4498424#gistcomment-4498424
*/
type DeepOmit<T, K> = T extends Primitive ? T : {
[P in Exclude<keyof T, K>]: //extra level of indirection needed to trigger homomorhic behavior
T[P] extends infer TP // distribute over unions
? TP extends Primitive ? TP // leave primitives and functions alone
: TP extends any[] ? DeepOmitArray<TP, K> // Array special handling
: DeepOmit<TP, K>
: never
}
export type Fields<in Q extends (...args: any) => any> = {
operation: ReturnType<Q>
@ -47,6 +68,6 @@ export type Fetch = {
init: { query: string; token?: string },
): Promise<Response | ResponseError>
}
export type Response<T = Record<string, any>> = {
data: T
export type Response = {
data: DeepOmit<Query & Mutation, "__typename">
}

View File

@ -4,7 +4,7 @@ export type ResponseError = {
status: number
locations: Array<Record<"line" | "column", number>>
}>
data: Record<string, unknown>
data: Record<string, null>
}
export const ResponseError = class extends Error {