houdini 1.0.0-next.2 → 1.0.0-next.3
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/build/cmd-cjs/index.js +1380 -1190
- package/build/cmd-esm/index.js +1380 -1190
- package/build/codegen/generators/typescript/documentTypes.d.ts +2 -0
- package/build/codegen/generators/typescript/{imperativeCache.d.ts → imperativeTypeDef.d.ts} +1 -1
- package/build/codegen/transforms/fragmentVariables.d.ts +1 -0
- package/build/codegen-cjs/index.js +1225 -1037
- package/build/codegen-esm/index.js +1225 -1037
- package/build/lib/config.d.ts +1 -1
- package/build/lib/walk.d.ts +4 -1
- package/build/lib-cjs/index.js +10 -10
- package/build/lib-esm/index.js +10 -10
- package/build/runtime/cache/lists.d.ts +1 -0
- package/build/runtime/generated.d.ts +1 -0
- package/build/runtime/index.d.ts +1 -1
- package/build/runtime/lib/config.d.ts +21 -22
- package/build/runtime/lib/scalars.d.ts +2 -2
- package/build/runtime/public/cache.d.ts +19 -6
- package/build/runtime/public/record.d.ts +17 -17
- package/build/runtime/public/tests/test.d.ts +43 -0
- package/build/runtime/public/types.d.ts +8 -0
- package/build/runtime-cjs/cache/lists.d.ts +1 -0
- package/build/runtime-cjs/cache/lists.js +3 -0
- package/build/runtime-cjs/generated.d.ts +1 -0
- package/build/runtime-cjs/index.d.ts +1 -1
- package/build/runtime-cjs/lib/config.d.ts +21 -22
- package/build/runtime-cjs/lib/scalars.d.ts +2 -2
- package/build/runtime-cjs/public/cache.d.ts +19 -6
- package/build/runtime-cjs/public/cache.js +29 -32
- package/build/runtime-cjs/public/list.js +6 -28
- package/build/runtime-cjs/public/record.d.ts +17 -17
- package/build/runtime-cjs/public/record.js +22 -188
- package/build/runtime-cjs/public/tests/test.d.ts +43 -0
- package/build/runtime-cjs/public/tests/test.js +27 -2
- package/build/runtime-cjs/public/types.d.ts +8 -0
- package/build/runtime-esm/cache/lists.d.ts +1 -0
- package/build/runtime-esm/cache/lists.js +3 -0
- package/build/runtime-esm/generated.d.ts +1 -0
- package/build/runtime-esm/index.d.ts +1 -1
- package/build/runtime-esm/lib/config.d.ts +21 -22
- package/build/runtime-esm/lib/scalars.d.ts +2 -2
- package/build/runtime-esm/public/cache.d.ts +19 -6
- package/build/runtime-esm/public/cache.js +28 -30
- package/build/runtime-esm/public/list.js +6 -28
- package/build/runtime-esm/public/record.d.ts +17 -17
- package/build/runtime-esm/public/record.js +21 -184
- package/build/runtime-esm/public/tests/test.d.ts +43 -0
- package/build/runtime-esm/public/tests/test.js +26 -1
- package/build/runtime-esm/public/types.d.ts +8 -0
- package/build/test-cjs/index.js +1233 -1046
- package/build/test-esm/index.js +1233 -1046
- package/build/vite-cjs/index.js +1234 -1046
- package/build/vite-esm/index.js +1234 -1046
- package/package.json +1 -1
|
@@ -31,10 +31,6 @@ export type ConfigFile = {
|
|
|
31
31
|
* FYI: `schemaPath` or `schema` should be defined
|
|
32
32
|
*/
|
|
33
33
|
schema?: string | GraphQLSchema;
|
|
34
|
-
/**
|
|
35
|
-
* A url to use to pull the schema. For more information: https://www.houdinigraphql.com/api/cli#generate
|
|
36
|
-
*/
|
|
37
|
-
apiUrl?: string | ((env: Record<string, string | undefined>) => string);
|
|
38
34
|
/**
|
|
39
35
|
* An object describing custom scalars for your project. For more information: https://www.houdinigraphql.com/api/config#custom-scalars
|
|
40
36
|
*/
|
|
@@ -43,11 +39,6 @@ export type ConfigFile = {
|
|
|
43
39
|
* A path that the generator will use to write schema.graphql and documents.gql files containing all of the internal fragment and directive definitions used in the project.
|
|
44
40
|
*/
|
|
45
41
|
definitionsPath?: string;
|
|
46
|
-
/**
|
|
47
|
-
* One of "kit" or "svelte". Used to tell the preprocessor what kind of loading paradigm to generate for you. (default: `kit`)
|
|
48
|
-
* @deprecated please follow the steps here: http://www.houdinigraphql.com/guides/release-notes#0170
|
|
49
|
-
*/
|
|
50
|
-
framework?: 'kit' | 'svelte';
|
|
51
42
|
/**
|
|
52
43
|
* One of "esm" or "commonjs". Tells the artifact generator what kind of modules to create. (default: `esm`)
|
|
53
44
|
*/
|
|
@@ -90,20 +81,9 @@ export type ConfigFile = {
|
|
|
90
81
|
*/
|
|
91
82
|
defaultFragmentMasking?: 'enable' | 'disable';
|
|
92
83
|
/**
|
|
93
|
-
*
|
|
94
|
-
* during development in order to keep it's definition of your schema up to date. The schemaPollingInterval
|
|
95
|
-
* config value sets the amount of time between each request in milliseconds (default 2 seconds).
|
|
96
|
-
* To limit the schema introspection to just on the start of the server, set schemaPollingInterval to 0.
|
|
97
|
-
* To disable the schema introspection, set schemaPollingInterval to null.
|
|
98
|
-
*/
|
|
99
|
-
schemaPollInterval?: number | null;
|
|
100
|
-
/**
|
|
101
|
-
* An object containing the environment variables you want passed onto the api when polling for a new schema.
|
|
102
|
-
* The keys dictate the header names. If the value is a string, the corresponding environment variable will be used
|
|
103
|
-
* directly. If the value is a function, the current environment will be passed to your function so you can perform any
|
|
104
|
-
* logic you need
|
|
84
|
+
* Configure the dev environment to watch a remote schema for changes
|
|
105
85
|
*/
|
|
106
|
-
|
|
86
|
+
watchSchema?: WatchSchemaConfig;
|
|
107
87
|
/**
|
|
108
88
|
* An object describing the plugins enabled for the project
|
|
109
89
|
*/
|
|
@@ -133,6 +113,25 @@ export type TypeConfig = {
|
|
|
133
113
|
};
|
|
134
114
|
};
|
|
135
115
|
};
|
|
116
|
+
export type WatchSchemaConfig = {
|
|
117
|
+
/**
|
|
118
|
+
* A url to use to pull the schema. For more information: https://www.houdinigraphql.com/api/cli#generate
|
|
119
|
+
*/
|
|
120
|
+
url: string | ((env: Record<string, string | undefined>) => string);
|
|
121
|
+
/**
|
|
122
|
+
* sets the amount of time between each request in milliseconds (default 2 seconds).
|
|
123
|
+
* To limit the schema introspection to just on the start of the server, set interval to 0.
|
|
124
|
+
* To disable the schema introspection, set interval to null.
|
|
125
|
+
*/
|
|
126
|
+
interval?: number | null;
|
|
127
|
+
/**
|
|
128
|
+
* An object containing the environment variables you want passed onto the api when polling for a new schema.
|
|
129
|
+
* The keys dictate the header names. If the value is a string, the corresponding environment variable will be used
|
|
130
|
+
* directly. If the value is a function, the current environment will be passed to your function so you can perform any
|
|
131
|
+
* logic you need
|
|
132
|
+
*/
|
|
133
|
+
headers?: Record<string, string | ((env: Record<string, string | undefined>) => string)> | ((env: Record<string, string | undefined>) => Record<string, string>);
|
|
134
|
+
};
|
|
136
135
|
export type ScalarSpec = {
|
|
137
136
|
type: string;
|
|
138
137
|
marshal?: (val: any) => any;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { ConfigFile } from './config';
|
|
2
|
-
import type { MutationArtifact, QueryArtifact, SubscriptionArtifact, SubscriptionSelection } from './types';
|
|
2
|
+
import type { FragmentArtifact, MutationArtifact, QueryArtifact, SubscriptionArtifact, SubscriptionSelection } from './types';
|
|
3
3
|
export declare function marshalSelection({ selection, data, }: {
|
|
4
4
|
selection: SubscriptionSelection;
|
|
5
5
|
data: any;
|
|
6
6
|
}): Promise<{} | null | undefined>;
|
|
7
7
|
export declare function marshalInputs<T>({ artifact, input, config, rootType, }: {
|
|
8
|
-
artifact: QueryArtifact | MutationArtifact | SubscriptionArtifact;
|
|
8
|
+
artifact: QueryArtifact | MutationArtifact | SubscriptionArtifact | FragmentArtifact;
|
|
9
9
|
input: unknown;
|
|
10
10
|
rootType?: string;
|
|
11
11
|
config: ConfigFile;
|
|
@@ -1,19 +1,32 @@
|
|
|
1
1
|
import type { Cache as _Cache } from '../cache/cache';
|
|
2
|
-
import
|
|
2
|
+
import { type QueryArtifact } from '../lib';
|
|
3
3
|
import { ListCollection } from './list';
|
|
4
4
|
import { Record } from './record';
|
|
5
|
-
import type { CacheTypeDef, IDFields, TypeNames, ValidLists } from './types';
|
|
5
|
+
import type { CacheTypeDef, IDFields, QueryInput, QueryList, QueryValue, TypeNames, ValidLists } from './types';
|
|
6
6
|
export declare class Cache<Def extends CacheTypeDef> {
|
|
7
7
|
_internal_unstable: _Cache;
|
|
8
8
|
constructor(cache: _Cache);
|
|
9
9
|
validateInstabilityWarning(): void;
|
|
10
|
-
setFieldType(...args: Parameters<SchemaManager['setFieldType']>): void;
|
|
11
|
-
get root(): Record<Def, '__ROOT__'>;
|
|
12
10
|
get<T extends TypeNames<Def>>(type: T, data: IDFields<Def, T>): Record<Def, T>;
|
|
13
|
-
get config(): import("
|
|
11
|
+
get config(): import("../lib").ConfigFile;
|
|
14
12
|
list<Name extends ValidLists<Def>>(name: Name, { parentID, allLists }?: {
|
|
15
13
|
parentID?: string;
|
|
16
14
|
allLists?: boolean;
|
|
17
15
|
}): ListCollection<Def, Name>;
|
|
16
|
+
read<_Query extends {
|
|
17
|
+
artifact: QueryArtifact;
|
|
18
|
+
}>({ query, variables, }: {
|
|
19
|
+
query: _Query;
|
|
20
|
+
variables?: QueryInput<QueryList<Def>, _Query>;
|
|
21
|
+
}): {
|
|
22
|
+
data: QueryValue<QueryList<Def>, _Query> | null;
|
|
23
|
+
partial: boolean;
|
|
24
|
+
};
|
|
25
|
+
write<_Query extends {
|
|
26
|
+
artifact: QueryArtifact;
|
|
27
|
+
}>({ query, variables, data, }: {
|
|
28
|
+
query: _Query;
|
|
29
|
+
data: QueryValue<QueryList<Def>, _Query>;
|
|
30
|
+
variables?: QueryInput<QueryList<Def>, _Query>;
|
|
31
|
+
}): void;
|
|
18
32
|
}
|
|
19
|
-
export declare function _typeInfo<Def extends CacheTypeDef>(cache: Cache<Def>, type: string, field: string): TypeInfo;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { marshalInputs } from "../lib";
|
|
2
2
|
import { ListCollection } from "./list";
|
|
3
3
|
import { Record } from "./record";
|
|
4
4
|
class Cache {
|
|
@@ -12,19 +12,6 @@ class Cache {
|
|
|
12
12
|
Please acknowledge this by setting acceptImperativeInstability to true in your config file.`);
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
|
-
setFieldType(...args) {
|
|
16
|
-
this.validateInstabilityWarning();
|
|
17
|
-
this._internal_unstable._internal_unstable.schema.setFieldType(...args);
|
|
18
|
-
}
|
|
19
|
-
get root() {
|
|
20
|
-
this.validateInstabilityWarning();
|
|
21
|
-
return new Record({
|
|
22
|
-
cache: this,
|
|
23
|
-
type: "Query",
|
|
24
|
-
id: rootID,
|
|
25
|
-
idFields: {}
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
15
|
get(type, data) {
|
|
29
16
|
this.validateInstabilityWarning();
|
|
30
17
|
let recordID = this._internal_unstable._internal_unstable.id(type, data);
|
|
@@ -42,6 +29,7 @@ Please acknowledge this by setting acceptImperativeInstability to true in your c
|
|
|
42
29
|
return this._internal_unstable._internal_unstable.config;
|
|
43
30
|
}
|
|
44
31
|
list(name, { parentID, allLists } = {}) {
|
|
32
|
+
this.validateInstabilityWarning();
|
|
45
33
|
return new ListCollection({
|
|
46
34
|
cache: this,
|
|
47
35
|
name,
|
|
@@ -49,24 +37,34 @@ Please acknowledge this by setting acceptImperativeInstability to true in your c
|
|
|
49
37
|
allLists
|
|
50
38
|
});
|
|
51
39
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
40
|
+
read({
|
|
41
|
+
query,
|
|
42
|
+
variables
|
|
43
|
+
}) {
|
|
44
|
+
this.validateInstabilityWarning();
|
|
45
|
+
return this._internal_unstable.read({
|
|
46
|
+
selection: query.artifact.selection,
|
|
47
|
+
variables
|
|
48
|
+
});
|
|
60
49
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
50
|
+
write({
|
|
51
|
+
query,
|
|
52
|
+
variables,
|
|
53
|
+
data
|
|
54
|
+
}) {
|
|
55
|
+
this.validateInstabilityWarning();
|
|
56
|
+
this._internal_unstable.write({
|
|
57
|
+
selection: query.artifact.selection,
|
|
58
|
+
data,
|
|
59
|
+
variables: marshalInputs({
|
|
60
|
+
config: this.config,
|
|
61
|
+
artifact: query.artifact,
|
|
62
|
+
input: variables
|
|
63
|
+
}) ?? {}
|
|
64
|
+
});
|
|
65
|
+
return;
|
|
66
66
|
}
|
|
67
|
-
return info;
|
|
68
67
|
}
|
|
69
68
|
export {
|
|
70
|
-
Cache
|
|
71
|
-
_typeInfo
|
|
69
|
+
Cache
|
|
72
70
|
};
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { keyFieldsForType } from "../lib/config";
|
|
2
|
-
import { _typeInfo } from "./cache";
|
|
3
1
|
import { Record } from "./record";
|
|
4
2
|
class ListCollection {
|
|
5
3
|
#parentID;
|
|
@@ -60,7 +58,7 @@ class ListCollection {
|
|
|
60
58
|
return new ListCollection({
|
|
61
59
|
parentID: this.#parentID,
|
|
62
60
|
allLists: this.#allLists,
|
|
63
|
-
when:
|
|
61
|
+
when: filter,
|
|
64
62
|
cache: this.#cache,
|
|
65
63
|
name: this.#name
|
|
66
64
|
});
|
|
@@ -96,36 +94,16 @@ class ListCollection {
|
|
|
96
94
|
}
|
|
97
95
|
}
|
|
98
96
|
#listOperationPayload(records) {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
};
|
|
97
|
+
let selection = this.#collection.selection;
|
|
98
|
+
const connectionSelection = selection.fields?.["edges"]?.selection?.fields?.node.selection;
|
|
99
|
+
if (connectionSelection) {
|
|
100
|
+
selection = connectionSelection;
|
|
101
|
+
}
|
|
105
102
|
const data = [];
|
|
106
103
|
for (const record of records) {
|
|
107
104
|
if (!(record instanceof Record)) {
|
|
108
105
|
throw new Error("You must provide a Record to a list operation");
|
|
109
106
|
}
|
|
110
|
-
const keys = keyFieldsForType(this.#cache.config, record.type);
|
|
111
|
-
selection.abstractFields.fields[record.type] = keys.reduce(
|
|
112
|
-
(acc, key) => {
|
|
113
|
-
const keyInfo = _typeInfo(this.#cache, record.type, key);
|
|
114
|
-
return {
|
|
115
|
-
...acc,
|
|
116
|
-
[key]: {
|
|
117
|
-
type: keyInfo.type,
|
|
118
|
-
keyRaw: key
|
|
119
|
-
}
|
|
120
|
-
};
|
|
121
|
-
},
|
|
122
|
-
{
|
|
123
|
-
__typename: {
|
|
124
|
-
type: "String",
|
|
125
|
-
keyRaw: "__typename"
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
);
|
|
129
107
|
data.push({ __typename: record.type, ...record.idFields });
|
|
130
108
|
}
|
|
131
109
|
return {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import type { FragmentArtifact } from '../lib/types';
|
|
1
2
|
import type { Cache } from './cache';
|
|
2
|
-
import type {
|
|
3
|
+
import type { CacheTypeDef, FragmentList, FragmentValue, FragmentVariables, ValidTypes } from './types';
|
|
3
4
|
export declare class Record<Def extends CacheTypeDef, Type extends ValidTypes<Def>> {
|
|
4
5
|
#private;
|
|
5
6
|
type: string;
|
|
@@ -10,22 +11,21 @@ export declare class Record<Def extends CacheTypeDef, Type extends ValidTypes<De
|
|
|
10
11
|
idFields: {};
|
|
11
12
|
id: string;
|
|
12
13
|
});
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
read<_Fragment extends {
|
|
15
|
+
artifact: FragmentArtifact;
|
|
16
|
+
}>({ fragment, variables, }: {
|
|
17
|
+
fragment: _Fragment;
|
|
18
|
+
variables?: FragmentVariables<FragmentList<Def, Type>, _Fragment>;
|
|
19
|
+
}): {
|
|
20
|
+
data: FragmentValue<FragmentList<Def, Type>, _Fragment> | null;
|
|
21
|
+
partial: boolean;
|
|
22
|
+
};
|
|
23
|
+
write<_Fragment extends {
|
|
24
|
+
artifact: FragmentArtifact;
|
|
25
|
+
}, _Variable>(args: {
|
|
26
|
+
fragment: _Fragment;
|
|
27
|
+
data: FragmentValue<FragmentList<Def, Type>, _Fragment>;
|
|
28
|
+
variables?: FragmentVariables<FragmentList<Def, Type>, _Fragment>;
|
|
17
29
|
}): void;
|
|
18
|
-
get<Field extends TypeFieldNames<Def, Type>>({ field, args, }: {
|
|
19
|
-
field: Field;
|
|
20
|
-
args?: ArgType<Def, Type, Field>;
|
|
21
|
-
}): FieldType<Def, Type, Field>;
|
|
22
30
|
delete(): void;
|
|
23
31
|
}
|
|
24
|
-
export declare function computeKey({ field, args }: {
|
|
25
|
-
field: string;
|
|
26
|
-
args?: {
|
|
27
|
-
[key: string]: any;
|
|
28
|
-
};
|
|
29
|
-
}): string;
|
|
30
|
-
export declare const stringifyObjectWithNoQuotesOnKeys: (obj_from_json: {}) => string;
|
|
31
|
-
export declare function marshalNestedList(list: any[]): any[];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { rootID } from "../cache/cache";
|
|
2
|
+
import { marshalInputs } from "../lib";
|
|
2
3
|
import { keyFieldsForType } from "../lib/config";
|
|
3
|
-
import { _typeInfo } from "./cache";
|
|
4
4
|
class Record {
|
|
5
5
|
#id;
|
|
6
6
|
#cache;
|
|
@@ -24,199 +24,36 @@ class Record {
|
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
value
|
|
27
|
+
read({
|
|
28
|
+
fragment,
|
|
29
|
+
variables
|
|
31
30
|
}) {
|
|
32
|
-
this.#cache.
|
|
33
|
-
|
|
34
|
-
const typeInfo = _typeInfo(this.#cache, this.type, field);
|
|
35
|
-
let newValue;
|
|
36
|
-
if (typeInfo.link) {
|
|
37
|
-
const keys = keyFieldsForType(this.#cache.config, typeInfo.type);
|
|
38
|
-
typeInfo.selection = {
|
|
39
|
-
fields: keys.reduce(
|
|
40
|
-
(acc, key2) => {
|
|
41
|
-
const keyInfo = _typeInfo(this.#cache, typeInfo.type, key2);
|
|
42
|
-
return {
|
|
43
|
-
...acc,
|
|
44
|
-
[key2]: {
|
|
45
|
-
type: keyInfo.type,
|
|
46
|
-
keyRaw: key2
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
},
|
|
50
|
-
{
|
|
51
|
-
__typename: {
|
|
52
|
-
type: "String",
|
|
53
|
-
keyRaw: "__typename"
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
)
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
if (!typeInfo.link) {
|
|
60
|
-
const fnMarshal = this.#cache.config.scalars?.[typeInfo.type]?.marshal;
|
|
61
|
-
if (fnMarshal) {
|
|
62
|
-
newValue = fnMarshal(value);
|
|
63
|
-
} else {
|
|
64
|
-
newValue = value;
|
|
65
|
-
}
|
|
66
|
-
} else if (value instanceof Record) {
|
|
67
|
-
newValue = {
|
|
68
|
-
...value.idFields,
|
|
69
|
-
__typename: value.type
|
|
70
|
-
};
|
|
71
|
-
} else if (Array.isArray(value)) {
|
|
72
|
-
newValue = marshalNestedList(value);
|
|
73
|
-
} else if (value !== null) {
|
|
74
|
-
throw new Error("Value must be a RecordProxy if the field is a link to another record");
|
|
75
|
-
}
|
|
76
|
-
this.#cache._internal_unstable._internal_unstable.lifetimes.resetLifetime(this.#id, key);
|
|
77
|
-
this.#cache._internal_unstable.write({
|
|
31
|
+
return this.#cache._internal_unstable.read({
|
|
32
|
+
selection: fragment.artifact.selection,
|
|
78
33
|
parent: this.#id,
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
},
|
|
87
|
-
data: {
|
|
88
|
-
[field]: newValue
|
|
89
|
-
}
|
|
34
|
+
variables: marshalInputs({
|
|
35
|
+
config: this.#cache.config,
|
|
36
|
+
artifact: fragment.artifact,
|
|
37
|
+
input: variables
|
|
38
|
+
}) ?? void 0
|
|
90
39
|
});
|
|
91
40
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
this.#cache.validateInstabilityWarning();
|
|
97
|
-
const key = computeKey({ field, args });
|
|
98
|
-
const typeInfo = _typeInfo(this.#cache, this.type, field);
|
|
99
|
-
if (typeInfo.link) {
|
|
100
|
-
const keys = keyFieldsForType(this.#cache.config, typeInfo.type);
|
|
101
|
-
typeInfo.selection = {
|
|
102
|
-
fields: keys.reduce(
|
|
103
|
-
(acc, key2) => {
|
|
104
|
-
const keyInfo = _typeInfo(this.#cache, typeInfo.type, key2);
|
|
105
|
-
return {
|
|
106
|
-
...acc,
|
|
107
|
-
[key2]: {
|
|
108
|
-
type: keyInfo.type,
|
|
109
|
-
keyRaw: key2
|
|
110
|
-
}
|
|
111
|
-
};
|
|
112
|
-
},
|
|
113
|
-
{
|
|
114
|
-
__typename: {
|
|
115
|
-
type: "String",
|
|
116
|
-
keyRaw: "__typename"
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
)
|
|
120
|
-
};
|
|
121
|
-
}
|
|
122
|
-
const result = this.#cache._internal_unstable.read({
|
|
41
|
+
write(args) {
|
|
42
|
+
this.#cache._internal_unstable.write({
|
|
43
|
+
data: args.data,
|
|
44
|
+
selection: args.fragment.artifact.selection,
|
|
123
45
|
parent: this.#id,
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
}
|
|
46
|
+
variables: marshalInputs({
|
|
47
|
+
config: this.#cache.config,
|
|
48
|
+
artifact: args.fragment.artifact,
|
|
49
|
+
input: args.variables
|
|
50
|
+
}) ?? void 0
|
|
132
51
|
});
|
|
133
|
-
if (!typeInfo.link) {
|
|
134
|
-
return result.data?.[field] ?? (typeInfo.nullable ? null : void 0);
|
|
135
|
-
}
|
|
136
|
-
const data = result.data?.[field] || {};
|
|
137
|
-
let finalResult = unmarshalNestedList(
|
|
138
|
-
this.#cache,
|
|
139
|
-
!Array.isArray(data) ? [data] : data
|
|
140
|
-
).map((val) => {
|
|
141
|
-
if (typeInfo.nullable && (val === null || Object.keys(val).length === 0)) {
|
|
142
|
-
return null;
|
|
143
|
-
}
|
|
144
|
-
return val;
|
|
145
|
-
});
|
|
146
|
-
return Array.isArray(data) ? finalResult : finalResult[0];
|
|
147
52
|
}
|
|
148
53
|
delete() {
|
|
149
54
|
this.#cache._internal_unstable.delete(this.#id);
|
|
150
55
|
}
|
|
151
56
|
}
|
|
152
|
-
function computeKey({ field, args }) {
|
|
153
|
-
const keys = Object.keys(args ?? {});
|
|
154
|
-
keys.sort();
|
|
155
|
-
return args && keys.length > 0 ? `${field}(${keys.map((key) => `${key}: ${stringifyObjectWithNoQuotesOnKeys(args[key])}`).join(", ")})` : field;
|
|
156
|
-
}
|
|
157
|
-
const stringifyObjectWithNoQuotesOnKeys = (obj_from_json) => {
|
|
158
|
-
if (Array.isArray(obj_from_json)) {
|
|
159
|
-
return `[${obj_from_json.map((obj) => `${stringifyObjectWithNoQuotesOnKeys(obj)}`).join(", ")}]`;
|
|
160
|
-
}
|
|
161
|
-
if (typeof obj_from_json !== "object" || obj_from_json instanceof Date || obj_from_json === null) {
|
|
162
|
-
return JSON.stringify(obj_from_json).replace(/"([^"]+)":/g, "$1: ");
|
|
163
|
-
}
|
|
164
|
-
return `{${Object.keys(obj_from_json).map((key) => `${key}: ${stringifyObjectWithNoQuotesOnKeys(obj_from_json[key])}`).join(", ")}}`;
|
|
165
|
-
};
|
|
166
|
-
function marshalNestedList(list) {
|
|
167
|
-
const newValue = [];
|
|
168
|
-
for (const inner of list) {
|
|
169
|
-
if (Array.isArray(inner)) {
|
|
170
|
-
newValue.push(marshalNestedList(inner));
|
|
171
|
-
} else if (inner instanceof Record) {
|
|
172
|
-
newValue.push({ ...inner.idFields, __typename: inner.type });
|
|
173
|
-
} else {
|
|
174
|
-
newValue.push(inner);
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
return newValue;
|
|
178
|
-
}
|
|
179
|
-
function unmarshalNestedList(cache, list) {
|
|
180
|
-
const newValue = [];
|
|
181
|
-
for (const inner of list) {
|
|
182
|
-
if (Array.isArray(inner)) {
|
|
183
|
-
newValue.push(unmarshalNestedList(cache, inner));
|
|
184
|
-
} else if (inner === null) {
|
|
185
|
-
newValue.push(null);
|
|
186
|
-
} else if (inner.__typename) {
|
|
187
|
-
const type = inner.__typename;
|
|
188
|
-
let recordID = cache._internal_unstable._internal_unstable.id(type, inner);
|
|
189
|
-
if (!recordID) {
|
|
190
|
-
throw new Error("todo");
|
|
191
|
-
}
|
|
192
|
-
const typename = cache._internal_unstable.read({
|
|
193
|
-
selection: {
|
|
194
|
-
fields: {
|
|
195
|
-
__typename: {
|
|
196
|
-
keyRaw: "__typename",
|
|
197
|
-
type: "String"
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
},
|
|
201
|
-
parent: recordID
|
|
202
|
-
}).data?.__typename;
|
|
203
|
-
newValue.push(
|
|
204
|
-
new Record({
|
|
205
|
-
cache,
|
|
206
|
-
type: type || typename,
|
|
207
|
-
idFields: inner,
|
|
208
|
-
id: recordID
|
|
209
|
-
})
|
|
210
|
-
);
|
|
211
|
-
} else {
|
|
212
|
-
newValue.push(inner);
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
return newValue;
|
|
216
|
-
}
|
|
217
57
|
export {
|
|
218
|
-
Record
|
|
219
|
-
computeKey,
|
|
220
|
-
marshalNestedList,
|
|
221
|
-
stringifyObjectWithNoQuotesOnKeys
|
|
58
|
+
Record
|
|
222
59
|
};
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import { type SubscriptionSelection, type FragmentArtifact, type QueryArtifact } from '../../lib';
|
|
1
2
|
import { Cache } from '../cache';
|
|
2
3
|
import type { Record } from '../record';
|
|
3
4
|
type CacheTypeDef = {
|
|
4
5
|
types: {
|
|
5
6
|
__ROOT__: {
|
|
6
7
|
idFields: {};
|
|
8
|
+
fragments: [];
|
|
7
9
|
fields: {
|
|
8
10
|
test: {
|
|
9
11
|
type: number | null;
|
|
@@ -39,6 +41,19 @@ type CacheTypeDef = {
|
|
|
39
41
|
idFields: {
|
|
40
42
|
id: string;
|
|
41
43
|
};
|
|
44
|
+
fragments: [
|
|
45
|
+
[
|
|
46
|
+
{
|
|
47
|
+
artifact: FragmentArtifact;
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
firstName: string;
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
pattern: string;
|
|
54
|
+
}
|
|
55
|
+
]
|
|
56
|
+
];
|
|
42
57
|
fields: {
|
|
43
58
|
firstName: {
|
|
44
59
|
type: string;
|
|
@@ -62,6 +77,7 @@ type CacheTypeDef = {
|
|
|
62
77
|
idFields: {
|
|
63
78
|
id: string;
|
|
64
79
|
};
|
|
80
|
+
fragments: [];
|
|
65
81
|
fields: {
|
|
66
82
|
name: {
|
|
67
83
|
type: string | null;
|
|
@@ -85,6 +101,7 @@ type CacheTypeDef = {
|
|
|
85
101
|
idFields: {
|
|
86
102
|
id: string;
|
|
87
103
|
};
|
|
104
|
+
fragments: [];
|
|
88
105
|
fields: {
|
|
89
106
|
name: {
|
|
90
107
|
type: string | null;
|
|
@@ -97,6 +114,26 @@ type CacheTypeDef = {
|
|
|
97
114
|
};
|
|
98
115
|
};
|
|
99
116
|
};
|
|
117
|
+
queries: [
|
|
118
|
+
[
|
|
119
|
+
{
|
|
120
|
+
artifact: QueryArtifact;
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
viewer: {
|
|
124
|
+
id: string;
|
|
125
|
+
firstName: string;
|
|
126
|
+
__typename: string;
|
|
127
|
+
parent: {
|
|
128
|
+
id: string;
|
|
129
|
+
firstName: string;
|
|
130
|
+
__typename: string;
|
|
131
|
+
};
|
|
132
|
+
};
|
|
133
|
+
},
|
|
134
|
+
any
|
|
135
|
+
]
|
|
136
|
+
];
|
|
100
137
|
lists: {
|
|
101
138
|
All_Pets: {
|
|
102
139
|
types: 'User' | 'Cat';
|
|
@@ -111,4 +148,10 @@ type CacheTypeDef = {
|
|
|
111
148
|
};
|
|
112
149
|
};
|
|
113
150
|
export declare const testCache: () => Cache<CacheTypeDef>;
|
|
151
|
+
export declare const testFragment: (selection: SubscriptionSelection) => {
|
|
152
|
+
artifact: FragmentArtifact;
|
|
153
|
+
};
|
|
154
|
+
export declare const testQuery: (selection: SubscriptionSelection) => {
|
|
155
|
+
artifact: QueryArtifact;
|
|
156
|
+
};
|
|
114
157
|
export {};
|
|
@@ -1,7 +1,32 @@
|
|
|
1
1
|
import { testConfigFile } from "../../../test";
|
|
2
2
|
import { Cache as _Cache } from "../../cache/cache";
|
|
3
|
+
import {
|
|
4
|
+
ArtifactKind
|
|
5
|
+
} from "../../lib";
|
|
3
6
|
import { Cache } from "../cache";
|
|
4
7
|
const testCache = () => new Cache(new _Cache(testConfigFile()));
|
|
8
|
+
const testFragment = (selection) => ({
|
|
9
|
+
artifact: {
|
|
10
|
+
kind: ArtifactKind.Fragment,
|
|
11
|
+
hash: "",
|
|
12
|
+
raw: "",
|
|
13
|
+
name: "",
|
|
14
|
+
rootType: "User",
|
|
15
|
+
selection
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
const testQuery = (selection) => ({
|
|
19
|
+
artifact: {
|
|
20
|
+
kind: ArtifactKind.Query,
|
|
21
|
+
hash: "",
|
|
22
|
+
raw: "",
|
|
23
|
+
name: "",
|
|
24
|
+
rootType: "Query",
|
|
25
|
+
selection
|
|
26
|
+
}
|
|
27
|
+
});
|
|
5
28
|
export {
|
|
6
|
-
testCache
|
|
29
|
+
testCache,
|
|
30
|
+
testFragment,
|
|
31
|
+
testQuery
|
|
7
32
|
};
|