@snowtop/ent 0.1.0-alpha160-test7 → 0.1.0-alpha161-test1
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/core → core}/query/assoc_query.d.ts +3 -0
- package/{dist/core → core}/query/assoc_query.js +71 -0
- package/{dist/core → core}/query/query.d.ts +3 -0
- package/{dist/core → core}/query/query.js +20 -6
- package/core/query/shared_assoc_test.d.ts +2 -0
- package/core/query/shared_assoc_test.js +1089 -0
- package/core/query/shared_test.d.ts +21 -0
- package/core/query/shared_test.js +736 -0
- package/graphql/query/shared_assoc_test.d.ts +1 -0
- package/graphql/query/shared_assoc_test.js +203 -0
- package/package.json +8 -53
- package/{dist/testutils → testutils}/fake_data/test_helpers.js +2 -1
- package/dist/package.json +0 -64
- package/src/action/action.ts +0 -330
- package/src/action/executor.ts +0 -453
- package/src/action/experimental_action.ts +0 -277
- package/src/action/index.ts +0 -31
- package/src/action/operations.ts +0 -967
- package/src/action/orchestrator.ts +0 -1527
- package/src/action/privacy.ts +0 -37
- package/src/action/relative_value.ts +0 -242
- package/src/action/transaction.ts +0 -38
- package/src/auth/auth.ts +0 -77
- package/src/auth/index.ts +0 -8
- package/src/core/base.ts +0 -367
- package/src/core/clause.ts +0 -1065
- package/src/core/config.ts +0 -219
- package/src/core/const.ts +0 -5
- package/src/core/context.ts +0 -135
- package/src/core/convert.ts +0 -106
- package/src/core/date.ts +0 -23
- package/src/core/db.ts +0 -498
- package/src/core/ent.ts +0 -1740
- package/src/core/global_schema.ts +0 -49
- package/src/core/loaders/assoc_count_loader.ts +0 -99
- package/src/core/loaders/assoc_edge_loader.ts +0 -250
- package/src/core/loaders/index.ts +0 -12
- package/src/core/loaders/loader.ts +0 -66
- package/src/core/loaders/object_loader.ts +0 -489
- package/src/core/loaders/query_loader.ts +0 -314
- package/src/core/loaders/raw_count_loader.ts +0 -175
- package/src/core/logger.ts +0 -49
- package/src/core/privacy.ts +0 -660
- package/src/core/query/assoc_query.ts +0 -240
- package/src/core/query/custom_clause_query.ts +0 -174
- package/src/core/query/custom_query.ts +0 -302
- package/src/core/query/index.ts +0 -9
- package/src/core/query/query.ts +0 -674
- package/src/core/query_impl.ts +0 -32
- package/src/core/viewer.ts +0 -52
- package/src/ent.code-workspace +0 -73
- package/src/graphql/builtins/connection.ts +0 -25
- package/src/graphql/builtins/edge.ts +0 -16
- package/src/graphql/builtins/node.ts +0 -12
- package/src/graphql/graphql.ts +0 -891
- package/src/graphql/graphql_field_helpers.ts +0 -221
- package/src/graphql/index.ts +0 -42
- package/src/graphql/mutations/union.ts +0 -39
- package/src/graphql/node_resolver.ts +0 -122
- package/src/graphql/query/connection_type.ts +0 -113
- package/src/graphql/query/edge_connection.ts +0 -171
- package/src/graphql/query/page_info.ts +0 -34
- package/src/graphql/query/shared_edge_connection.ts +0 -287
- package/src/graphql/scalars/orderby_direction.ts +0 -13
- package/src/graphql/scalars/time.ts +0 -38
- package/src/imports/dataz/example1/_auth.ts +0 -51
- package/src/imports/dataz/example1/_viewer.ts +0 -35
- package/src/imports/index.ts +0 -213
- package/src/index.ts +0 -145
- package/src/parse_schema/parse.ts +0 -585
- package/src/schema/base_schema.ts +0 -224
- package/src/schema/field.ts +0 -1087
- package/src/schema/index.ts +0 -53
- package/src/schema/json_field.ts +0 -94
- package/src/schema/schema.ts +0 -1028
- package/src/schema/struct_field.ts +0 -234
- package/src/schema/union_field.ts +0 -105
- package/src/scripts/custom_compiler.ts +0 -331
- package/src/scripts/custom_graphql.ts +0 -550
- package/src/scripts/migrate_v0.1.ts +0 -41
- package/src/scripts/move_types.ts +0 -131
- package/src/scripts/read_schema.ts +0 -67
- package/src/setupPackage.js +0 -42
- package/src/testutils/action/complex_schemas.ts +0 -517
- package/src/testutils/builder.ts +0 -422
- package/src/testutils/context/test_context.ts +0 -25
- package/src/testutils/db/fixture.ts +0 -32
- package/src/testutils/db/temp_db.ts +0 -941
- package/src/testutils/db/value.ts +0 -294
- package/src/testutils/db_mock.ts +0 -351
- package/src/testutils/db_time_zone.ts +0 -40
- package/src/testutils/ent-graphql-tests/index.ts +0 -653
- package/src/testutils/fake_comms.ts +0 -50
- package/src/testutils/fake_data/const.ts +0 -64
- package/src/testutils/fake_data/events_query.ts +0 -145
- package/src/testutils/fake_data/fake_contact.ts +0 -150
- package/src/testutils/fake_data/fake_event.ts +0 -150
- package/src/testutils/fake_data/fake_tag.ts +0 -139
- package/src/testutils/fake_data/fake_user.ts +0 -232
- package/src/testutils/fake_data/index.ts +0 -1
- package/src/testutils/fake_data/internal.ts +0 -8
- package/src/testutils/fake_data/tag_query.ts +0 -56
- package/src/testutils/fake_data/test_helpers.ts +0 -388
- package/src/testutils/fake_data/user_query.ts +0 -524
- package/src/testutils/fake_log.ts +0 -52
- package/src/testutils/mock_date.ts +0 -10
- package/src/testutils/mock_log.ts +0 -39
- package/src/testutils/parse_sql.ts +0 -685
- package/src/testutils/test_edge_global_schema.ts +0 -49
- package/src/testutils/write.ts +0 -70
- package/src/tsc/ast.ts +0 -351
- package/src/tsc/compilerOptions.ts +0 -85
- package/src/tsc/move_generated.ts +0 -191
- package/src/tsc/transform.ts +0 -226
- package/src/tsc/transform_action.ts +0 -224
- package/src/tsc/transform_ent.ts +0 -66
- package/src/tsc/transform_schema.ts +0 -546
- package/tsconfig.json +0 -20
- /package/{dist/action → action}/action.d.ts +0 -0
- /package/{dist/action → action}/action.js +0 -0
- /package/{dist/action → action}/executor.d.ts +0 -0
- /package/{dist/action → action}/executor.js +0 -0
- /package/{dist/action → action}/experimental_action.d.ts +0 -0
- /package/{dist/action → action}/experimental_action.js +0 -0
- /package/{dist/action → action}/index.d.ts +0 -0
- /package/{dist/action → action}/index.js +0 -0
- /package/{dist/action → action}/operations.d.ts +0 -0
- /package/{dist/action → action}/operations.js +0 -0
- /package/{dist/action → action}/orchestrator.d.ts +0 -0
- /package/{dist/action → action}/orchestrator.js +0 -0
- /package/{dist/action → action}/privacy.d.ts +0 -0
- /package/{dist/action → action}/privacy.js +0 -0
- /package/{dist/action → action}/relative_value.d.ts +0 -0
- /package/{dist/action → action}/relative_value.js +0 -0
- /package/{dist/action → action}/transaction.d.ts +0 -0
- /package/{dist/action → action}/transaction.js +0 -0
- /package/{dist/auth → auth}/auth.d.ts +0 -0
- /package/{dist/auth → auth}/auth.js +0 -0
- /package/{dist/auth → auth}/index.d.ts +0 -0
- /package/{dist/auth → auth}/index.js +0 -0
- /package/{dist/core → core}/base.d.ts +0 -0
- /package/{dist/core → core}/base.js +0 -0
- /package/{dist/core → core}/clause.d.ts +0 -0
- /package/{dist/core → core}/clause.js +0 -0
- /package/{dist/core → core}/config.d.ts +0 -0
- /package/{dist/core → core}/config.js +0 -0
- /package/{dist/core → core}/const.d.ts +0 -0
- /package/{dist/core → core}/const.js +0 -0
- /package/{dist/core → core}/context.d.ts +0 -0
- /package/{dist/core → core}/context.js +0 -0
- /package/{dist/core → core}/convert.d.ts +0 -0
- /package/{dist/core → core}/convert.js +0 -0
- /package/{dist/core → core}/date.d.ts +0 -0
- /package/{dist/core → core}/date.js +0 -0
- /package/{dist/core → core}/db.d.ts +0 -0
- /package/{dist/core → core}/db.js +0 -0
- /package/{dist/core → core}/ent.d.ts +0 -0
- /package/{dist/core → core}/ent.js +0 -0
- /package/{dist/core → core}/global_schema.d.ts +0 -0
- /package/{dist/core → core}/global_schema.js +0 -0
- /package/{dist/core → core}/loaders/assoc_count_loader.d.ts +0 -0
- /package/{dist/core → core}/loaders/assoc_count_loader.js +0 -0
- /package/{dist/core → core}/loaders/assoc_edge_loader.d.ts +0 -0
- /package/{dist/core → core}/loaders/assoc_edge_loader.js +0 -0
- /package/{dist/core → core}/loaders/index.d.ts +0 -0
- /package/{dist/core → core}/loaders/index.js +0 -0
- /package/{dist/core → core}/loaders/loader.d.ts +0 -0
- /package/{dist/core → core}/loaders/loader.js +0 -0
- /package/{dist/core → core}/loaders/object_loader.d.ts +0 -0
- /package/{dist/core → core}/loaders/object_loader.js +0 -0
- /package/{dist/core → core}/loaders/query_loader.d.ts +0 -0
- /package/{dist/core → core}/loaders/query_loader.js +0 -0
- /package/{dist/core → core}/loaders/raw_count_loader.d.ts +0 -0
- /package/{dist/core → core}/loaders/raw_count_loader.js +0 -0
- /package/{dist/core → core}/logger.d.ts +0 -0
- /package/{dist/core → core}/logger.js +0 -0
- /package/{dist/core → core}/privacy.d.ts +0 -0
- /package/{dist/core → core}/privacy.js +0 -0
- /package/{dist/core → core}/query/custom_clause_query.d.ts +0 -0
- /package/{dist/core → core}/query/custom_clause_query.js +0 -0
- /package/{dist/core → core}/query/custom_query.d.ts +0 -0
- /package/{dist/core → core}/query/custom_query.js +0 -0
- /package/{dist/core → core}/query/index.d.ts +0 -0
- /package/{dist/core → core}/query/index.js +0 -0
- /package/{dist/core → core}/query_impl.d.ts +0 -0
- /package/{dist/core → core}/query_impl.js +0 -0
- /package/{dist/core → core}/viewer.d.ts +0 -0
- /package/{dist/core → core}/viewer.js +0 -0
- /package/{dist/graphql → graphql}/builtins/connection.d.ts +0 -0
- /package/{dist/graphql → graphql}/builtins/connection.js +0 -0
- /package/{dist/graphql → graphql}/builtins/edge.d.ts +0 -0
- /package/{dist/graphql → graphql}/builtins/edge.js +0 -0
- /package/{dist/graphql → graphql}/builtins/node.d.ts +0 -0
- /package/{dist/graphql → graphql}/builtins/node.js +0 -0
- /package/{dist/graphql → graphql}/graphql.d.ts +0 -0
- /package/{dist/graphql → graphql}/graphql.js +0 -0
- /package/{dist/graphql → graphql}/graphql_field_helpers.d.ts +0 -0
- /package/{dist/graphql → graphql}/graphql_field_helpers.js +0 -0
- /package/{dist/graphql → graphql}/index.d.ts +0 -0
- /package/{dist/graphql → graphql}/index.js +0 -0
- /package/{dist/graphql → graphql}/mutations/union.d.ts +0 -0
- /package/{dist/graphql → graphql}/mutations/union.js +0 -0
- /package/{dist/graphql → graphql}/node_resolver.d.ts +0 -0
- /package/{dist/graphql → graphql}/node_resolver.js +0 -0
- /package/{dist/graphql → graphql}/query/connection_type.d.ts +0 -0
- /package/{dist/graphql → graphql}/query/connection_type.js +0 -0
- /package/{dist/graphql → graphql}/query/edge_connection.d.ts +0 -0
- /package/{dist/graphql → graphql}/query/edge_connection.js +0 -0
- /package/{dist/graphql → graphql}/query/page_info.d.ts +0 -0
- /package/{dist/graphql → graphql}/query/page_info.js +0 -0
- /package/{dist/graphql → graphql}/query/shared_edge_connection.d.ts +0 -0
- /package/{dist/graphql → graphql}/query/shared_edge_connection.js +0 -0
- /package/{dist/graphql → graphql}/scalars/orderby_direction.d.ts +0 -0
- /package/{dist/graphql → graphql}/scalars/orderby_direction.js +0 -0
- /package/{dist/graphql → graphql}/scalars/time.d.ts +0 -0
- /package/{dist/graphql → graphql}/scalars/time.js +0 -0
- /package/{dist/imports → imports}/dataz/example1/_auth.d.ts +0 -0
- /package/{dist/imports → imports}/dataz/example1/_auth.js +0 -0
- /package/{dist/imports → imports}/dataz/example1/_viewer.d.ts +0 -0
- /package/{dist/imports → imports}/dataz/example1/_viewer.js +0 -0
- /package/{dist/imports → imports}/index.d.ts +0 -0
- /package/{dist/imports → imports}/index.js +0 -0
- /package/{dist/index.d.ts → index.d.ts} +0 -0
- /package/{dist/index.js → index.js} +0 -0
- /package/{dist/parse_schema → parse_schema}/parse.d.ts +0 -0
- /package/{dist/parse_schema → parse_schema}/parse.js +0 -0
- /package/{dist/schema → schema}/base_schema.d.ts +0 -0
- /package/{dist/schema → schema}/base_schema.js +0 -0
- /package/{dist/schema → schema}/field.d.ts +0 -0
- /package/{dist/schema → schema}/field.js +0 -0
- /package/{dist/schema → schema}/index.d.ts +0 -0
- /package/{dist/schema → schema}/index.js +0 -0
- /package/{dist/schema → schema}/json_field.d.ts +0 -0
- /package/{dist/schema → schema}/json_field.js +0 -0
- /package/{dist/schema → schema}/schema.d.ts +0 -0
- /package/{dist/schema → schema}/schema.js +0 -0
- /package/{dist/schema → schema}/struct_field.d.ts +0 -0
- /package/{dist/schema → schema}/struct_field.js +0 -0
- /package/{dist/schema → schema}/union_field.d.ts +0 -0
- /package/{dist/schema → schema}/union_field.js +0 -0
- /package/{dist/scripts → scripts}/custom_compiler.d.ts +0 -0
- /package/{dist/scripts → scripts}/custom_compiler.js +0 -0
- /package/{dist/scripts → scripts}/custom_graphql.d.ts +0 -0
- /package/{dist/scripts → scripts}/custom_graphql.js +0 -0
- /package/{dist/scripts → scripts}/migrate_v0.1.d.ts +0 -0
- /package/{dist/scripts → scripts}/migrate_v0.1.js +0 -0
- /package/{dist/scripts → scripts}/move_types.d.ts +0 -0
- /package/{dist/scripts → scripts}/move_types.js +0 -0
- /package/{dist/scripts → scripts}/read_schema.d.ts +0 -0
- /package/{dist/scripts → scripts}/read_schema.js +0 -0
- /package/{dist/testutils → testutils}/action/complex_schemas.d.ts +0 -0
- /package/{dist/testutils → testutils}/action/complex_schemas.js +0 -0
- /package/{dist/testutils → testutils}/builder.d.ts +0 -0
- /package/{dist/testutils → testutils}/builder.js +0 -0
- /package/{dist/testutils → testutils}/context/test_context.d.ts +0 -0
- /package/{dist/testutils → testutils}/context/test_context.js +0 -0
- /package/{dist/testutils → testutils}/db/fixture.d.ts +0 -0
- /package/{dist/testutils → testutils}/db/fixture.js +0 -0
- /package/{dist/testutils → testutils}/db/temp_db.d.ts +0 -0
- /package/{dist/testutils → testutils}/db/temp_db.js +0 -0
- /package/{dist/testutils → testutils}/db/value.d.ts +0 -0
- /package/{dist/testutils → testutils}/db/value.js +0 -0
- /package/{dist/testutils → testutils}/db_mock.d.ts +0 -0
- /package/{dist/testutils → testutils}/db_mock.js +0 -0
- /package/{dist/testutils → testutils}/db_time_zone.d.ts +0 -0
- /package/{dist/testutils → testutils}/db_time_zone.js +0 -0
- /package/{dist/testutils → testutils}/ent-graphql-tests/index.d.ts +0 -0
- /package/{dist/testutils → testutils}/ent-graphql-tests/index.js +0 -0
- /package/{dist/testutils → testutils}/fake_comms.d.ts +0 -0
- /package/{dist/testutils → testutils}/fake_comms.js +0 -0
- /package/{dist/testutils → testutils}/fake_data/const.d.ts +0 -0
- /package/{dist/testutils → testutils}/fake_data/const.js +0 -0
- /package/{dist/testutils → testutils}/fake_data/events_query.d.ts +0 -0
- /package/{dist/testutils → testutils}/fake_data/events_query.js +0 -0
- /package/{dist/testutils → testutils}/fake_data/fake_contact.d.ts +0 -0
- /package/{dist/testutils → testutils}/fake_data/fake_contact.js +0 -0
- /package/{dist/testutils → testutils}/fake_data/fake_event.d.ts +0 -0
- /package/{dist/testutils → testutils}/fake_data/fake_event.js +0 -0
- /package/{dist/testutils → testutils}/fake_data/fake_tag.d.ts +0 -0
- /package/{dist/testutils → testutils}/fake_data/fake_tag.js +0 -0
- /package/{dist/testutils → testutils}/fake_data/fake_user.d.ts +0 -0
- /package/{dist/testutils → testutils}/fake_data/fake_user.js +0 -0
- /package/{dist/testutils → testutils}/fake_data/index.d.ts +0 -0
- /package/{dist/testutils → testutils}/fake_data/index.js +0 -0
- /package/{dist/testutils → testutils}/fake_data/internal.d.ts +0 -0
- /package/{dist/testutils → testutils}/fake_data/internal.js +0 -0
- /package/{dist/testutils → testutils}/fake_data/tag_query.d.ts +0 -0
- /package/{dist/testutils → testutils}/fake_data/tag_query.js +0 -0
- /package/{dist/testutils → testutils}/fake_data/test_helpers.d.ts +0 -0
- /package/{dist/testutils → testutils}/fake_data/user_query.d.ts +0 -0
- /package/{dist/testutils → testutils}/fake_data/user_query.js +0 -0
- /package/{dist/testutils → testutils}/fake_log.d.ts +0 -0
- /package/{dist/testutils → testutils}/fake_log.js +0 -0
- /package/{dist/testutils → testutils}/mock_date.d.ts +0 -0
- /package/{dist/testutils → testutils}/mock_date.js +0 -0
- /package/{dist/testutils → testutils}/mock_log.d.ts +0 -0
- /package/{dist/testutils → testutils}/mock_log.js +0 -0
- /package/{dist/testutils → testutils}/parse_sql.d.ts +0 -0
- /package/{dist/testutils → testutils}/parse_sql.js +0 -0
- /package/{dist/testutils → testutils}/test_edge_global_schema.d.ts +0 -0
- /package/{dist/testutils → testutils}/test_edge_global_schema.js +0 -0
- /package/{dist/testutils → testutils}/write.d.ts +0 -0
- /package/{dist/testutils → testutils}/write.js +0 -0
- /package/{dist/tsc → tsc}/ast.d.ts +0 -0
- /package/{dist/tsc → tsc}/ast.js +0 -0
- /package/{dist/tsc → tsc}/compilerOptions.d.ts +0 -0
- /package/{dist/tsc → tsc}/compilerOptions.js +0 -0
- /package/{dist/tsc → tsc}/move_generated.d.ts +0 -0
- /package/{dist/tsc → tsc}/move_generated.js +0 -0
- /package/{dist/tsc → tsc}/transform.d.ts +0 -0
- /package/{dist/tsc → tsc}/transform.js +0 -0
- /package/{dist/tsc → tsc}/transform_action.d.ts +0 -0
- /package/{dist/tsc → tsc}/transform_action.js +0 -0
- /package/{dist/tsc → tsc}/transform_ent.d.ts +0 -0
- /package/{dist/tsc → tsc}/transform_ent.js +0 -0
- /package/{dist/tsc → tsc}/transform_schema.d.ts +0 -0
- /package/{dist/tsc → tsc}/transform_schema.js +0 -0
package/src/graphql/graphql.ts
DELETED
|
@@ -1,891 +0,0 @@
|
|
|
1
|
-
import { GraphQLScalarType } from "graphql";
|
|
2
|
-
import { Data } from "../core/base";
|
|
3
|
-
import type { FieldMap } from "../schema";
|
|
4
|
-
import {
|
|
5
|
-
processFields,
|
|
6
|
-
ProcessedField as ParsedProcessedField,
|
|
7
|
-
} from "../parse_schema/parse";
|
|
8
|
-
import { ImportPath } from "../schema/schema";
|
|
9
|
-
|
|
10
|
-
interface ClassType<T = any> {
|
|
11
|
-
new (...args: any[]): T;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
declare type StringToStringMap = {
|
|
15
|
-
[key: string]: string;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
interface CustomFieldInput {
|
|
19
|
-
graphQLName?: string;
|
|
20
|
-
name?: string;
|
|
21
|
-
functionName?: string;
|
|
22
|
-
args?: Field[];
|
|
23
|
-
results?: Field[];
|
|
24
|
-
fieldType: CustomFieldTypeInput;
|
|
25
|
-
description?: string;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
interface CustomTopLevelInput {
|
|
29
|
-
class?: string; // for inline fields, it's empty
|
|
30
|
-
graphQLName?: string;
|
|
31
|
-
name?: string;
|
|
32
|
-
functionName?: string;
|
|
33
|
-
edgeName?: string;
|
|
34
|
-
args?: Field[];
|
|
35
|
-
results?: Field[];
|
|
36
|
-
extraImports?: ImportPath[];
|
|
37
|
-
functionContents?: string;
|
|
38
|
-
fieldType: CustomFieldTypeInput;
|
|
39
|
-
description?: string;
|
|
40
|
-
list?: boolean;
|
|
41
|
-
connection?: boolean;
|
|
42
|
-
resultType?: string;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
type CustomFieldInputMap = {
|
|
46
|
-
[key: string]: CustomFieldInput[];
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
type CustomTypeInputMap = {
|
|
50
|
-
[key: string]: CustomTypeInput;
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
interface CustomObjectInput {
|
|
54
|
-
name: string;
|
|
55
|
-
graphQLName?: string;
|
|
56
|
-
fields?: CustomFieldInput[];
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export interface CustomGraphQLInput {
|
|
60
|
-
fields?: CustomFieldInputMap;
|
|
61
|
-
inputs?: CustomObjectInput[];
|
|
62
|
-
objects?: CustomObjectInput[];
|
|
63
|
-
args?: CustomObjectInput[];
|
|
64
|
-
queries?: CustomTopLevelInput[];
|
|
65
|
-
mutations?: CustomTopLevelInput[];
|
|
66
|
-
customTypes?: CustomTypeInputMap;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
export interface CustomTypeInput {
|
|
70
|
-
type: string;
|
|
71
|
-
importPath: string;
|
|
72
|
-
tsType?: string;
|
|
73
|
-
tsImportPath?: string;
|
|
74
|
-
enumMap?: StringToStringMap;
|
|
75
|
-
// create a struct type here...
|
|
76
|
-
structFields?: FieldMap;
|
|
77
|
-
|
|
78
|
-
// if enumMap or structField
|
|
79
|
-
// are we creating an inputType or output type
|
|
80
|
-
// determines where file is located and for the struct type, determines if GraphQLInputObjectType or GraphQLObjectType
|
|
81
|
-
inputType?: boolean;
|
|
82
|
-
[x: string]: any;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
export type CustomType = Omit<CustomTypeInput, "structFields"> & {
|
|
86
|
-
structFields?: ParsedProcessedField[];
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
// scalars or classes
|
|
90
|
-
// string for GraphQL name in situation where we can't load the object
|
|
91
|
-
// e.g. User, Contact etc
|
|
92
|
-
// CustomType for types that are not in "graphql" and we need to know where to load it from...
|
|
93
|
-
type Type = GraphQLScalarType | ClassType | string | CustomTypeInput;
|
|
94
|
-
|
|
95
|
-
// node in a connection
|
|
96
|
-
export type GraphQLConnection<T> = { node: T };
|
|
97
|
-
|
|
98
|
-
interface gqlFieldOptionsBase {
|
|
99
|
-
name?: string;
|
|
100
|
-
nullable?: boolean | NullableListOptions;
|
|
101
|
-
description?: string;
|
|
102
|
-
type?: Type | Array<Type> | GraphQLConnection<Type>; // types or lists of types
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
interface gqlFieldArg extends Omit<gqlFieldOptionsBase, "name"> {
|
|
106
|
-
isContextArg?: boolean;
|
|
107
|
-
name: string;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
export interface gqlFieldOptions extends gqlFieldOptionsBase {
|
|
111
|
-
class: string;
|
|
112
|
-
|
|
113
|
-
args?: gqlFieldArg[];
|
|
114
|
-
async?: boolean;
|
|
115
|
-
|
|
116
|
-
// required for @gqlField
|
|
117
|
-
type: NonNullable<gqlFieldOptionsBase["type"]>;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
export interface gqlObjectOptions {
|
|
121
|
-
name?: string;
|
|
122
|
-
description?: string;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
export interface gqlObjectWithInterfaceOptions extends gqlObjectOptions {
|
|
126
|
-
interfaces?: string[];
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
export interface gqlObjectWithUnionOptions extends gqlObjectOptions {
|
|
130
|
-
unionTypes: string[];
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
type gqlMutationOptions = Omit<gqlFieldOptions, "nullable" | "type"> & {
|
|
134
|
-
type?: gqlFieldOptionsBase["type"];
|
|
135
|
-
};
|
|
136
|
-
|
|
137
|
-
// nullable allowed in query. why was it previously not allowed??
|
|
138
|
-
type gqlQueryOptions = gqlFieldOptions;
|
|
139
|
-
|
|
140
|
-
export enum CustomFieldType {
|
|
141
|
-
Accessor = "ACCESSOR",
|
|
142
|
-
Field = "FIELD",
|
|
143
|
-
Function = "FUNCTION",
|
|
144
|
-
AsyncFunction = "ASYNC_FUNCTION",
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
export type CustomFieldTypeInput =
|
|
148
|
-
| "ACCESSOR"
|
|
149
|
-
| "FIELD"
|
|
150
|
-
| "FUNCTION"
|
|
151
|
-
| "ASYNC_FUNCTION";
|
|
152
|
-
|
|
153
|
-
interface CustomFieldImpl {
|
|
154
|
-
nodeName: string;
|
|
155
|
-
gqlName: string;
|
|
156
|
-
functionName: string; // accessorName (not necessarily a function)
|
|
157
|
-
// need enum type for accessor/function/etc so we can build generated code
|
|
158
|
-
importPath?: string;
|
|
159
|
-
fieldType: CustomFieldType;
|
|
160
|
-
description?: string;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
export interface CustomField extends CustomFieldImpl {
|
|
164
|
-
args: Field[];
|
|
165
|
-
results: Field[];
|
|
166
|
-
extraImports?: ImportPath[]; // defined on server
|
|
167
|
-
functionContents?: string; // used in dynamic
|
|
168
|
-
// used by graphql connections e.g. if you a field `foo_connection`, you can specify the edge name here as `foo` so the generated
|
|
169
|
-
// connection is RootToFooConnectionType instead of RootToFooConnectionConnectionType
|
|
170
|
-
// mostly API bloat though but all of this can be changed eventually.
|
|
171
|
-
edgeName?: string;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
export interface CustomMutation extends CustomField {}
|
|
175
|
-
export interface CustomQuery extends CustomField {}
|
|
176
|
-
|
|
177
|
-
export interface ProcessedCustomField extends CustomFieldImpl {
|
|
178
|
-
args: ProcessedField[];
|
|
179
|
-
results: ProcessedField[];
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
export type ProcessCustomFieldMap = {
|
|
183
|
-
[key: string]: ProcessedCustomField[];
|
|
184
|
-
};
|
|
185
|
-
|
|
186
|
-
export interface CustomObject {
|
|
187
|
-
nodeName: string;
|
|
188
|
-
className: string; // TODO both of these 2 the same right now
|
|
189
|
-
description?: string;
|
|
190
|
-
interfaces?: string[];
|
|
191
|
-
unionTypes?: string[];
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
type NullableListOptions = "contents" | "contentsAndList";
|
|
195
|
-
|
|
196
|
-
interface FieldImpl {
|
|
197
|
-
type: string; // TODO
|
|
198
|
-
tsType?: string; // TODO make this required...
|
|
199
|
-
importPath?: string;
|
|
200
|
-
needsResolving?: boolean; // unknown type that we need to resolve eventually
|
|
201
|
-
list?: boolean;
|
|
202
|
-
connection?: boolean;
|
|
203
|
-
name: string;
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
export interface Field extends FieldImpl {
|
|
207
|
-
// if a list and nullable
|
|
208
|
-
// list itself is nullable
|
|
209
|
-
// if a list and items are nullable, list is not nullable but list contains nullable items
|
|
210
|
-
// if a list and both are nullable, both contents and list itself nullable
|
|
211
|
-
nullable?: boolean | NullableListOptions;
|
|
212
|
-
isContextArg?: boolean;
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
export interface ProcessedField extends FieldImpl {
|
|
216
|
-
nullable?: NullableResult;
|
|
217
|
-
isContextArg?: boolean;
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
enum NullableResult {
|
|
221
|
-
CONTENTS = "contents",
|
|
222
|
-
CONTENTS_AND_LIST = "contentsAndList",
|
|
223
|
-
ITEM = "true", // nullable = true
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
export const knownAllowedNames: Map<string, string> = new Map([
|
|
227
|
-
["Date", "Date"],
|
|
228
|
-
["Boolean", "boolean"],
|
|
229
|
-
["Number", "number"],
|
|
230
|
-
["String", "string"],
|
|
231
|
-
// TODO not right to have this and Number
|
|
232
|
-
["Int", "number"],
|
|
233
|
-
["Float", "number"],
|
|
234
|
-
["ID", "ID"],
|
|
235
|
-
["JSON", "any"],
|
|
236
|
-
["Node", "Ent"],
|
|
237
|
-
]);
|
|
238
|
-
|
|
239
|
-
export const knownDisAllowedNames: Map<string, boolean> = new Map([
|
|
240
|
-
["Function", true],
|
|
241
|
-
["Object", true],
|
|
242
|
-
["Array", true],
|
|
243
|
-
["Promise", true],
|
|
244
|
-
]);
|
|
245
|
-
|
|
246
|
-
export const knownInterfaces: Map<string, boolean> = new Map([
|
|
247
|
-
["Node", true],
|
|
248
|
-
["Edge", true],
|
|
249
|
-
["Connection", true],
|
|
250
|
-
]);
|
|
251
|
-
|
|
252
|
-
const isArray = (type: Type | Array<Type>): type is Array<Type> => {
|
|
253
|
-
if (typeof type === "function") {
|
|
254
|
-
return false;
|
|
255
|
-
}
|
|
256
|
-
return (type as Array<Type>).push !== undefined;
|
|
257
|
-
};
|
|
258
|
-
|
|
259
|
-
const isConnection = (
|
|
260
|
-
type: Type | Array<Type> | GraphQLConnection<Type>,
|
|
261
|
-
): type is GraphQLConnection<Type> => {
|
|
262
|
-
if (typeof type !== "object") {
|
|
263
|
-
return false;
|
|
264
|
-
}
|
|
265
|
-
return (type as GraphQLConnection<Type>).node !== undefined;
|
|
266
|
-
};
|
|
267
|
-
|
|
268
|
-
const isString = (type: Type | Array<Type>): type is string => {
|
|
269
|
-
if ((type as string).lastIndexOf !== undefined) {
|
|
270
|
-
return true;
|
|
271
|
-
}
|
|
272
|
-
return false;
|
|
273
|
-
};
|
|
274
|
-
|
|
275
|
-
export const isCustomType = (type: Type): type is CustomTypeInput => {
|
|
276
|
-
return (type as CustomTypeInput).importPath !== undefined;
|
|
277
|
-
};
|
|
278
|
-
|
|
279
|
-
const isGraphQLScalarType = (type: Type): type is GraphQLScalarType => {
|
|
280
|
-
return (type as GraphQLScalarType).serialize !== undefined;
|
|
281
|
-
};
|
|
282
|
-
|
|
283
|
-
export const addCustomType = async (
|
|
284
|
-
type: CustomTypeInput,
|
|
285
|
-
gqlCapture: typeof GQLCapture,
|
|
286
|
-
) => {
|
|
287
|
-
// TODO these should return ReadOnly objects...
|
|
288
|
-
const customTypes = gqlCapture.getCustomTypes();
|
|
289
|
-
const customType = customTypes.get(type.type);
|
|
290
|
-
|
|
291
|
-
if (customType && customType === type) {
|
|
292
|
-
return;
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
const addType = async (type: CustomTypeInput) => {
|
|
296
|
-
// @ts-expect-error
|
|
297
|
-
const typ2: CustomType = { ...type };
|
|
298
|
-
if (type.structFields) {
|
|
299
|
-
typ2.structFields = await processFields(type.structFields);
|
|
300
|
-
}
|
|
301
|
-
customTypes.set(type.type, typ2);
|
|
302
|
-
};
|
|
303
|
-
|
|
304
|
-
if (type.enumMap || type.structFields) {
|
|
305
|
-
await addType(type);
|
|
306
|
-
}
|
|
307
|
-
try {
|
|
308
|
-
const r = require(type.importPath);
|
|
309
|
-
const ct = r[type.type];
|
|
310
|
-
// this gets us the information needed for scalars
|
|
311
|
-
if (ct && isGraphQLScalarType(ct)) {
|
|
312
|
-
type.scalarInfo = {
|
|
313
|
-
description: ct.description,
|
|
314
|
-
name: ct.name,
|
|
315
|
-
};
|
|
316
|
-
if (ct.specifiedByURL) {
|
|
317
|
-
type.scalarInfo.specifiedByUrl = ct.specifiedByURL;
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
} catch (e) {
|
|
321
|
-
if (type.secondaryImportPath) {
|
|
322
|
-
addCustomType(
|
|
323
|
-
{
|
|
324
|
-
...type,
|
|
325
|
-
importPath: type.secondaryImportPath,
|
|
326
|
-
},
|
|
327
|
-
gqlCapture,
|
|
328
|
-
);
|
|
329
|
-
}
|
|
330
|
-
return;
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
if (customType) {
|
|
334
|
-
if (JSON.stringify(customType) !== JSON.stringify(type)) {
|
|
335
|
-
throw new Error(`cannot add multiple custom types of name ${type.type}`);
|
|
336
|
-
}
|
|
337
|
-
return;
|
|
338
|
-
}
|
|
339
|
-
await addType(type);
|
|
340
|
-
};
|
|
341
|
-
|
|
342
|
-
interface typeInfo {
|
|
343
|
-
list?: boolean | undefined;
|
|
344
|
-
scalarType?: boolean;
|
|
345
|
-
connection?: boolean | undefined;
|
|
346
|
-
type: string;
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
const getType = (
|
|
350
|
-
typ: Type | Array<Type> | GraphQLConnection<Type>,
|
|
351
|
-
result: typeInfo,
|
|
352
|
-
): undefined => {
|
|
353
|
-
if (isConnection(typ)) {
|
|
354
|
-
result.connection = true;
|
|
355
|
-
return getType(typ.node, result);
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
if (isArray(typ)) {
|
|
359
|
-
result.list = true;
|
|
360
|
-
return getType(typ[0], result);
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
if (isString(typ)) {
|
|
364
|
-
if (typ.lastIndexOf("]") !== -1) {
|
|
365
|
-
result.list = true;
|
|
366
|
-
result.type = typ.substr(1, typ.length - 2);
|
|
367
|
-
} else {
|
|
368
|
-
result.type = typ;
|
|
369
|
-
}
|
|
370
|
-
return;
|
|
371
|
-
}
|
|
372
|
-
if (isCustomType(typ)) {
|
|
373
|
-
result.type = typ.type;
|
|
374
|
-
// TODO???
|
|
375
|
-
addCustomType(typ, GQLCapture);
|
|
376
|
-
return;
|
|
377
|
-
}
|
|
378
|
-
// GraphQLScalarType or ClassType
|
|
379
|
-
result.scalarType = isGraphQLScalarType(typ);
|
|
380
|
-
result.type = typ.name;
|
|
381
|
-
return;
|
|
382
|
-
};
|
|
383
|
-
|
|
384
|
-
export class GQLCapture {
|
|
385
|
-
private static enabled = false;
|
|
386
|
-
|
|
387
|
-
static enable(enabled: boolean) {
|
|
388
|
-
this.enabled = enabled;
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
static isEnabled(): boolean {
|
|
392
|
-
return this.enabled;
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
// map from class name to fields
|
|
396
|
-
private static customFields: Map<string, CustomField[]> = new Map();
|
|
397
|
-
private static customQueries: CustomQuery[] = [];
|
|
398
|
-
private static customMutations: CustomMutation[] = [];
|
|
399
|
-
private static customArgs: Map<string, CustomObject> = new Map();
|
|
400
|
-
private static customInputObjects: Map<string, CustomObject> = new Map();
|
|
401
|
-
private static customObjects: Map<string, CustomObject> = new Map();
|
|
402
|
-
private static customInterfaces: Map<string, CustomObject> = new Map();
|
|
403
|
-
private static customUnions: Map<string, CustomObject> = new Map();
|
|
404
|
-
private static customTypes: Map<string, CustomType> = new Map();
|
|
405
|
-
|
|
406
|
-
static clear(): void {
|
|
407
|
-
this.customFields.clear();
|
|
408
|
-
this.customQueries = [];
|
|
409
|
-
this.customMutations = [];
|
|
410
|
-
this.customArgs.clear();
|
|
411
|
-
this.customInputObjects.clear();
|
|
412
|
-
this.customObjects.clear();
|
|
413
|
-
this.customInterfaces.clear();
|
|
414
|
-
this.customUnions.clear();
|
|
415
|
-
this.customTypes.clear();
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
static getCustomFields(): Map<string, CustomField[]> {
|
|
419
|
-
return this.customFields;
|
|
420
|
-
}
|
|
421
|
-
|
|
422
|
-
static getCustomMutations(): CustomMutation[] {
|
|
423
|
-
return this.customMutations;
|
|
424
|
-
}
|
|
425
|
-
|
|
426
|
-
static getCustomQueries(): CustomQuery[] {
|
|
427
|
-
return this.customQueries;
|
|
428
|
-
}
|
|
429
|
-
|
|
430
|
-
static getCustomArgs(): Map<string, CustomObject> {
|
|
431
|
-
return this.customArgs;
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
static getCustomInputObjects(): Map<string, CustomObject> {
|
|
435
|
-
return this.customInputObjects;
|
|
436
|
-
}
|
|
437
|
-
|
|
438
|
-
static getCustomObjects(): Map<string, CustomObject> {
|
|
439
|
-
return this.customObjects;
|
|
440
|
-
}
|
|
441
|
-
|
|
442
|
-
static getCustomInterfaces(): Map<string, CustomObject> {
|
|
443
|
-
return this.customInterfaces;
|
|
444
|
-
}
|
|
445
|
-
|
|
446
|
-
static getCustomUnions(): Map<string, CustomObject> {
|
|
447
|
-
return this.customUnions;
|
|
448
|
-
}
|
|
449
|
-
|
|
450
|
-
static getCustomTypes(): Map<string, CustomType> {
|
|
451
|
-
return this.customTypes;
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
private static getNullableArg(fd: Field): ProcessedField {
|
|
455
|
-
let res: ProcessedField = fd as ProcessedField;
|
|
456
|
-
if (fd.nullable === undefined) {
|
|
457
|
-
return res;
|
|
458
|
-
}
|
|
459
|
-
if (fd.nullable === "contents") {
|
|
460
|
-
res.nullable = NullableResult.CONTENTS;
|
|
461
|
-
} else if (fd.nullable === "contentsAndList") {
|
|
462
|
-
res.nullable = NullableResult.CONTENTS_AND_LIST;
|
|
463
|
-
} else {
|
|
464
|
-
res.nullable = NullableResult.ITEM;
|
|
465
|
-
}
|
|
466
|
-
return res;
|
|
467
|
-
}
|
|
468
|
-
|
|
469
|
-
static getProcessedCustomFields(): ProcessCustomFieldMap {
|
|
470
|
-
let result: Data = {};
|
|
471
|
-
for (const [key, value] of this.customFields) {
|
|
472
|
-
result[key] = this.getProcessedCustomFieldsImpl(value);
|
|
473
|
-
}
|
|
474
|
-
return result;
|
|
475
|
-
}
|
|
476
|
-
|
|
477
|
-
static getProcessedCustomMutations(): ProcessedCustomField[] {
|
|
478
|
-
return this.getProcessedCustomFieldsImpl(this.customMutations);
|
|
479
|
-
}
|
|
480
|
-
|
|
481
|
-
static getProcessedCustomQueries(): ProcessedCustomField[] {
|
|
482
|
-
return this.getProcessedCustomFieldsImpl(this.customQueries);
|
|
483
|
-
}
|
|
484
|
-
|
|
485
|
-
private static getProcessedCustomFieldsImpl(
|
|
486
|
-
customFields: CustomField[],
|
|
487
|
-
): ProcessedCustomField[] {
|
|
488
|
-
return customFields.map((field) => {
|
|
489
|
-
let res: ProcessedCustomField = field as ProcessedCustomField;
|
|
490
|
-
res.args = field.args.map((arg) => {
|
|
491
|
-
return this.getNullableArg(arg);
|
|
492
|
-
});
|
|
493
|
-
res.results = field.results.map((result) => {
|
|
494
|
-
return this.getNullableArg(result);
|
|
495
|
-
});
|
|
496
|
-
return res;
|
|
497
|
-
});
|
|
498
|
-
}
|
|
499
|
-
|
|
500
|
-
private static getField(field: gqlFieldOptionsBase | gqlFieldArg): Field {
|
|
501
|
-
let list: boolean | undefined;
|
|
502
|
-
let scalarType = false;
|
|
503
|
-
let connection: boolean | undefined;
|
|
504
|
-
let type = "";
|
|
505
|
-
|
|
506
|
-
if (field?.type) {
|
|
507
|
-
let r: typeInfo = { type: "" };
|
|
508
|
-
getType(field.type, r);
|
|
509
|
-
list = r.list;
|
|
510
|
-
scalarType = r.scalarType || false;
|
|
511
|
-
connection = r.connection;
|
|
512
|
-
type = r.type;
|
|
513
|
-
}
|
|
514
|
-
|
|
515
|
-
if (!type) {
|
|
516
|
-
throw new Error(`type is required for accessor/function/property`);
|
|
517
|
-
}
|
|
518
|
-
if (knownDisAllowedNames.has(type)) {
|
|
519
|
-
throw new Error(
|
|
520
|
-
`${type} isn't a valid type for accessor/function/property`,
|
|
521
|
-
);
|
|
522
|
-
}
|
|
523
|
-
|
|
524
|
-
let result: Field = {
|
|
525
|
-
name: field?.name || "",
|
|
526
|
-
type: type,
|
|
527
|
-
tsType: knownAllowedNames.get(type) || this.customTypes.get(type)?.tsType,
|
|
528
|
-
nullable: field?.nullable,
|
|
529
|
-
list: list,
|
|
530
|
-
connection: connection,
|
|
531
|
-
// @ts-ignore
|
|
532
|
-
isContextArg: field?.isContextArg,
|
|
533
|
-
};
|
|
534
|
-
|
|
535
|
-
// unknown type. we need to flag that this field needs to eventually be resolved
|
|
536
|
-
if (!knownAllowedNames.has(type)) {
|
|
537
|
-
if (scalarType) {
|
|
538
|
-
throw new Error(
|
|
539
|
-
`custom scalar type ${type} is not supported this way. use CustomType syntax. see \`gqlFileUpload\` as an example`,
|
|
540
|
-
);
|
|
541
|
-
}
|
|
542
|
-
result.needsResolving = true;
|
|
543
|
-
}
|
|
544
|
-
return result;
|
|
545
|
-
}
|
|
546
|
-
|
|
547
|
-
static gqlField(options: gqlFieldOptions): any {
|
|
548
|
-
return function (
|
|
549
|
-
_target: any,
|
|
550
|
-
ctx:
|
|
551
|
-
| ClassMethodDecoratorContext
|
|
552
|
-
| ClassFieldDecoratorContext
|
|
553
|
-
| ClassGetterDecoratorContext,
|
|
554
|
-
) {
|
|
555
|
-
if (
|
|
556
|
-
!GQLCapture.isEnabled() ||
|
|
557
|
-
(ctx.kind !== "method" &&
|
|
558
|
-
ctx.kind !== "field" &&
|
|
559
|
-
ctx.kind !== "getter") ||
|
|
560
|
-
ctx.static ||
|
|
561
|
-
ctx.private
|
|
562
|
-
) {
|
|
563
|
-
return;
|
|
564
|
-
}
|
|
565
|
-
|
|
566
|
-
let customField = GQLCapture.getCustomField(ctx, options);
|
|
567
|
-
if (!customField) {
|
|
568
|
-
return;
|
|
569
|
-
}
|
|
570
|
-
const connections = customField.results.filter(
|
|
571
|
-
(result) => result.connection,
|
|
572
|
-
);
|
|
573
|
-
if (connections.length > 1) {
|
|
574
|
-
throw new Error(`if using a connection, need to only return one item`);
|
|
575
|
-
}
|
|
576
|
-
if (connections.length === 1) {
|
|
577
|
-
const conn = connections[0];
|
|
578
|
-
if (conn.list) {
|
|
579
|
-
throw new Error("GraphQLConnection result cannot be a list");
|
|
580
|
-
}
|
|
581
|
-
if (conn.nullable) {
|
|
582
|
-
throw new Error("GraphQLConnection result cannot be nullable");
|
|
583
|
-
}
|
|
584
|
-
if (conn.isContextArg) {
|
|
585
|
-
throw new Error("GraphQLConnection result cannot be contextArg");
|
|
586
|
-
}
|
|
587
|
-
|
|
588
|
-
if (customField.fieldType === CustomFieldType.AsyncFunction) {
|
|
589
|
-
throw new Error(
|
|
590
|
-
`async function not currently supported for GraphQLConnection`,
|
|
591
|
-
);
|
|
592
|
-
}
|
|
593
|
-
}
|
|
594
|
-
let list = GQLCapture.customFields.get(customField.nodeName);
|
|
595
|
-
if (list === undefined) {
|
|
596
|
-
list = [];
|
|
597
|
-
}
|
|
598
|
-
list.push(customField);
|
|
599
|
-
GQLCapture.customFields.set(customField.nodeName, list);
|
|
600
|
-
};
|
|
601
|
-
}
|
|
602
|
-
|
|
603
|
-
private static getCustomField(
|
|
604
|
-
ctx:
|
|
605
|
-
| ClassMethodDecoratorContext
|
|
606
|
-
| ClassFieldDecoratorContext
|
|
607
|
-
| ClassGetterDecoratorContext,
|
|
608
|
-
options: gqlFieldOptions | gqlMutationOptions | gqlQueryOptions,
|
|
609
|
-
allowNoReturnType?: boolean,
|
|
610
|
-
): CustomField {
|
|
611
|
-
let fieldType: CustomFieldType;
|
|
612
|
-
|
|
613
|
-
let args: Field[] = [];
|
|
614
|
-
let results: Field[] = [];
|
|
615
|
-
|
|
616
|
-
switch (ctx.kind) {
|
|
617
|
-
case "method":
|
|
618
|
-
fieldType = CustomFieldType.Function;
|
|
619
|
-
if (options.async) {
|
|
620
|
-
fieldType = CustomFieldType.AsyncFunction;
|
|
621
|
-
}
|
|
622
|
-
break;
|
|
623
|
-
|
|
624
|
-
case "field":
|
|
625
|
-
fieldType = CustomFieldType.Field;
|
|
626
|
-
break;
|
|
627
|
-
|
|
628
|
-
case "getter":
|
|
629
|
-
fieldType = CustomFieldType.Accessor;
|
|
630
|
-
break;
|
|
631
|
-
}
|
|
632
|
-
|
|
633
|
-
if (!allowNoReturnType && !options.type) {
|
|
634
|
-
throw new Error(`type is required for ${fieldType}`);
|
|
635
|
-
}
|
|
636
|
-
if (options.type) {
|
|
637
|
-
// override name property passed down so we return '' as name
|
|
638
|
-
results.push(GQLCapture.getField({ ...options, name: "" }));
|
|
639
|
-
}
|
|
640
|
-
|
|
641
|
-
if (options.args?.length) {
|
|
642
|
-
options.args.forEach((arg) => {
|
|
643
|
-
args.push(GQLCapture.getField(arg));
|
|
644
|
-
});
|
|
645
|
-
}
|
|
646
|
-
|
|
647
|
-
return {
|
|
648
|
-
nodeName: options.class,
|
|
649
|
-
gqlName: options?.name || ctx.name.toString(),
|
|
650
|
-
functionName: ctx.name.toString(),
|
|
651
|
-
args: args,
|
|
652
|
-
results: results,
|
|
653
|
-
fieldType: fieldType!,
|
|
654
|
-
description: options?.description,
|
|
655
|
-
};
|
|
656
|
-
}
|
|
657
|
-
|
|
658
|
-
static gqlContextType(): gqlFieldArg {
|
|
659
|
-
return {
|
|
660
|
-
name: "context",
|
|
661
|
-
isContextArg: true,
|
|
662
|
-
type: "Context",
|
|
663
|
-
};
|
|
664
|
-
}
|
|
665
|
-
|
|
666
|
-
static gqlArgType(options?: gqlObjectOptions): any {
|
|
667
|
-
return function (target: any, ctx: ClassDecoratorContext): void {
|
|
668
|
-
return GQLCapture.customGQLObject(ctx, GQLCapture.customArgs, options);
|
|
669
|
-
};
|
|
670
|
-
}
|
|
671
|
-
|
|
672
|
-
static gqlInputObjectType(options?: gqlObjectOptions): any {
|
|
673
|
-
return function (target: any, ctx: ClassDecoratorContext): void {
|
|
674
|
-
return GQLCapture.customGQLObject(
|
|
675
|
-
ctx,
|
|
676
|
-
GQLCapture.customInputObjects,
|
|
677
|
-
options,
|
|
678
|
-
);
|
|
679
|
-
};
|
|
680
|
-
}
|
|
681
|
-
|
|
682
|
-
static gqlObjectType(options?: gqlObjectWithInterfaceOptions): any {
|
|
683
|
-
return function (target: any, ctx: ClassDecoratorContext): void {
|
|
684
|
-
return GQLCapture.customGQLObject(ctx, GQLCapture.customObjects, options);
|
|
685
|
-
};
|
|
686
|
-
}
|
|
687
|
-
|
|
688
|
-
static gqlUnionType(options: gqlObjectWithUnionOptions): any {
|
|
689
|
-
return function (target: any, ctx: ClassDecoratorContext): void {
|
|
690
|
-
return GQLCapture.customGQLObject(ctx, GQLCapture.customUnions, options);
|
|
691
|
-
};
|
|
692
|
-
}
|
|
693
|
-
|
|
694
|
-
static gqlInterfaceType(options?: gqlObjectOptions): any {
|
|
695
|
-
return function (target: any, ctx: ClassDecoratorContext): void {
|
|
696
|
-
return GQLCapture.customGQLObject(
|
|
697
|
-
ctx,
|
|
698
|
-
GQLCapture.customInterfaces,
|
|
699
|
-
options,
|
|
700
|
-
);
|
|
701
|
-
};
|
|
702
|
-
}
|
|
703
|
-
|
|
704
|
-
private static customGQLObject(
|
|
705
|
-
ctx: ClassDecoratorContext,
|
|
706
|
-
map: Map<string, CustomObject>,
|
|
707
|
-
options?: gqlObjectWithInterfaceOptions | gqlObjectWithUnionOptions,
|
|
708
|
-
) {
|
|
709
|
-
if (!GQLCapture.isEnabled() || ctx.kind !== "class" || !ctx.name) {
|
|
710
|
-
return;
|
|
711
|
-
}
|
|
712
|
-
|
|
713
|
-
let className = ctx.name.toString();
|
|
714
|
-
let nodeName = options?.name || className;
|
|
715
|
-
|
|
716
|
-
map.set(className, {
|
|
717
|
-
className,
|
|
718
|
-
nodeName,
|
|
719
|
-
description: options?.description,
|
|
720
|
-
// @ts-ignore
|
|
721
|
-
interfaces: options?.interfaces,
|
|
722
|
-
// @ts-ignore
|
|
723
|
-
unionTypes: options?.unionTypes,
|
|
724
|
-
});
|
|
725
|
-
}
|
|
726
|
-
|
|
727
|
-
// we want to specify args if any, name, response if any
|
|
728
|
-
static gqlQuery(options: gqlQueryOptions): any {
|
|
729
|
-
return function (target: Function, ctx: ClassMethodDecoratorContext): void {
|
|
730
|
-
if (!GQLCapture.isEnabled()) {
|
|
731
|
-
return;
|
|
732
|
-
}
|
|
733
|
-
|
|
734
|
-
GQLCapture.customQueries.push(GQLCapture.getCustomField(ctx, options));
|
|
735
|
-
};
|
|
736
|
-
}
|
|
737
|
-
|
|
738
|
-
static gqlMutation(options: gqlMutationOptions): any {
|
|
739
|
-
return function (target: Function, ctx: ClassMethodDecoratorContext): void {
|
|
740
|
-
if (!GQLCapture.isEnabled()) {
|
|
741
|
-
return;
|
|
742
|
-
}
|
|
743
|
-
|
|
744
|
-
GQLCapture.customMutations.push(
|
|
745
|
-
GQLCapture.getCustomField(ctx, options, true),
|
|
746
|
-
);
|
|
747
|
-
};
|
|
748
|
-
}
|
|
749
|
-
|
|
750
|
-
static gqlConnection(type: Type): any {
|
|
751
|
-
return {
|
|
752
|
-
node: type,
|
|
753
|
-
};
|
|
754
|
-
}
|
|
755
|
-
|
|
756
|
-
static resolve(objects: string[]): void {
|
|
757
|
-
let baseObjects = new Map<string, boolean>();
|
|
758
|
-
objects.forEach((object) => baseObjects.set(object, true));
|
|
759
|
-
|
|
760
|
-
this.customObjects.forEach((obj, key) => {
|
|
761
|
-
baseObjects.set(key, true);
|
|
762
|
-
|
|
763
|
-
obj.interfaces?.forEach((interfaceName) => {
|
|
764
|
-
const inter = this.customInterfaces.get(interfaceName);
|
|
765
|
-
if (inter) {
|
|
766
|
-
const fields = this.customFields.get(inter.nodeName);
|
|
767
|
-
if (fields) {
|
|
768
|
-
// check for duplicate fields
|
|
769
|
-
// if field is already defined no need to add it
|
|
770
|
-
let objFields = this.customFields.get(obj.nodeName);
|
|
771
|
-
if (!objFields) {
|
|
772
|
-
objFields = [];
|
|
773
|
-
}
|
|
774
|
-
let map = new Map();
|
|
775
|
-
for (const f of objFields) {
|
|
776
|
-
map.set(f.gqlName, f);
|
|
777
|
-
}
|
|
778
|
-
for (const field of fields) {
|
|
779
|
-
const newField = {
|
|
780
|
-
...field,
|
|
781
|
-
nodeName: obj.nodeName,
|
|
782
|
-
};
|
|
783
|
-
if (map.has(field.gqlName)) {
|
|
784
|
-
const existing = map.get(field.gqlName)!;
|
|
785
|
-
if (JSON.stringify(existing) !== JSON.stringify(newField)) {
|
|
786
|
-
throw new Error(
|
|
787
|
-
`object ${obj.nodeName} has duplicate field ${field.gqlName} with different definition`,
|
|
788
|
-
);
|
|
789
|
-
}
|
|
790
|
-
continue;
|
|
791
|
-
}
|
|
792
|
-
objFields.push(newField);
|
|
793
|
-
}
|
|
794
|
-
this.customFields.set(obj.nodeName, objFields);
|
|
795
|
-
}
|
|
796
|
-
} else if (!knownInterfaces.has(interfaceName)) {
|
|
797
|
-
throw new Error(
|
|
798
|
-
`object ${key} references unknown interface ${interfaceName}`,
|
|
799
|
-
);
|
|
800
|
-
}
|
|
801
|
-
});
|
|
802
|
-
});
|
|
803
|
-
|
|
804
|
-
let baseArgs = new Map<string, boolean>();
|
|
805
|
-
this.customArgs.forEach((_val, key) => baseArgs.set(key, true));
|
|
806
|
-
this.customInputObjects.forEach((_val, key) => baseArgs.set(key, true));
|
|
807
|
-
baseArgs.set("Context", true);
|
|
808
|
-
this.customTypes.forEach((_val, key) => baseArgs.set(key, true));
|
|
809
|
-
|
|
810
|
-
this.customUnions.forEach((val, key) => {
|
|
811
|
-
if (this.customFields.has(key)) {
|
|
812
|
-
throw new Error(`union ${key} has custom fields which is not allowed`);
|
|
813
|
-
}
|
|
814
|
-
|
|
815
|
-
val.unionTypes?.forEach((typ) => {
|
|
816
|
-
if (!baseObjects.has(typ)) {
|
|
817
|
-
throw new Error(
|
|
818
|
-
`union ${key} references ${typ} which isn't a graphql object`,
|
|
819
|
-
);
|
|
820
|
-
}
|
|
821
|
-
});
|
|
822
|
-
});
|
|
823
|
-
|
|
824
|
-
// TODO this should be aware of knownCustomTypes
|
|
825
|
-
const resolveFields = (fields: CustomField[]) => {
|
|
826
|
-
fields.forEach((field) => {
|
|
827
|
-
// we have a check earlier that *should* make this path impossible
|
|
828
|
-
field.args.forEach((arg) => {
|
|
829
|
-
if (arg.needsResolving) {
|
|
830
|
-
if (baseArgs.has(arg.type)) {
|
|
831
|
-
arg.needsResolving = false;
|
|
832
|
-
} else {
|
|
833
|
-
throw new Error(
|
|
834
|
-
`arg ${arg.name} of field ${field.functionName} needs resolving. should not be possible`,
|
|
835
|
-
);
|
|
836
|
-
}
|
|
837
|
-
}
|
|
838
|
-
});
|
|
839
|
-
// fields are not because we can return existing ents and we want to run the capturing
|
|
840
|
-
// in parallel with the codegen gathering step so we resolve at the end to make
|
|
841
|
-
// sure there's no dangling objects
|
|
842
|
-
// TODO when we have other objects, we may need to change the logic here
|
|
843
|
-
// but i don't think it applies
|
|
844
|
-
field.results.forEach((result) => {
|
|
845
|
-
if (result.needsResolving) {
|
|
846
|
-
if (
|
|
847
|
-
baseObjects.has(result.type) ||
|
|
848
|
-
this.customUnions.has(result.type) ||
|
|
849
|
-
this.customInterfaces.has(result.type)
|
|
850
|
-
) {
|
|
851
|
-
result.needsResolving = false;
|
|
852
|
-
} else {
|
|
853
|
-
throw new Error(
|
|
854
|
-
`field ${field.functionName} references ${result.type} which isn't a graphql object`,
|
|
855
|
-
);
|
|
856
|
-
}
|
|
857
|
-
}
|
|
858
|
-
});
|
|
859
|
-
});
|
|
860
|
-
};
|
|
861
|
-
GQLCapture.customFields.forEach((customFields) =>
|
|
862
|
-
resolveFields(customFields),
|
|
863
|
-
);
|
|
864
|
-
resolveFields(GQLCapture.customQueries);
|
|
865
|
-
resolveFields(GQLCapture.customMutations);
|
|
866
|
-
}
|
|
867
|
-
}
|
|
868
|
-
|
|
869
|
-
// why is this a static class lol?
|
|
870
|
-
// TODO make all these just plain functions
|
|
871
|
-
export const gqlField = GQLCapture.gqlField;
|
|
872
|
-
|
|
873
|
-
export const gqlArgType = GQLCapture.gqlArgType;
|
|
874
|
-
export const gqlInputObjectType = GQLCapture.gqlInputObjectType;
|
|
875
|
-
export const gqlObjectType = GQLCapture.gqlObjectType;
|
|
876
|
-
export const gqlInterfaceType = GQLCapture.gqlInterfaceType;
|
|
877
|
-
export const gqlUnionType = GQLCapture.gqlUnionType;
|
|
878
|
-
export const gqlQuery = GQLCapture.gqlQuery;
|
|
879
|
-
export const gqlMutation = GQLCapture.gqlMutation;
|
|
880
|
-
export const gqlContextType = GQLCapture.gqlContextType;
|
|
881
|
-
export const gqlConnection = GQLCapture.gqlConnection;
|
|
882
|
-
|
|
883
|
-
// this requires the developer to npm-install "graphql-upload on their own"
|
|
884
|
-
const gqlFileUpload: CustomTypeInput = {
|
|
885
|
-
type: "GraphQLUpload",
|
|
886
|
-
importPath: "graphql-upload",
|
|
887
|
-
tsType: "FileUpload",
|
|
888
|
-
tsImportPath: "graphql-upload",
|
|
889
|
-
};
|
|
890
|
-
|
|
891
|
-
export { gqlFileUpload };
|