11import { ParentCache } from '@isograph/react-disposable-state' ;
2+ import type { Brand } from './brand' ;
3+ import type { NetworkResponseValue } from './cache' ;
24import {
35 IsographEntrypoint ,
46 IsographOperation ,
@@ -15,7 +17,6 @@ import { LogFunction, WrappedLogFunction } from './logging';
1517import { PromiseWrapper , wrapPromise } from './PromiseWrapper' ;
1618import { WithEncounteredRecords } from './read' ;
1719import type { ReaderAst , StartUpdate } from './reader' ;
18- import type { Brand } from './brand' ;
1920
2021export type ComponentOrFieldName = string ;
2122export type StringifiedArgs = string ;
@@ -48,7 +49,7 @@ export type AnyRecordSubscription = {
4849} ;
4950
5051export type Subscription =
51- | FragmentSubscription < any >
52+ | FragmentSubscription < UnknownTReadFromStore >
5253 | AnyChangesToRecordSubscription
5354 | AnyRecordSubscription ;
5455export type Subscriptions = Set < Subscription > ;
@@ -84,10 +85,47 @@ export type MissingFieldHandler = (
8485 variables : Variables | null ,
8586) => StoreLink | undefined ;
8687
88+ export type PayloadData = Record < string , NetworkResponseValue > ;
89+ export interface PayloadExtensions { }
90+ export interface PayloadErrorExtensions { }
91+
92+ export interface GraphQLResponseWithExtensionsOnly {
93+ data : null ;
94+ extensions : PayloadExtensions ;
95+ }
96+ export interface PayloadError {
97+ message : string ;
98+ locations ?: { line : number ; column : number } [ ] ;
99+ path ?: ( string | number ) [ ] ;
100+ extensions ?: PayloadErrorExtensions ;
101+ }
102+
103+ export type PayloadErrors = [ PayloadError , ...PayloadError [ ] ] ;
104+
105+ interface GraphQLResponseWithoutData {
106+ data : PayloadData ;
107+ extensions ?: PayloadExtensions ;
108+ errors ?: PayloadErrors ;
109+ label ?: 'string' ;
110+ path ?: '(string|number)[]' ;
111+ }
112+ interface GraphQLResponseWithData {
113+ data : PayloadData ;
114+ extensions ?: PayloadExtensions ;
115+ label ?: string | undefined ;
116+ path ?: ( string | number ) [ ] | undefined ;
117+ errors ?: PayloadErrors ;
118+ }
119+
120+ export type GraphqlResponse =
121+ | GraphQLResponseWithExtensionsOnly
122+ | GraphQLResponseWithoutData
123+ | GraphQLResponseWithData ;
124+
87125export type IsographNetworkFunction = (
88126 operation : IsographOperation | IsographPersistedOperation ,
89127 variables : Variables ,
90- ) => Promise < any > ;
128+ ) => Promise < GraphqlResponse > ;
91129
92130export interface Link < T extends TypeName > extends StoreLink {
93131 readonly __link : Brand < DataId , T > ;
@@ -125,12 +163,17 @@ export type DataId = string;
125163
126164export const ROOT_ID : DataId & '__ROOT' = '__ROOT' ;
127165
166+ export interface WithErrors < T > {
167+ readonly record : T ;
168+ readonly errors : Record < DataId | string , PayloadErrors > ;
169+ }
170+
128171export type IsographStore = {
129172 [ index : TypeName ] : {
130- [ index : DataId ] : StoreRecord | null ;
173+ [ index : DataId ] : WithErrors < StoreRecord > ;
131174 } | null ;
132175 readonly Query : {
133- readonly __ROOT : StoreRecord ;
176+ readonly __ROOT : WithErrors < StoreRecord > ;
134177 } ;
135178} ;
136179
@@ -163,7 +206,10 @@ export function createIsographEnvironment(
163206export function createIsographStore ( ) : IsographStore {
164207 return {
165208 Query : {
166- [ ROOT_ID ] : { } ,
209+ [ ROOT_ID ] : {
210+ errors : { } ,
211+ record : { } ,
212+ } ,
167213 } ,
168214 } ;
169215}
0 commit comments