Skip to content

Commit ab5be31

Browse files
committed
throw errors for each component
1 parent 9a26637 commit ab5be31

File tree

9 files changed

+369
-119
lines changed

9 files changed

+369
-119
lines changed

libs/isograph-react/src/core/IsographEnvironment.ts

Lines changed: 52 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { ParentCache } from '@isograph/react-disposable-state';
2+
import type { Brand } from './brand';
3+
import type { NetworkResponseValue } from './cache';
24
import {
35
IsographEntrypoint,
46
IsographOperation,
@@ -15,7 +17,6 @@ import { LogFunction, WrappedLogFunction } from './logging';
1517
import { PromiseWrapper, wrapPromise } from './PromiseWrapper';
1618
import { WithEncounteredRecords } from './read';
1719
import type { ReaderAst, StartUpdate } from './reader';
18-
import type { Brand } from './brand';
1920

2021
export type ComponentOrFieldName = string;
2122
export type StringifiedArgs = string;
@@ -48,7 +49,7 @@ export type AnyRecordSubscription = {
4849
};
4950

5051
export type Subscription =
51-
| FragmentSubscription<any>
52+
| FragmentSubscription<UnknownTReadFromStore>
5253
| AnyChangesToRecordSubscription
5354
| AnyRecordSubscription;
5455
export 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+
87125
export type IsographNetworkFunction = (
88126
operation: IsographOperation | IsographPersistedOperation,
89127
variables: Variables,
90-
) => Promise<any>;
128+
) => Promise<GraphqlResponse>;
91129

92130
export interface Link<T extends TypeName> extends StoreLink {
93131
readonly __link: Brand<DataId, T>;
@@ -125,12 +163,17 @@ export type DataId = string;
125163

126164
export 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+
128171
export 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(
163206
export function createIsographStore(): IsographStore {
164207
return {
165208
Query: {
166-
[ROOT_ID]: {},
209+
[ROOT_ID]: {
210+
errors: {},
211+
record: {},
212+
},
167213
},
168214
};
169215
}

0 commit comments

Comments
 (0)