import { DefinitionNode , DocumentNode , print } from "graphql" ; export declare type GFetchQueryDefault = { errors ? : Error [ ] ; gQueryStatus : "LOADED" ; } ; type OptionalPropertyNames < T > = { [ K in keyof T ] - ? : { } extends { [ P in K ] : T [ K ] ; } ? K : never ; } [ keyof T ] ; type SpreadProperties < L , R , K extends keyof L & keyof R > = { [ P in K ] : L [ P ] | Exclude < R [ P ] , undefined > ; } ; type Id < T > = T extends infer U ? { [ K in keyof U ] : U [ K ] ; } : never ; type SpreadTwo < L , R > = Id < Pick < L , Exclude < keyof L , keyof R > > & Pick < R , Exclude < keyof R , OptionalPropertyNames < R > > > & Pick < R , Exclude < OptionalPropertyNames < R > , keyof L > > & SpreadProperties < L , R , OptionalPropertyNames < R > & keyof L > > ; type Spread < A extends readonly [ ... any ] > = A extends [ infer L , ... infer R ] ? SpreadTwo < L , Spread < R > > : unknown ; export declare type GFetchQueries = { query : DocumentNode ; variables ? : Record < string , unknown > ; } ; export const stringifyDocument = ( node ) : string => { let str = ( typeof node !== "string" ? print ( node ) : node ) . replace ( /([\s,]|#[^\n\r]+)+/g , " " ) . trim ( ) ; return str ; } ; type gFetchProperties = { queries : GFetchQueries [ ] ; fetch : typeof fetch ; } ; export type GClientOptions = { path ? : string ; } ; export type GGetParameters < Variables > = { variables ? : Variables ; fetch : typeof fetch ; } ; export type GFetchReturnWithErrors < T > = Spread < [ T , GFetchQueryDefault ] > ; export class GFetch extends Object { public path : string ; constructor ( options ) { super ( ) ; const { path } = options ; this . path = path ; this . fetch = this . fetch . bind ( this ) ; } public async fetch < T > ( { queries , fetch , } ) { let documentString = stringifyDocument ( queries [ 0 ] . query ) ; const newQueries = { ... queries [ 0 ] , query : documentString , } ; const res = await fetch ( this . path , { method : "POST" , credentials : "include" , headers : { "Content-Type" : "application/json" } , body : JSON . stringify ( newQueries ) , } ) ; const data = await res . json ( ) ; return { ... data . data , errors : data . errors , } ; } }