@isograph/react 0.0.0-main-ad899464 → 0.0.0-main-084bfeee
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/FragmentReference.d.ts +7 -7
- package/dist/IsographEnvironment.d.ts +12 -12
- package/dist/IsographEnvironmentProvider.d.ts +2 -2
- package/dist/PromiseWrapper.d.ts +1 -1
- package/dist/cache.d.ts +2 -4
- package/dist/cache.js +1 -1
- package/dist/entrypoint.d.ts +21 -21
- package/dist/garbageCollection.d.ts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/read.d.ts +2 -2
- package/dist/read.js +5 -8
- package/dist/reader.d.ts +50 -33
- package/dist/useResult.js +4 -5
- package/dist/util.d.ts +4 -4
- package/package.json +5 -4
- package/src/FragmentReference.ts +11 -7
- package/src/IsographEnvironment.tsx +12 -12
- package/src/IsographEnvironmentProvider.tsx +2 -2
- package/src/PromiseWrapper.ts +1 -1
- package/src/cache.ts +12 -13
- package/src/entrypoint.ts +26 -21
- package/src/garbageCollection.ts +2 -2
- package/src/index.ts +6 -3
- package/src/read.ts +15 -19
- package/src/reader.ts +86 -39
- package/src/tests/__isograph/Query/meName/entrypoint.ts +2 -2
- package/src/tests/__isograph/Query/meName/output_type.ts +1 -3
- package/src/tests/__isograph/Query/meName/reader.ts +6 -8
- package/src/tests/__isograph/Query/meNameSuccessor/entrypoint.ts +2 -2
- package/src/tests/__isograph/Query/meNameSuccessor/output_type.ts +1 -3
- package/src/tests/__isograph/Query/meNameSuccessor/reader.ts +6 -8
- package/src/tests/__isograph/Query/nodeField/entrypoint.ts +2 -2
- package/src/tests/__isograph/Query/nodeField/output_type.ts +1 -3
- package/src/tests/__isograph/Query/nodeField/reader.ts +6 -8
- package/src/useResult.ts +4 -5
- package/src/util.ts +4 -4
@@ -1,14 +1,14 @@
|
|
1
1
|
import { DataId } from './IsographEnvironment';
|
2
|
-
import {
|
3
|
-
import {
|
2
|
+
import { RefetchQueryNormalizationArtifactWrapper } from './entrypoint';
|
3
|
+
import { TopLevelReaderArtifact } from './reader';
|
4
4
|
export type Variable = any;
|
5
5
|
export type Variables = {
|
6
6
|
readonly [index: string]: Variable;
|
7
7
|
};
|
8
8
|
export type FragmentReference<TReadFromStore extends Object, TClientFieldValue> = {
|
9
|
-
kind: 'FragmentReference';
|
10
|
-
readerArtifact:
|
11
|
-
root: DataId;
|
12
|
-
variables: Variables | null;
|
13
|
-
nestedRefetchQueries:
|
9
|
+
readonly kind: 'FragmentReference';
|
10
|
+
readonly readerArtifact: TopLevelReaderArtifact<TReadFromStore, TClientFieldValue, any>;
|
11
|
+
readonly root: DataId;
|
12
|
+
readonly variables: Variables | null;
|
13
|
+
readonly nestedRefetchQueries: RefetchQueryNormalizationArtifactWrapper[];
|
14
14
|
};
|
@@ -29,15 +29,15 @@ type SuspenseCache = {
|
|
29
29
|
[index: string]: ParentCache<any>;
|
30
30
|
};
|
31
31
|
export type IsographEnvironment = {
|
32
|
-
store: IsographStore;
|
33
|
-
networkFunction: IsographNetworkFunction;
|
34
|
-
missingFieldHandler: MissingFieldHandler | null;
|
35
|
-
componentCache: ComponentCache;
|
36
|
-
subscriptions: Subscriptions;
|
37
|
-
suspenseCache: SuspenseCache;
|
38
|
-
retainedQueries: Set<RetainedQuery>;
|
39
|
-
gcBuffer: Array<RetainedQuery>;
|
40
|
-
gcBufferSize: number;
|
32
|
+
readonly store: IsographStore;
|
33
|
+
readonly networkFunction: IsographNetworkFunction;
|
34
|
+
readonly missingFieldHandler: MissingFieldHandler | null;
|
35
|
+
readonly componentCache: ComponentCache;
|
36
|
+
readonly subscriptions: Subscriptions;
|
37
|
+
readonly suspenseCache: SuspenseCache;
|
38
|
+
readonly retainedQueries: Set<RetainedQuery>;
|
39
|
+
readonly gcBuffer: Array<RetainedQuery>;
|
40
|
+
readonly gcBufferSize: number;
|
41
41
|
};
|
42
42
|
export type MissingFieldHandler = (storeRecord: StoreRecord, root: DataId, fieldName: string, arguments_: {
|
43
43
|
[index: string]: any;
|
@@ -46,18 +46,18 @@ export type MissingFieldHandler = (storeRecord: StoreRecord, root: DataId, field
|
|
46
46
|
} | null) => Link | undefined;
|
47
47
|
export type IsographNetworkFunction = (queryText: string, variables: object) => Promise<any>;
|
48
48
|
export type Link = {
|
49
|
-
__link: DataId;
|
49
|
+
readonly __link: DataId;
|
50
50
|
};
|
51
51
|
export type DataTypeValue = undefined | number | boolean | string | null | Link | DataTypeValue[];
|
52
52
|
export type StoreRecord = {
|
53
53
|
[index: DataId | string]: DataTypeValue;
|
54
|
-
id?: DataId;
|
54
|
+
readonly id?: DataId;
|
55
55
|
};
|
56
56
|
export type DataId = string;
|
57
57
|
export declare const ROOT_ID: DataId & '__ROOT';
|
58
58
|
export type IsographStore = {
|
59
59
|
[index: DataId]: StoreRecord | null;
|
60
|
-
__ROOT: StoreRecord;
|
60
|
+
readonly __ROOT: StoreRecord;
|
61
61
|
};
|
62
62
|
export declare function createIsographEnvironment(store: IsographStore, networkFunction: IsographNetworkFunction, missingFieldHandler?: MissingFieldHandler): IsographEnvironment;
|
63
63
|
export declare function createIsographStore(): {
|
@@ -3,8 +3,8 @@ import { ReactNode } from 'react';
|
|
3
3
|
import { type IsographEnvironment } from './IsographEnvironment';
|
4
4
|
export declare const IsographEnvironmentContext: React.Context<IsographEnvironment | null>;
|
5
5
|
export type IsographEnvironmentProviderProps = {
|
6
|
-
environment: IsographEnvironment;
|
7
|
-
children: ReactNode;
|
6
|
+
readonly environment: IsographEnvironment;
|
7
|
+
readonly children: ReactNode;
|
8
8
|
};
|
9
9
|
export declare function IsographEnvironmentProvider({ environment, children, }: IsographEnvironmentProviderProps): React.JSX.Element;
|
10
10
|
export declare function useIsographEnvironment(): IsographEnvironment;
|
package/dist/PromiseWrapper.d.ts
CHANGED
@@ -5,7 +5,7 @@ type NotSet = typeof NOT_SET;
|
|
5
5
|
* Before the promise is resolved, value becomes non-null.
|
6
6
|
*/
|
7
7
|
export type PromiseWrapper<T> = {
|
8
|
-
promise: Promise<T>;
|
8
|
+
readonly promise: Promise<T>;
|
9
9
|
value: Exclude<T, NotSet> | NotSet;
|
10
10
|
};
|
11
11
|
export declare function wrapPromise<T>(promise: Promise<T>): PromiseWrapper<T>;
|
package/dist/cache.d.ts
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
import { ItemCleanupPair, ParentCache } from '@isograph/react-disposable-state';
|
2
2
|
import { PromiseWrapper } from './PromiseWrapper';
|
3
3
|
import { type IsographEnvironment } from './IsographEnvironment';
|
4
|
-
import { IsographEntrypoint, NormalizationLinkedField, NormalizationScalarField } from './entrypoint';
|
4
|
+
import { IsographEntrypoint, NormalizationLinkedField, NormalizationScalarField, RefetchQueryNormalizationArtifact } from './entrypoint';
|
5
5
|
import { ReaderLinkedField, ReaderScalarField } from './reader';
|
6
6
|
import { WithEncounteredRecords } from './read';
|
7
7
|
import { FragmentReference } from './FragmentReference';
|
@@ -16,9 +16,8 @@ declare global {
|
|
16
16
|
* results.
|
17
17
|
*/
|
18
18
|
export declare function stableCopy<T>(value: T): T;
|
19
|
-
type IsoResolver = IsographEntrypoint<any, any>;
|
20
19
|
export declare function getOrCreateCacheForArtifact<TReadFromStore extends Object, TClientFieldValue>(environment: IsographEnvironment, artifact: IsographEntrypoint<TReadFromStore, TClientFieldValue>, variables: object): ParentCache<PromiseWrapper<TClientFieldValue>>;
|
21
|
-
export declare function makeNetworkRequest<T>(environment: IsographEnvironment, artifact:
|
20
|
+
export declare function makeNetworkRequest<T>(environment: IsographEnvironment, artifact: RefetchQueryNormalizationArtifact | IsographEntrypoint<any, any>, variables: object): ItemCleanupPair<PromiseWrapper<T>>;
|
22
21
|
export declare function subscribeToAnyChange(environment: IsographEnvironment, callback: () => void): () => void;
|
23
22
|
export declare function subscribe<TReadFromStore extends Object>(environment: IsographEnvironment, encounteredDataAndRecords: WithEncounteredRecords<TReadFromStore>, fragmentReference: FragmentReference<TReadFromStore, any>, callback: (newEncounteredDataAndRecords: WithEncounteredRecords<TReadFromStore>) => void): () => void;
|
24
23
|
export declare function onNextChange(environment: IsographEnvironment): Promise<void>;
|
@@ -27,4 +26,3 @@ export declare function getParentRecordKey(astNode: NormalizationLinkedField | N
|
|
27
26
|
}): string;
|
28
27
|
export declare const FIRST_SPLIT_KEY = "____";
|
29
28
|
export declare const SECOND_SPLIT_KEY = "___";
|
30
|
-
export {};
|
package/dist/cache.js
CHANGED
@@ -63,7 +63,7 @@ function makeNetworkRequest(environment, artifact, variables) {
|
|
63
63
|
console.log('network response', artifact, artifact);
|
64
64
|
}
|
65
65
|
if (status.kind === 'UndisposedIncomplete') {
|
66
|
-
normalizeData(environment, artifact.normalizationAst, networkResponse.data, variables, artifact.nestedRefetchQueries);
|
66
|
+
normalizeData(environment, artifact.normalizationAst, networkResponse.data, variables, artifact.kind === 'Entrypoint' ? artifact.nestedRefetchQueries : []);
|
67
67
|
const retainedQuery = {
|
68
68
|
normalizationAst: artifact.normalizationAst,
|
69
69
|
variables,
|
package/dist/entrypoint.d.ts
CHANGED
@@ -1,33 +1,33 @@
|
|
1
|
-
import {
|
1
|
+
import { TopLevelReaderArtifact } from './reader';
|
2
2
|
import { Arguments } from './util';
|
3
3
|
export type IsographEntrypoint<TReadFromStore extends Object, TClientFieldValue> = {
|
4
|
-
kind: 'Entrypoint';
|
5
|
-
queryText: string;
|
6
|
-
normalizationAst: NormalizationAst;
|
7
|
-
readerArtifact:
|
8
|
-
nestedRefetchQueries:
|
4
|
+
readonly kind: 'Entrypoint';
|
5
|
+
readonly queryText: string;
|
6
|
+
readonly normalizationAst: NormalizationAst;
|
7
|
+
readonly readerArtifact: TopLevelReaderArtifact<TReadFromStore, TClientFieldValue, any>;
|
8
|
+
readonly nestedRefetchQueries: RefetchQueryNormalizationArtifactWrapper[];
|
9
9
|
};
|
10
10
|
export type NormalizationAstNode = NormalizationScalarField | NormalizationLinkedField;
|
11
|
-
export type NormalizationAst = NormalizationAstNode
|
11
|
+
export type NormalizationAst = ReadonlyArray<NormalizationAstNode>;
|
12
12
|
export type NormalizationScalarField = {
|
13
|
-
kind: 'Scalar';
|
14
|
-
fieldName: string;
|
15
|
-
arguments: Arguments | null;
|
13
|
+
readonly kind: 'Scalar';
|
14
|
+
readonly fieldName: string;
|
15
|
+
readonly arguments: Arguments | null;
|
16
16
|
};
|
17
17
|
export type NormalizationLinkedField = {
|
18
|
-
kind: 'Linked';
|
19
|
-
fieldName: string;
|
20
|
-
arguments: Arguments | null;
|
21
|
-
selections: NormalizationAst;
|
18
|
+
readonly kind: 'Linked';
|
19
|
+
readonly fieldName: string;
|
20
|
+
readonly arguments: Arguments | null;
|
21
|
+
readonly selections: NormalizationAst;
|
22
22
|
};
|
23
|
-
export type
|
24
|
-
kind: 'RefetchQuery';
|
25
|
-
queryText: string;
|
26
|
-
normalizationAst: NormalizationAst;
|
23
|
+
export type RefetchQueryNormalizationArtifact = {
|
24
|
+
readonly kind: 'RefetchQuery';
|
25
|
+
readonly queryText: string;
|
26
|
+
readonly normalizationAst: NormalizationAst;
|
27
27
|
};
|
28
|
-
export type
|
29
|
-
artifact:
|
30
|
-
allowedVariables: string[];
|
28
|
+
export type RefetchQueryNormalizationArtifactWrapper = {
|
29
|
+
readonly artifact: RefetchQueryNormalizationArtifact;
|
30
|
+
readonly allowedVariables: string[];
|
31
31
|
};
|
32
32
|
export declare function assertIsEntrypoint<TReadFromStore extends Object, TClientFieldValue>(value: IsographEntrypoint<TReadFromStore, TClientFieldValue> | ((_: any) => any) | any): asserts value is IsographEntrypoint<TReadFromStore, TClientFieldValue>;
|
33
33
|
export type ExtractReadFromStore<Type> = Type extends IsographEntrypoint<infer X, any> ? X : never;
|
@@ -1,8 +1,8 @@
|
|
1
1
|
import { IsographEnvironment } from './IsographEnvironment';
|
2
2
|
import { NormalizationAst } from './entrypoint';
|
3
3
|
export type RetainedQuery = {
|
4
|
-
normalizationAst: NormalizationAst;
|
5
|
-
variables: {};
|
4
|
+
readonly normalizationAst: NormalizationAst;
|
5
|
+
readonly variables: {};
|
6
6
|
};
|
7
7
|
type DidUnretainSomeQuery = boolean;
|
8
8
|
export declare function unretainQuery(environment: IsographEnvironment, retainedQuery: RetainedQuery): DidUnretainSomeQuery;
|
package/dist/index.d.ts
CHANGED
@@ -5,8 +5,8 @@ export { ROOT_ID, type DataId, type DataTypeValue, type IsographEnvironment, typ
|
|
5
5
|
export { IsographEnvironmentProvider, useIsographEnvironment, type IsographEnvironmentProviderProps, } from './IsographEnvironmentProvider';
|
6
6
|
export { useImperativeReference } from './useImperativeReference';
|
7
7
|
export { EntrypointReader } from './EntrypointReader';
|
8
|
-
export {
|
9
|
-
export { NormalizationAst, NormalizationAstNode, NormalizationLinkedField, NormalizationScalarField, IsographEntrypoint, assertIsEntrypoint,
|
8
|
+
export { EagerReaderArtifact, ComponentReaderArtifact, MutationReaderArtifact, RefetchReaderArtifact, ReaderAst, ReaderAstNode, ReaderLinkedField, ReaderMutationField, ReaderRefetchField, ReaderResolverField, ReaderResolverVariant, ReaderScalarField, } from './reader';
|
9
|
+
export { NormalizationAst, NormalizationAstNode, NormalizationLinkedField, NormalizationScalarField, IsographEntrypoint, assertIsEntrypoint, RefetchQueryNormalizationArtifact, RefetchQueryNormalizationArtifactWrapper, } from './entrypoint';
|
10
10
|
export { readButDoNotEvaluate } from './read';
|
11
11
|
export { useResult } from './useResult';
|
12
12
|
export { type FragmentReference } from './FragmentReference';
|
package/dist/read.d.ts
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
import { FragmentReference } from './FragmentReference';
|
2
2
|
import { DataId, IsographEnvironment } from './IsographEnvironment';
|
3
3
|
export type WithEncounteredRecords<T> = {
|
4
|
-
encounteredRecords: Set<DataId>;
|
5
|
-
item: T;
|
4
|
+
readonly encounteredRecords: Set<DataId>;
|
5
|
+
readonly item: T;
|
6
6
|
};
|
7
7
|
export declare function readButDoNotEvaluate<TReadFromStore extends Object>(environment: IsographEnvironment, reference: FragmentReference<TReadFromStore, unknown>): WithEncounteredRecords<TReadFromStore>;
|
package/dist/read.js
CHANGED
@@ -176,17 +176,15 @@ function readData(environment, ast, root, variables, nestedRefetchQueries, mutab
|
|
176
176
|
const refetchQuery = nestedRefetchQueries[refetchQueryIndex];
|
177
177
|
const refetchQueryArtifact = refetchQuery.artifact;
|
178
178
|
const allowedVariables = refetchQuery.allowedVariables;
|
179
|
-
target[field.alias] = field.readerArtifact.resolver(environment, refetchQueryArtifact,
|
180
|
-
// @ts-expect-error
|
181
|
-
data.data, filterVariables(variables, allowedVariables));
|
179
|
+
target[field.alias] = field.readerArtifact.resolver(environment, refetchQueryArtifact, data.data, filterVariables(variables, allowedVariables));
|
182
180
|
}
|
183
181
|
break;
|
184
182
|
}
|
185
183
|
case 'Resolver': {
|
186
184
|
const usedRefetchQueries = field.usedRefetchQueries;
|
187
185
|
const resolverRefetchQueries = usedRefetchQueries.map((index) => nestedRefetchQueries[index]);
|
188
|
-
const
|
189
|
-
if (
|
186
|
+
const kind = field.readerArtifact.kind;
|
187
|
+
if (kind === 'EagerReaderArtifact') {
|
190
188
|
const data = readData(environment, field.readerArtifact.readerAst, root, variables, resolverRefetchQueries, mutableEncounteredRecords);
|
191
189
|
if (data.kind === 'MissingData') {
|
192
190
|
return {
|
@@ -196,12 +194,11 @@ function readData(environment, ast, root, variables, nestedRefetchQueries, mutab
|
|
196
194
|
};
|
197
195
|
}
|
198
196
|
else {
|
199
|
-
// @ts-expect-error
|
200
197
|
target[field.alias] = field.readerArtifact.resolver(data.data);
|
201
198
|
}
|
202
199
|
}
|
203
|
-
else if (
|
204
|
-
target[field.alias] = (0, componentCache_1.getOrCreateCachedComponent)(environment,
|
200
|
+
else if (kind === 'ComponentReaderArtifact') {
|
201
|
+
target[field.alias] = (0, componentCache_1.getOrCreateCachedComponent)(environment, field.readerArtifact.componentName, {
|
205
202
|
kind: 'FragmentReference',
|
206
203
|
readerArtifact: field.readerArtifact,
|
207
204
|
root,
|
package/dist/reader.d.ts
CHANGED
@@ -1,49 +1,66 @@
|
|
1
|
-
|
1
|
+
/// <reference types="react" />
|
2
|
+
import { ComponentOrFieldName, IsographEnvironment } from './IsographEnvironment';
|
3
|
+
import { RefetchQueryNormalizationArtifact } from './entrypoint';
|
2
4
|
import { Arguments } from './util';
|
3
|
-
export type
|
4
|
-
|
5
|
-
|
6
|
-
readerAst: ReaderAst<TReadFromStore>;
|
7
|
-
resolver: (data: TReadFromStore
|
8
|
-
|
5
|
+
export type TopLevelReaderArtifact<TReadFromStore extends Object, TClientFieldValue, TAdditionalProps extends Record<string, never>> = EagerReaderArtifact<TReadFromStore, TClientFieldValue> | ComponentReaderArtifact<TReadFromStore, TAdditionalProps>;
|
6
|
+
export type EagerReaderArtifact<TReadFromStore extends Object, TClientFieldValue> = {
|
7
|
+
readonly kind: 'EagerReaderArtifact';
|
8
|
+
readonly readerAst: ReaderAst<TReadFromStore>;
|
9
|
+
readonly resolver: (data: TReadFromStore) => TClientFieldValue;
|
10
|
+
};
|
11
|
+
export type ComponentReaderArtifact<TReadFromStore extends Object, TAdditionalProps extends Record<string, unknown> = Record<string, never>> = {
|
12
|
+
readonly kind: 'ComponentReaderArtifact';
|
13
|
+
readonly componentName: ComponentOrFieldName;
|
14
|
+
readonly readerAst: ReaderAst<TReadFromStore>;
|
15
|
+
readonly resolver: (data: TReadFromStore, runtimeProps: TAdditionalProps) => React.ReactNode;
|
16
|
+
};
|
17
|
+
export type RefetchReaderArtifact = {
|
18
|
+
readonly kind: 'RefetchReaderArtifact';
|
19
|
+
readonly readerAst: ReaderAst<unknown>;
|
20
|
+
readonly resolver: (environment: IsographEnvironment, artifact: RefetchQueryNormalizationArtifact, variables: any) => () => void;
|
21
|
+
};
|
22
|
+
export type MutationReaderArtifact<TReadFromStore extends Object> = {
|
23
|
+
readonly kind: 'MutationReaderArtifact';
|
24
|
+
readonly readerAst: ReaderAst<unknown>;
|
25
|
+
readonly resolver: (environment: IsographEnvironment, entrypoint: RefetchQueryNormalizationArtifact, readOutData: TReadFromStore, filteredVariables: any) => (mutationParams: any) => void;
|
9
26
|
};
|
10
27
|
export type ReaderAstNode = ReaderScalarField | ReaderLinkedField | ReaderResolverField | ReaderRefetchField | ReaderMutationField;
|
11
|
-
export type ReaderAst<TReadFromStore> = ReaderAstNode
|
28
|
+
export type ReaderAst<TReadFromStore> = ReadonlyArray<ReaderAstNode>;
|
12
29
|
export type ReaderScalarField = {
|
13
|
-
kind: 'Scalar';
|
14
|
-
fieldName: string;
|
15
|
-
alias: string | null;
|
16
|
-
arguments: Arguments | null;
|
30
|
+
readonly kind: 'Scalar';
|
31
|
+
readonly fieldName: string;
|
32
|
+
readonly alias: string | null;
|
33
|
+
readonly arguments: Arguments | null;
|
17
34
|
};
|
18
35
|
export type ReaderLinkedField = {
|
19
|
-
kind: 'Linked';
|
20
|
-
fieldName: string;
|
21
|
-
alias: string | null;
|
22
|
-
selections: ReaderAst<unknown>;
|
23
|
-
arguments: Arguments | null;
|
36
|
+
readonly kind: 'Linked';
|
37
|
+
readonly fieldName: string;
|
38
|
+
readonly alias: string | null;
|
39
|
+
readonly selections: ReaderAst<unknown>;
|
40
|
+
readonly arguments: Arguments | null;
|
24
41
|
};
|
25
42
|
export type ReaderResolverVariant = {
|
26
|
-
kind: 'Eager';
|
43
|
+
readonly kind: 'Eager';
|
27
44
|
} | {
|
28
|
-
kind: 'Component';
|
29
|
-
componentName: string;
|
45
|
+
readonly kind: 'Component';
|
46
|
+
readonly componentName: string;
|
30
47
|
};
|
31
48
|
export type ReaderResolverField = {
|
32
|
-
kind: 'Resolver';
|
33
|
-
alias: string;
|
34
|
-
readerArtifact:
|
35
|
-
arguments: Arguments | null;
|
36
|
-
usedRefetchQueries: number[];
|
49
|
+
readonly kind: 'Resolver';
|
50
|
+
readonly alias: string;
|
51
|
+
readonly readerArtifact: TopLevelReaderArtifact<any, any, any>;
|
52
|
+
readonly arguments: Arguments | null;
|
53
|
+
readonly usedRefetchQueries: number[];
|
37
54
|
};
|
38
55
|
export type ReaderRefetchField = {
|
39
|
-
kind: 'RefetchField';
|
40
|
-
alias: string;
|
41
|
-
readerArtifact:
|
42
|
-
refetchQuery: number;
|
56
|
+
readonly kind: 'RefetchField';
|
57
|
+
readonly alias: string;
|
58
|
+
readonly readerArtifact: RefetchReaderArtifact;
|
59
|
+
readonly refetchQuery: number;
|
43
60
|
};
|
44
61
|
export type ReaderMutationField = {
|
45
|
-
kind: 'MutationField';
|
46
|
-
alias: string;
|
47
|
-
readerArtifact:
|
48
|
-
refetchQuery: number;
|
62
|
+
readonly kind: 'MutationField';
|
63
|
+
readonly alias: string;
|
64
|
+
readonly readerArtifact: MutationReaderArtifact<any>;
|
65
|
+
readonly refetchQuery: number;
|
49
66
|
};
|
package/dist/useResult.js
CHANGED
@@ -6,14 +6,13 @@ const componentCache_1 = require("./componentCache");
|
|
6
6
|
const useReadAndSubscribe_1 = require("./useReadAndSubscribe");
|
7
7
|
function useResult(fragmentReference) {
|
8
8
|
const environment = (0, IsographEnvironmentProvider_1.useIsographEnvironment)();
|
9
|
-
switch (fragmentReference.readerArtifact.
|
10
|
-
case '
|
9
|
+
switch (fragmentReference.readerArtifact.kind) {
|
10
|
+
case 'ComponentReaderArtifact': {
|
11
11
|
// @ts-expect-error
|
12
|
-
return (0, componentCache_1.getOrCreateCachedComponent)(environment, fragmentReference.readerArtifact.
|
12
|
+
return (0, componentCache_1.getOrCreateCachedComponent)(environment, fragmentReference.readerArtifact.componentName, fragmentReference);
|
13
13
|
}
|
14
|
-
case '
|
14
|
+
case 'EagerReaderArtifact': {
|
15
15
|
const data = (0, useReadAndSubscribe_1.useReadAndSubscribe)(environment, fragmentReference);
|
16
|
-
// @ts-expect-error resolver is incorrectly typed in ReaderArtifact
|
17
16
|
return fragmentReference.readerArtifact.resolver(data);
|
18
17
|
}
|
19
18
|
}
|
package/dist/util.d.ts
CHANGED
@@ -3,9 +3,9 @@ export type Arguments = Argument[];
|
|
3
3
|
export type Argument = [ArgumentName, ArgumentValue];
|
4
4
|
export type ArgumentName = string;
|
5
5
|
export type ArgumentValue = {
|
6
|
-
kind: 'Variable';
|
7
|
-
name: string;
|
6
|
+
readonly kind: 'Variable';
|
7
|
+
readonly name: string;
|
8
8
|
} | {
|
9
|
-
kind: 'Literal';
|
10
|
-
value: any;
|
9
|
+
readonly kind: 'Literal';
|
10
|
+
readonly value: any;
|
11
11
|
};
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@isograph/react",
|
3
|
-
"version": "0.0.0-main-
|
3
|
+
"version": "0.0.0-main-084bfeee",
|
4
4
|
"description": "Use Isograph with React",
|
5
5
|
"homepage": "https://isograph.dev",
|
6
6
|
"main": "dist/index.js",
|
@@ -16,8 +16,8 @@
|
|
16
16
|
"prepack": "yarn run test && yarn run compile"
|
17
17
|
},
|
18
18
|
"dependencies": {
|
19
|
-
"@isograph/disposable-types": "0.0.0-main-
|
20
|
-
"@isograph/react-disposable-state": "0.0.0-main-
|
19
|
+
"@isograph/disposable-types": "0.0.0-main-084bfeee",
|
20
|
+
"@isograph/react-disposable-state": "0.0.0-main-084bfeee",
|
21
21
|
"react": "^18.2.0"
|
22
22
|
},
|
23
23
|
"devDependencies": {
|
@@ -30,5 +30,6 @@
|
|
30
30
|
"type": "git",
|
31
31
|
"url": "git+https://github.com/isographlabs/isograph.git",
|
32
32
|
"directory": "libs/isograph-react"
|
33
|
-
}
|
33
|
+
},
|
34
|
+
"sideEffects": false
|
34
35
|
}
|
package/src/FragmentReference.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import { DataId } from './IsographEnvironment';
|
2
|
-
import {
|
3
|
-
import {
|
2
|
+
import { RefetchQueryNormalizationArtifactWrapper } from './entrypoint';
|
3
|
+
import { TopLevelReaderArtifact } from './reader';
|
4
4
|
|
5
5
|
// TODO type this better
|
6
6
|
export type Variable = any;
|
@@ -11,10 +11,14 @@ export type FragmentReference<
|
|
11
11
|
TReadFromStore extends Object,
|
12
12
|
TClientFieldValue,
|
13
13
|
> = {
|
14
|
-
kind: 'FragmentReference';
|
15
|
-
readerArtifact:
|
16
|
-
|
17
|
-
|
14
|
+
readonly kind: 'FragmentReference';
|
15
|
+
readonly readerArtifact: TopLevelReaderArtifact<
|
16
|
+
TReadFromStore,
|
17
|
+
TClientFieldValue,
|
18
|
+
any
|
19
|
+
>;
|
20
|
+
readonly root: DataId;
|
21
|
+
readonly variables: Variables | null;
|
18
22
|
// TODO: We should instead have ReaderAst<TClientFieldProps>
|
19
|
-
nestedRefetchQueries:
|
23
|
+
readonly nestedRefetchQueries: RefetchQueryNormalizationArtifactWrapper[];
|
20
24
|
};
|
@@ -30,15 +30,15 @@ type Subscriptions = Set<Subscription>;
|
|
30
30
|
type SuspenseCache = { [index: string]: ParentCache<any> };
|
31
31
|
|
32
32
|
export type IsographEnvironment = {
|
33
|
-
store: IsographStore;
|
34
|
-
networkFunction: IsographNetworkFunction;
|
35
|
-
missingFieldHandler: MissingFieldHandler | null;
|
36
|
-
componentCache: ComponentCache;
|
37
|
-
subscriptions: Subscriptions;
|
38
|
-
suspenseCache: SuspenseCache;
|
39
|
-
retainedQueries: Set<RetainedQuery>;
|
40
|
-
gcBuffer: Array<RetainedQuery>;
|
41
|
-
gcBufferSize: number;
|
33
|
+
readonly store: IsographStore;
|
34
|
+
readonly networkFunction: IsographNetworkFunction;
|
35
|
+
readonly missingFieldHandler: MissingFieldHandler | null;
|
36
|
+
readonly componentCache: ComponentCache;
|
37
|
+
readonly subscriptions: Subscriptions;
|
38
|
+
readonly suspenseCache: SuspenseCache;
|
39
|
+
readonly retainedQueries: Set<RetainedQuery>;
|
40
|
+
readonly gcBuffer: Array<RetainedQuery>;
|
41
|
+
readonly gcBufferSize: number;
|
42
42
|
};
|
43
43
|
|
44
44
|
export type MissingFieldHandler = (
|
@@ -55,7 +55,7 @@ export type IsographNetworkFunction = (
|
|
55
55
|
) => Promise<any>;
|
56
56
|
|
57
57
|
export type Link = {
|
58
|
-
__link: DataId;
|
58
|
+
readonly __link: DataId;
|
59
59
|
};
|
60
60
|
|
61
61
|
export type DataTypeValue =
|
@@ -76,7 +76,7 @@ export type StoreRecord = {
|
|
76
76
|
[index: DataId | string]: DataTypeValue;
|
77
77
|
// TODO __typename?: T, which is restricted to being a concrete string
|
78
78
|
// TODO this shouldn't always be named id
|
79
|
-
id?: DataId;
|
79
|
+
readonly id?: DataId;
|
80
80
|
};
|
81
81
|
|
82
82
|
export type DataId = string;
|
@@ -85,7 +85,7 @@ export const ROOT_ID: DataId & '__ROOT' = '__ROOT';
|
|
85
85
|
|
86
86
|
export type IsographStore = {
|
87
87
|
[index: DataId]: StoreRecord | null;
|
88
|
-
__ROOT: StoreRecord;
|
88
|
+
readonly __ROOT: StoreRecord;
|
89
89
|
};
|
90
90
|
|
91
91
|
const DEFAULT_GC_BUFFER_SIZE = 10;
|
@@ -6,8 +6,8 @@ export const IsographEnvironmentContext =
|
|
6
6
|
createContext<IsographEnvironment | null>(null);
|
7
7
|
|
8
8
|
export type IsographEnvironmentProviderProps = {
|
9
|
-
environment: IsographEnvironment;
|
10
|
-
children: ReactNode;
|
9
|
+
readonly environment: IsographEnvironment;
|
10
|
+
readonly children: ReactNode;
|
11
11
|
};
|
12
12
|
|
13
13
|
export function IsographEnvironmentProvider({
|
package/src/PromiseWrapper.ts
CHANGED
package/src/cache.ts
CHANGED
@@ -24,7 +24,8 @@ import {
|
|
24
24
|
NormalizationAst,
|
25
25
|
NormalizationLinkedField,
|
26
26
|
NormalizationScalarField,
|
27
|
-
|
27
|
+
RefetchQueryNormalizationArtifact,
|
28
|
+
RefetchQueryNormalizationArtifactWrapper,
|
28
29
|
} from './entrypoint';
|
29
30
|
import { ReaderLinkedField, ReaderScalarField } from './reader';
|
30
31
|
import { Argument, ArgumentValue } from './util';
|
@@ -79,8 +80,6 @@ export function stableCopy<T>(value: T): T {
|
|
79
80
|
return stable as any;
|
80
81
|
}
|
81
82
|
|
82
|
-
type IsoResolver = IsographEntrypoint<any, any>;
|
83
|
-
|
84
83
|
export function getOrCreateCacheForArtifact<
|
85
84
|
TReadFromStore extends Object,
|
86
85
|
TClientFieldValue,
|
@@ -101,19 +100,19 @@ export function getOrCreateCacheForArtifact<
|
|
101
100
|
|
102
101
|
type NetworkRequestStatus =
|
103
102
|
| {
|
104
|
-
kind: 'UndisposedIncomplete';
|
103
|
+
readonly kind: 'UndisposedIncomplete';
|
105
104
|
}
|
106
105
|
| {
|
107
|
-
kind: 'Disposed';
|
106
|
+
readonly kind: 'Disposed';
|
108
107
|
}
|
109
108
|
| {
|
110
|
-
kind: 'UndisposedComplete';
|
111
|
-
retainedQuery: RetainedQuery;
|
109
|
+
readonly kind: 'UndisposedComplete';
|
110
|
+
readonly retainedQuery: RetainedQuery;
|
112
111
|
};
|
113
112
|
|
114
113
|
export function makeNetworkRequest<T>(
|
115
114
|
environment: IsographEnvironment,
|
116
|
-
artifact:
|
115
|
+
artifact: RefetchQueryNormalizationArtifact | IsographEntrypoint<any, any>,
|
117
116
|
variables: object,
|
118
117
|
): ItemCleanupPair<PromiseWrapper<T>> {
|
119
118
|
if (typeof window !== 'undefined' && window.__LOG) {
|
@@ -136,7 +135,7 @@ export function makeNetworkRequest<T>(
|
|
136
135
|
artifact.normalizationAst,
|
137
136
|
networkResponse.data,
|
138
137
|
variables,
|
139
|
-
artifact.nestedRefetchQueries,
|
138
|
+
artifact.kind === 'Entrypoint' ? artifact.nestedRefetchQueries : [],
|
140
139
|
);
|
141
140
|
const retainedQuery = {
|
142
141
|
normalizationAst: artifact.normalizationAst,
|
@@ -193,7 +192,7 @@ function normalizeData(
|
|
193
192
|
normalizationAst: NormalizationAst,
|
194
193
|
networkResponse: NetworkResponseObject,
|
195
194
|
variables: Object,
|
196
|
-
nestedRefetchQueries:
|
195
|
+
nestedRefetchQueries: RefetchQueryNormalizationArtifactWrapper[],
|
197
196
|
): Set<DataId> {
|
198
197
|
const encounteredIds = new Set<DataId>();
|
199
198
|
|
@@ -344,7 +343,7 @@ function normalizeDataIntoRecord(
|
|
344
343
|
targetParentRecord: StoreRecord,
|
345
344
|
targetParentRecordId: DataId,
|
346
345
|
variables: { [index: string]: string },
|
347
|
-
nestedRefetchQueries:
|
346
|
+
nestedRefetchQueries: RefetchQueryNormalizationArtifactWrapper[],
|
348
347
|
mutableEncounteredIds: Set<DataId>,
|
349
348
|
) {
|
350
349
|
let recordHasBeenUpdated = false;
|
@@ -416,7 +415,7 @@ function normalizeLinkedField(
|
|
416
415
|
targetParentRecord: StoreRecord,
|
417
416
|
targetParentRecordId: DataId,
|
418
417
|
variables: { [index: string]: string },
|
419
|
-
nestedRefetchQueries:
|
418
|
+
nestedRefetchQueries: RefetchQueryNormalizationArtifactWrapper[],
|
420
419
|
mutableEncounteredIds: Set<DataId>,
|
421
420
|
): RecordHasBeenUpdated {
|
422
421
|
const networkResponseKey = getNetworkResponseKey(astNode);
|
@@ -504,7 +503,7 @@ function normalizeNetworkResponseObject(
|
|
504
503
|
targetParentRecordId: string,
|
505
504
|
variables: { [index: string]: string },
|
506
505
|
index: number | null,
|
507
|
-
nestedRefetchQueries:
|
506
|
+
nestedRefetchQueries: RefetchQueryNormalizationArtifactWrapper[],
|
508
507
|
mutableEncounteredIds: Set<DataId>,
|
509
508
|
): DataId /* The id of the modified or newly created item */ {
|
510
509
|
const newStoreRecordId = getDataIdOfNetworkResponse(
|
package/src/entrypoint.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import {
|
1
|
+
import { TopLevelReaderArtifact } from './reader';
|
2
2
|
import { Arguments } from './util';
|
3
3
|
|
4
4
|
// This type should be treated as an opaque type.
|
@@ -6,42 +6,47 @@ export type IsographEntrypoint<
|
|
6
6
|
TReadFromStore extends Object,
|
7
7
|
TClientFieldValue,
|
8
8
|
> = {
|
9
|
-
kind: 'Entrypoint';
|
10
|
-
queryText: string;
|
11
|
-
normalizationAst: NormalizationAst;
|
12
|
-
readerArtifact:
|
13
|
-
|
9
|
+
readonly kind: 'Entrypoint';
|
10
|
+
readonly queryText: string;
|
11
|
+
readonly normalizationAst: NormalizationAst;
|
12
|
+
readonly readerArtifact: TopLevelReaderArtifact<
|
13
|
+
TReadFromStore,
|
14
|
+
TClientFieldValue,
|
15
|
+
// TODO don't type this as any
|
16
|
+
any
|
17
|
+
>;
|
18
|
+
readonly nestedRefetchQueries: RefetchQueryNormalizationArtifactWrapper[];
|
14
19
|
};
|
15
20
|
|
16
21
|
export type NormalizationAstNode =
|
17
22
|
| NormalizationScalarField
|
18
23
|
| NormalizationLinkedField;
|
19
|
-
export type NormalizationAst = NormalizationAstNode
|
24
|
+
export type NormalizationAst = ReadonlyArray<NormalizationAstNode>;
|
20
25
|
|
21
26
|
export type NormalizationScalarField = {
|
22
|
-
kind: 'Scalar';
|
23
|
-
fieldName: string;
|
24
|
-
arguments: Arguments | null;
|
27
|
+
readonly kind: 'Scalar';
|
28
|
+
readonly fieldName: string;
|
29
|
+
readonly arguments: Arguments | null;
|
25
30
|
};
|
26
31
|
|
27
32
|
export type NormalizationLinkedField = {
|
28
|
-
kind: 'Linked';
|
29
|
-
fieldName: string;
|
30
|
-
arguments: Arguments | null;
|
31
|
-
selections: NormalizationAst;
|
33
|
+
readonly kind: 'Linked';
|
34
|
+
readonly fieldName: string;
|
35
|
+
readonly arguments: Arguments | null;
|
36
|
+
readonly selections: NormalizationAst;
|
32
37
|
};
|
33
38
|
|
34
39
|
// This is more like an entrypoint, but one specifically for a refetch query/mutation
|
35
|
-
export type
|
36
|
-
kind: 'RefetchQuery';
|
37
|
-
queryText: string;
|
38
|
-
normalizationAst: NormalizationAst;
|
40
|
+
export type RefetchQueryNormalizationArtifact = {
|
41
|
+
readonly kind: 'RefetchQuery';
|
42
|
+
readonly queryText: string;
|
43
|
+
readonly normalizationAst: NormalizationAst;
|
39
44
|
};
|
40
45
|
|
41
46
|
// TODO rename
|
42
|
-
export type
|
43
|
-
artifact:
|
44
|
-
allowedVariables: string[];
|
47
|
+
export type RefetchQueryNormalizationArtifactWrapper = {
|
48
|
+
readonly artifact: RefetchQueryNormalizationArtifact;
|
49
|
+
readonly allowedVariables: string[];
|
45
50
|
};
|
46
51
|
|
47
52
|
export function assertIsEntrypoint<
|
package/src/garbageCollection.ts
CHANGED
@@ -10,8 +10,8 @@ import { getParentRecordKey } from './cache';
|
|
10
10
|
import { NormalizationAst } from './entrypoint';
|
11
11
|
|
12
12
|
export type RetainedQuery = {
|
13
|
-
normalizationAst: NormalizationAst;
|
14
|
-
variables: {};
|
13
|
+
readonly normalizationAst: NormalizationAst;
|
14
|
+
readonly variables: {};
|
15
15
|
};
|
16
16
|
|
17
17
|
type DidUnretainSomeQuery = boolean;
|
package/src/index.ts
CHANGED
@@ -27,7 +27,10 @@ export {
|
|
27
27
|
export { useImperativeReference } from './useImperativeReference';
|
28
28
|
export { EntrypointReader } from './EntrypointReader';
|
29
29
|
export {
|
30
|
-
|
30
|
+
EagerReaderArtifact,
|
31
|
+
ComponentReaderArtifact,
|
32
|
+
MutationReaderArtifact,
|
33
|
+
RefetchReaderArtifact,
|
31
34
|
ReaderAst,
|
32
35
|
ReaderAstNode,
|
33
36
|
ReaderLinkedField,
|
@@ -44,8 +47,8 @@ export {
|
|
44
47
|
NormalizationScalarField,
|
45
48
|
IsographEntrypoint,
|
46
49
|
assertIsEntrypoint,
|
47
|
-
|
48
|
-
|
50
|
+
RefetchQueryNormalizationArtifact,
|
51
|
+
RefetchQueryNormalizationArtifactWrapper,
|
49
52
|
} from './entrypoint';
|
50
53
|
export { readButDoNotEvaluate } from './read';
|
51
54
|
export { useResult } from './useResult';
|
package/src/read.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import { getParentRecordKey, onNextChange } from './cache';
|
2
2
|
import { getOrCreateCachedComponent } from './componentCache';
|
3
|
-
import {
|
3
|
+
import { RefetchQueryNormalizationArtifactWrapper } from './entrypoint';
|
4
4
|
import { FragmentReference } from './FragmentReference';
|
5
5
|
import {
|
6
6
|
assertLink,
|
@@ -11,8 +11,8 @@ import {
|
|
11
11
|
import { ReaderAst } from './reader';
|
12
12
|
|
13
13
|
export type WithEncounteredRecords<T> = {
|
14
|
-
encounteredRecords: Set<DataId>;
|
15
|
-
item: T;
|
14
|
+
readonly encounteredRecords: Set<DataId>;
|
15
|
+
readonly item: T;
|
16
16
|
};
|
17
17
|
|
18
18
|
export function readButDoNotEvaluate<TReadFromStore extends Object>(
|
@@ -43,14 +43,14 @@ export function readButDoNotEvaluate<TReadFromStore extends Object>(
|
|
43
43
|
|
44
44
|
type ReadDataResult<TReadFromStore> =
|
45
45
|
| {
|
46
|
-
kind: 'Success';
|
47
|
-
data: TReadFromStore;
|
48
|
-
encounteredRecords: Set<DataId>;
|
46
|
+
readonly kind: 'Success';
|
47
|
+
readonly data: TReadFromStore;
|
48
|
+
readonly encounteredRecords: Set<DataId>;
|
49
49
|
}
|
50
50
|
| {
|
51
|
-
kind: 'MissingData';
|
52
|
-
reason: string;
|
53
|
-
nestedReason?: ReadDataResult<unknown>;
|
51
|
+
readonly kind: 'MissingData';
|
52
|
+
readonly reason: string;
|
53
|
+
readonly nestedReason?: ReadDataResult<unknown>;
|
54
54
|
};
|
55
55
|
|
56
56
|
function readData<TReadFromStore>(
|
@@ -58,7 +58,7 @@ function readData<TReadFromStore>(
|
|
58
58
|
ast: ReaderAst<TReadFromStore>,
|
59
59
|
root: DataId,
|
60
60
|
variables: { [index: string]: string },
|
61
|
-
nestedRefetchQueries:
|
61
|
+
nestedRefetchQueries: RefetchQueryNormalizationArtifactWrapper[],
|
62
62
|
mutableEncounteredRecords: Set<DataId>,
|
63
63
|
): ReadDataResult<TReadFromStore> {
|
64
64
|
mutableEncounteredRecords.add(root);
|
@@ -222,11 +222,9 @@ function readData<TReadFromStore>(
|
|
222
222
|
environment,
|
223
223
|
// resolvers for refetch fields take 3 args, and this is not reflected in types
|
224
224
|
refetchQueryArtifact,
|
225
|
-
// @ts-expect-error
|
226
225
|
{
|
226
|
+
// @ts-expect-error
|
227
227
|
...data.data,
|
228
|
-
// TODO continue from here
|
229
|
-
// variables need to be filtered for what we need just for the refetch query
|
230
228
|
...filterVariables(variables, allowedVariables),
|
231
229
|
},
|
232
230
|
);
|
@@ -261,7 +259,6 @@ function readData<TReadFromStore>(
|
|
261
259
|
target[field.alias] = field.readerArtifact.resolver(
|
262
260
|
environment,
|
263
261
|
refetchQueryArtifact,
|
264
|
-
// @ts-expect-error
|
265
262
|
data.data,
|
266
263
|
filterVariables(variables, allowedVariables),
|
267
264
|
);
|
@@ -274,8 +271,8 @@ function readData<TReadFromStore>(
|
|
274
271
|
(index) => nestedRefetchQueries[index],
|
275
272
|
);
|
276
273
|
|
277
|
-
const
|
278
|
-
if (
|
274
|
+
const kind = field.readerArtifact.kind;
|
275
|
+
if (kind === 'EagerReaderArtifact') {
|
279
276
|
const data = readData(
|
280
277
|
environment,
|
281
278
|
field.readerArtifact.readerAst,
|
@@ -291,13 +288,12 @@ function readData<TReadFromStore>(
|
|
291
288
|
nestedReason: data,
|
292
289
|
};
|
293
290
|
} else {
|
294
|
-
// @ts-expect-error
|
295
291
|
target[field.alias] = field.readerArtifact.resolver(data.data);
|
296
292
|
}
|
297
|
-
} else if (
|
293
|
+
} else if (kind === 'ComponentReaderArtifact') {
|
298
294
|
target[field.alias] = getOrCreateCachedComponent(
|
299
295
|
environment,
|
300
|
-
|
296
|
+
field.readerArtifact.componentName,
|
301
297
|
{
|
302
298
|
kind: 'FragmentReference',
|
303
299
|
readerArtifact: field.readerArtifact,
|
package/src/reader.ts
CHANGED
@@ -1,15 +1,63 @@
|
|
1
|
-
import {
|
1
|
+
import {
|
2
|
+
ComponentOrFieldName,
|
3
|
+
IsographEnvironment,
|
4
|
+
} from './IsographEnvironment';
|
5
|
+
import { RefetchQueryNormalizationArtifact } from './entrypoint';
|
2
6
|
import { Arguments } from './util';
|
3
7
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
8
|
+
export type TopLevelReaderArtifact<
|
9
|
+
TReadFromStore extends Object,
|
10
|
+
TClientFieldValue,
|
11
|
+
TAdditionalProps extends Record<string, never>,
|
12
|
+
> =
|
13
|
+
| EagerReaderArtifact<TReadFromStore, TClientFieldValue>
|
14
|
+
| ComponentReaderArtifact<TReadFromStore, TAdditionalProps>;
|
15
|
+
|
16
|
+
export type EagerReaderArtifact<
|
17
|
+
TReadFromStore extends Object,
|
18
|
+
TClientFieldValue,
|
19
|
+
> = {
|
20
|
+
readonly kind: 'EagerReaderArtifact';
|
21
|
+
readonly readerAst: ReaderAst<TReadFromStore>;
|
22
|
+
readonly resolver: (data: TReadFromStore) => TClientFieldValue;
|
23
|
+
};
|
24
|
+
|
25
|
+
export type ComponentReaderArtifact<
|
26
|
+
TReadFromStore extends Object,
|
27
|
+
TAdditionalProps extends Record<string, unknown> = Record<string, never>,
|
28
|
+
> = {
|
29
|
+
readonly kind: 'ComponentReaderArtifact';
|
30
|
+
readonly componentName: ComponentOrFieldName;
|
31
|
+
readonly readerAst: ReaderAst<TReadFromStore>;
|
32
|
+
readonly resolver: (
|
33
|
+
data: TReadFromStore,
|
34
|
+
runtimeProps: TAdditionalProps,
|
35
|
+
) => React.ReactNode;
|
36
|
+
};
|
37
|
+
|
38
|
+
export type RefetchReaderArtifact = {
|
39
|
+
readonly kind: 'RefetchReaderArtifact';
|
40
|
+
readonly readerAst: ReaderAst<unknown>;
|
41
|
+
readonly resolver: (
|
42
|
+
environment: IsographEnvironment,
|
43
|
+
artifact: RefetchQueryNormalizationArtifact,
|
44
|
+
// TODO type this better
|
45
|
+
variables: any,
|
46
|
+
) => () => void;
|
47
|
+
};
|
48
|
+
|
49
|
+
export type MutationReaderArtifact<TReadFromStore extends Object> = {
|
50
|
+
readonly kind: 'MutationReaderArtifact';
|
51
|
+
readonly readerAst: ReaderAst<unknown>;
|
52
|
+
readonly resolver: (
|
53
|
+
environment: IsographEnvironment,
|
54
|
+
// TODO type this better
|
55
|
+
entrypoint: RefetchQueryNormalizationArtifact,
|
56
|
+
readOutData: TReadFromStore,
|
57
|
+
// TODO type this better
|
58
|
+
filteredVariables: any,
|
59
|
+
// TODO type this better
|
60
|
+
) => (mutationParams: any) => void;
|
13
61
|
};
|
14
62
|
|
15
63
|
export type ReaderAstNode =
|
@@ -20,48 +68,47 @@ export type ReaderAstNode =
|
|
20
68
|
| ReaderMutationField;
|
21
69
|
|
22
70
|
// @ts-ignore
|
23
|
-
export type ReaderAst<TReadFromStore> = ReaderAstNode
|
71
|
+
export type ReaderAst<TReadFromStore> = ReadonlyArray<ReaderAstNode>;
|
24
72
|
|
25
73
|
export type ReaderScalarField = {
|
26
|
-
kind: 'Scalar';
|
27
|
-
fieldName: string;
|
28
|
-
alias: string | null;
|
29
|
-
arguments: Arguments | null;
|
74
|
+
readonly kind: 'Scalar';
|
75
|
+
readonly fieldName: string;
|
76
|
+
readonly alias: string | null;
|
77
|
+
readonly arguments: Arguments | null;
|
30
78
|
};
|
31
79
|
export type ReaderLinkedField = {
|
32
|
-
kind: 'Linked';
|
33
|
-
fieldName: string;
|
34
|
-
alias: string | null;
|
35
|
-
selections: ReaderAst<unknown>;
|
36
|
-
arguments: Arguments | null;
|
80
|
+
readonly kind: 'Linked';
|
81
|
+
readonly fieldName: string;
|
82
|
+
readonly alias: string | null;
|
83
|
+
readonly selections: ReaderAst<unknown>;
|
84
|
+
readonly arguments: Arguments | null;
|
37
85
|
};
|
38
86
|
|
39
87
|
export type ReaderResolverVariant =
|
40
|
-
| { kind: 'Eager' }
|
41
|
-
// componentName is
|
42
|
-
|
43
|
-
| { kind: 'Component'; componentName: string };
|
88
|
+
| { readonly kind: 'Eager' }
|
89
|
+
// componentName is type + field concatenated
|
90
|
+
| { readonly kind: 'Component'; readonly componentName: string };
|
44
91
|
|
45
92
|
export type ReaderResolverField = {
|
46
|
-
kind: 'Resolver';
|
47
|
-
alias: string;
|
48
|
-
|
49
|
-
|
50
|
-
|
93
|
+
readonly kind: 'Resolver';
|
94
|
+
readonly alias: string;
|
95
|
+
// TODO don't type this as any
|
96
|
+
readonly readerArtifact: TopLevelReaderArtifact<any, any, any>;
|
97
|
+
readonly arguments: Arguments | null;
|
98
|
+
readonly usedRefetchQueries: number[];
|
51
99
|
};
|
52
100
|
|
53
101
|
export type ReaderRefetchField = {
|
54
|
-
kind: 'RefetchField';
|
55
|
-
alias: string;
|
56
|
-
|
57
|
-
|
58
|
-
refetchQuery: number;
|
102
|
+
readonly kind: 'RefetchField';
|
103
|
+
readonly alias: string;
|
104
|
+
readonly readerArtifact: RefetchReaderArtifact;
|
105
|
+
readonly refetchQuery: number;
|
59
106
|
};
|
60
107
|
|
61
108
|
export type ReaderMutationField = {
|
62
|
-
kind: 'MutationField';
|
63
|
-
alias: string;
|
64
|
-
// TODO
|
65
|
-
readerArtifact:
|
66
|
-
refetchQuery: number;
|
109
|
+
readonly kind: 'MutationField';
|
110
|
+
readonly alias: string;
|
111
|
+
// TODO don't pass any here
|
112
|
+
readonly readerArtifact: MutationReaderArtifact<any>;
|
113
|
+
readonly refetchQuery: number;
|
67
114
|
};
|
@@ -1,8 +1,8 @@
|
|
1
|
-
import type {IsographEntrypoint, NormalizationAst,
|
1
|
+
import type {IsographEntrypoint, NormalizationAst, RefetchQueryNormalizationArtifactWrapper} from '@isograph/react';
|
2
2
|
import {Query__meName__param} from './param_type';
|
3
3
|
import {Query__meName__outputType} from './output_type';
|
4
4
|
import readerResolver from './reader';
|
5
|
-
const nestedRefetchQueries:
|
5
|
+
const nestedRefetchQueries: RefetchQueryNormalizationArtifactWrapper[] = [];
|
6
6
|
|
7
7
|
const queryText = 'query meName {\
|
8
8
|
me {\
|
@@ -1,4 +1,2 @@
|
|
1
|
-
import type {ExtractSecondParam} from '@isograph/react';
|
2
1
|
import { meNameField as resolver } from '../../../garbageCollection.test.ts';
|
3
|
-
|
4
|
-
export type Query__meName__outputType = ReturnType<typeof resolver>;
|
2
|
+
export type Query__meName__outputType = ReturnType<typeof resolver>;
|
@@ -1,6 +1,6 @@
|
|
1
|
-
import type {
|
2
|
-
import { Query__meName__param } from './param_type
|
3
|
-
import { Query__meName__outputType } from './output_type
|
1
|
+
import type {EagerReaderArtifact, ReaderAst, RefetchQueryNormalizationArtifact} from '@isograph/react';
|
2
|
+
import { Query__meName__param } from './param_type';
|
3
|
+
import { Query__meName__outputType } from './output_type';
|
4
4
|
import { meNameField as resolver } from '../../../garbageCollection.test.ts';
|
5
5
|
|
6
6
|
const readerAst: ReaderAst<Query__meName__param> = [
|
@@ -20,15 +20,13 @@ const readerAst: ReaderAst<Query__meName__param> = [
|
|
20
20
|
},
|
21
21
|
];
|
22
22
|
|
23
|
-
const artifact:
|
23
|
+
const artifact: EagerReaderArtifact<
|
24
24
|
Query__meName__param,
|
25
25
|
Query__meName__outputType
|
26
26
|
> = {
|
27
|
-
kind: "
|
28
|
-
|
29
|
-
resolver: resolver as any,
|
27
|
+
kind: "EagerReaderArtifact",
|
28
|
+
resolver,
|
30
29
|
readerAst,
|
31
|
-
variant: { kind: "Eager" },
|
32
30
|
};
|
33
31
|
|
34
32
|
export default artifact;
|
@@ -1,8 +1,8 @@
|
|
1
|
-
import type {IsographEntrypoint, NormalizationAst,
|
1
|
+
import type {IsographEntrypoint, NormalizationAst, RefetchQueryNormalizationArtifactWrapper} from '@isograph/react';
|
2
2
|
import {Query__meNameSuccessor__param} from './param_type';
|
3
3
|
import {Query__meNameSuccessor__outputType} from './output_type';
|
4
4
|
import readerResolver from './reader';
|
5
|
-
const nestedRefetchQueries:
|
5
|
+
const nestedRefetchQueries: RefetchQueryNormalizationArtifactWrapper[] = [];
|
6
6
|
|
7
7
|
const queryText = 'query meNameSuccessor {\
|
8
8
|
me {\
|
@@ -1,4 +1,2 @@
|
|
1
|
-
import type {ExtractSecondParam} from '@isograph/react';
|
2
1
|
import { meNameField as resolver } from '../../../meNameSuccessor.ts';
|
3
|
-
|
4
|
-
export type Query__meNameSuccessor__outputType = ReturnType<typeof resolver>;
|
2
|
+
export type Query__meNameSuccessor__outputType = ReturnType<typeof resolver>;
|
@@ -1,6 +1,6 @@
|
|
1
|
-
import type {
|
2
|
-
import { Query__meNameSuccessor__param } from './param_type
|
3
|
-
import { Query__meNameSuccessor__outputType } from './output_type
|
1
|
+
import type {EagerReaderArtifact, ReaderAst, RefetchQueryNormalizationArtifact} from '@isograph/react';
|
2
|
+
import { Query__meNameSuccessor__param } from './param_type';
|
3
|
+
import { Query__meNameSuccessor__outputType } from './output_type';
|
4
4
|
import { meNameField as resolver } from '../../../meNameSuccessor.ts';
|
5
5
|
|
6
6
|
const readerAst: ReaderAst<Query__meNameSuccessor__param> = [
|
@@ -42,15 +42,13 @@ const readerAst: ReaderAst<Query__meNameSuccessor__param> = [
|
|
42
42
|
},
|
43
43
|
];
|
44
44
|
|
45
|
-
const artifact:
|
45
|
+
const artifact: EagerReaderArtifact<
|
46
46
|
Query__meNameSuccessor__param,
|
47
47
|
Query__meNameSuccessor__outputType
|
48
48
|
> = {
|
49
|
-
kind: "
|
50
|
-
|
51
|
-
resolver: resolver as any,
|
49
|
+
kind: "EagerReaderArtifact",
|
50
|
+
resolver,
|
52
51
|
readerAst,
|
53
|
-
variant: { kind: "Eager" },
|
54
52
|
};
|
55
53
|
|
56
54
|
export default artifact;
|
@@ -1,8 +1,8 @@
|
|
1
|
-
import type {IsographEntrypoint, NormalizationAst,
|
1
|
+
import type {IsographEntrypoint, NormalizationAst, RefetchQueryNormalizationArtifactWrapper} from '@isograph/react';
|
2
2
|
import {Query__nodeField__param} from './param_type';
|
3
3
|
import {Query__nodeField__outputType} from './output_type';
|
4
4
|
import readerResolver from './reader';
|
5
|
-
const nestedRefetchQueries:
|
5
|
+
const nestedRefetchQueries: RefetchQueryNormalizationArtifactWrapper[] = [];
|
6
6
|
|
7
7
|
const queryText = 'query nodeField ($id: ID!) {\
|
8
8
|
node____id___v_id: node(id: $id) {\
|
@@ -1,4 +1,2 @@
|
|
1
|
-
import type {ExtractSecondParam} from '@isograph/react';
|
2
1
|
import { nodeField as resolver } from '../../../nodeQuery.ts';
|
3
|
-
|
4
|
-
export type Query__nodeField__outputType = ReturnType<typeof resolver>;
|
2
|
+
export type Query__nodeField__outputType = ReturnType<typeof resolver>;
|
@@ -1,6 +1,6 @@
|
|
1
|
-
import type {
|
2
|
-
import { Query__nodeField__param } from './param_type
|
3
|
-
import { Query__nodeField__outputType } from './output_type
|
1
|
+
import type {EagerReaderArtifact, ReaderAst, RefetchQueryNormalizationArtifact} from '@isograph/react';
|
2
|
+
import { Query__nodeField__param } from './param_type';
|
3
|
+
import { Query__nodeField__outputType } from './output_type';
|
4
4
|
import { nodeField as resolver } from '../../../nodeQuery.ts';
|
5
5
|
|
6
6
|
const readerAst: ReaderAst<Query__nodeField__param> = [
|
@@ -25,15 +25,13 @@ const readerAst: ReaderAst<Query__nodeField__param> = [
|
|
25
25
|
},
|
26
26
|
];
|
27
27
|
|
28
|
-
const artifact:
|
28
|
+
const artifact: EagerReaderArtifact<
|
29
29
|
Query__nodeField__param,
|
30
30
|
Query__nodeField__outputType
|
31
31
|
> = {
|
32
|
-
kind: "
|
33
|
-
|
34
|
-
resolver: resolver as any,
|
32
|
+
kind: "EagerReaderArtifact",
|
33
|
+
resolver,
|
35
34
|
readerAst,
|
36
|
-
variant: { kind: "Eager" },
|
37
35
|
};
|
38
36
|
|
39
37
|
export default artifact;
|
package/src/useResult.ts
CHANGED
@@ -8,18 +8,17 @@ export function useResult<TReadFromStore extends Object, TClientFieldValue>(
|
|
8
8
|
): TClientFieldValue {
|
9
9
|
const environment = useIsographEnvironment();
|
10
10
|
|
11
|
-
switch (fragmentReference.readerArtifact.
|
12
|
-
case '
|
11
|
+
switch (fragmentReference.readerArtifact.kind) {
|
12
|
+
case 'ComponentReaderArtifact': {
|
13
13
|
// @ts-expect-error
|
14
14
|
return getOrCreateCachedComponent(
|
15
15
|
environment,
|
16
|
-
fragmentReference.readerArtifact.
|
16
|
+
fragmentReference.readerArtifact.componentName,
|
17
17
|
fragmentReference,
|
18
18
|
);
|
19
19
|
}
|
20
|
-
case '
|
20
|
+
case 'EagerReaderArtifact': {
|
21
21
|
const data = useReadAndSubscribe(environment, fragmentReference);
|
22
|
-
// @ts-expect-error resolver is incorrectly typed in ReaderArtifact
|
23
22
|
return fragmentReference.readerArtifact.resolver(data);
|
24
23
|
}
|
25
24
|
}
|
package/src/util.ts
CHANGED
@@ -6,10 +6,10 @@ export type Argument = [ArgumentName, ArgumentValue];
|
|
6
6
|
export type ArgumentName = string;
|
7
7
|
export type ArgumentValue =
|
8
8
|
| {
|
9
|
-
kind: 'Variable';
|
10
|
-
name: string;
|
9
|
+
readonly kind: 'Variable';
|
10
|
+
readonly name: string;
|
11
11
|
}
|
12
12
|
| {
|
13
|
-
kind: 'Literal';
|
14
|
-
value: any;
|
13
|
+
readonly kind: 'Literal';
|
14
|
+
readonly value: any;
|
15
15
|
};
|