@distilled.cloud/core 1.0.0-rc.17 → 1.0.0-rc.18
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/lib/_bundle/base.js +2 -2
- package/lib/_bundle/base.js.map +1 -1
- package/lib/_bundle/graphql.js +2 -2
- package/lib/_bundle/graphql.js.map +1 -1
- package/lib/_bundle/rest.js +1 -1
- package/lib/_bundle/rest.js.map +1 -1
- package/lib/annotations.d.ts +15 -0
- package/lib/annotations.d.ts.map +1 -0
- package/lib/annotations.js +2 -0
- package/lib/annotations.js.map +1 -0
- package/lib/api.d.ts +15 -0
- package/lib/api.d.ts.map +1 -1
- package/lib/api.js +1 -1
- package/lib/category.d.ts.map +1 -1
- package/lib/config.d.ts +54 -13
- package/lib/config.d.ts.map +1 -1
- package/lib/config.js +1 -1
- package/lib/debug.d.ts.map +1 -1
- package/lib/error-category.d.ts.map +1 -1
- package/lib/errors.d.ts +2 -13
- package/lib/errors.d.ts.map +1 -1
- package/lib/errors.js +1 -1
- package/lib/graphql.d.ts +14 -0
- package/lib/graphql.d.ts.map +1 -1
- package/lib/index.d.ts +3 -2
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -0
- package/lib/pagination.d.ts +34 -2
- package/lib/pagination.d.ts.map +1 -1
- package/lib/pagination.js +1 -1
- package/lib/protocol-http.d.ts +30 -6
- package/lib/protocol-http.d.ts.map +1 -1
- package/lib/protocol-http.js +1 -1
- package/lib/protocol-rest.d.ts +53 -39
- package/lib/protocol-rest.d.ts.map +1 -1
- package/lib/protocol-rest.js +1 -1
- package/lib/response-validation.d.ts +4 -3
- package/lib/response-validation.d.ts.map +1 -1
- package/lib/schema-lite-typed.js +1 -2
- package/lib/telemetry-debug.d.ts +14 -0
- package/lib/telemetry-debug.d.ts.map +1 -0
- package/lib/telemetry-debug.js +2 -0
- package/lib/telemetry-debug.js.map +1 -0
- package/lib/telemetry-hooks.d.ts +32 -0
- package/lib/telemetry-hooks.d.ts.map +1 -0
- package/lib/telemetry-hooks.js +2 -0
- package/lib/telemetry-hooks.js.map +1 -0
- package/lib/telemetry-host-rules.d.ts +23 -0
- package/lib/telemetry-host-rules.d.ts.map +1 -0
- package/lib/telemetry-host-rules.js +2 -0
- package/lib/telemetry-host-rules.js.map +1 -0
- package/lib/telemetry-lambda-context.d.ts +17 -0
- package/lib/telemetry-lambda-context.d.ts.map +1 -0
- package/lib/telemetry-lambda-context.js +2 -0
- package/lib/telemetry-lambda-context.js.map +1 -0
- package/lib/telemetry-message-context.d.ts +52 -0
- package/lib/telemetry-message-context.d.ts.map +1 -0
- package/lib/telemetry-message-context.js +2 -0
- package/lib/telemetry-message-context.js.map +1 -0
- package/lib/telemetry-metrics.d.ts +6 -0
- package/lib/telemetry-metrics.d.ts.map +1 -0
- package/lib/telemetry-metrics.js +2 -0
- package/lib/telemetry-metrics.js.map +1 -0
- package/lib/telemetry-name-template.d.ts +13 -0
- package/lib/telemetry-name-template.d.ts.map +1 -0
- package/lib/telemetry-name-template.js +2 -0
- package/lib/telemetry-name-template.js.map +1 -0
- package/lib/telemetry-stream.d.ts +9 -0
- package/lib/telemetry-stream.d.ts.map +1 -0
- package/lib/telemetry-stream.js +2 -0
- package/lib/telemetry-stream.js.map +1 -0
- package/lib/telemetry-xray.d.ts +28 -0
- package/lib/telemetry-xray.d.ts.map +1 -0
- package/lib/telemetry-xray.js +2 -0
- package/lib/telemetry-xray.js.map +1 -0
- package/lib/telemetry.d.ts +269 -0
- package/lib/telemetry.d.ts.map +1 -0
- package/lib/telemetry.js +3 -0
- package/lib/telemetry.js.map +1 -0
- package/package.json +1 -3
- package/src/annotations.ts +37 -0
- package/src/api.ts +123 -24
- package/src/category.ts +21 -22
- package/src/config.ts +58 -29
- package/src/debug.ts +9 -6
- package/src/error-category.ts +12 -14
- package/src/errors.ts +7 -7
- package/src/graphql.ts +123 -18
- package/src/index.ts +3 -2
- package/src/pagination.ts +119 -6
- package/src/protocol-http.ts +63 -43
- package/src/protocol-rest.ts +201 -140
- package/src/response-validation.ts +4 -3
- package/src/telemetry-debug.ts +135 -0
- package/src/telemetry-hooks.ts +33 -0
- package/src/telemetry-host-rules.ts +39 -0
- package/src/telemetry-lambda-context.ts +46 -0
- package/src/telemetry-message-context.ts +170 -0
- package/src/telemetry-metrics.ts +69 -0
- package/src/telemetry-name-template.ts +26 -0
- package/src/telemetry-stream.ts +91 -0
- package/src/telemetry-xray.ts +66 -0
- package/src/telemetry.ts +768 -0
- package/lib/codegen/boolean-string-enums.d.ts +0 -36
- package/lib/codegen/boolean-string-enums.d.ts.map +0 -1
- package/lib/codegen/boolean-string-enums.js +0 -147
- package/lib/codegen/boolean-string-enums.js.map +0 -1
- package/lib/codegen/chunk.d.ts +0 -7
- package/lib/codegen/chunk.d.ts.map +0 -1
- package/lib/codegen/chunk.js +0 -139
- package/lib/codegen/chunk.js.map +0 -1
- package/lib/codegen/cli.d.ts +0 -80
- package/lib/codegen/cli.d.ts.map +0 -1
- package/lib/codegen/cli.js +0 -166
- package/lib/codegen/cli.js.map +0 -1
- package/lib/codegen/datafy.d.ts +0 -14
- package/lib/codegen/datafy.d.ts.map +0 -1
- package/lib/codegen/datafy.js +0 -853
- package/lib/codegen/datafy.js.map +0 -1
- package/lib/codegen/dedupe.d.ts +0 -5
- package/lib/codegen/dedupe.d.ts.map +0 -1
- package/lib/codegen/dedupe.js +0 -153
- package/lib/codegen/dedupe.js.map +0 -1
- package/lib/codegen/emit.d.ts +0 -125
- package/lib/codegen/emit.d.ts.map +0 -1
- package/lib/codegen/emit.js +0 -99
- package/lib/codegen/emit.js.map +0 -1
- package/lib/codegen/format.d.ts +0 -11
- package/lib/codegen/format.d.ts.map +0 -1
- package/lib/codegen/format.js +0 -32
- package/lib/codegen/format.js.map +0 -1
- package/lib/codegen/generated-at.d.ts +0 -29
- package/lib/codegen/generated-at.d.ts.map +0 -1
- package/lib/codegen/generated-at.js +0 -78
- package/lib/codegen/generated-at.js.map +0 -1
- package/lib/codegen/generator.d.ts +0 -353
- package/lib/codegen/generator.d.ts.map +0 -1
- package/lib/codegen/generator.js +0 -810
- package/lib/codegen/generator.js.map +0 -1
- package/lib/codegen/graph.d.ts +0 -36
- package/lib/codegen/graph.d.ts.map +0 -1
- package/lib/codegen/graph.js +0 -136
- package/lib/codegen/graph.js.map +0 -1
- package/lib/codegen/graphql-client.d.ts +0 -70
- package/lib/codegen/graphql-client.d.ts.map +0 -1
- package/lib/codegen/graphql-client.js +0 -439
- package/lib/codegen/graphql-client.js.map +0 -1
- package/lib/codegen/graphql.d.ts +0 -207
- package/lib/codegen/graphql.d.ts.map +0 -1
- package/lib/codegen/graphql.js +0 -786
- package/lib/codegen/graphql.js.map +0 -1
- package/lib/codegen/latin1.d.ts +0 -3
- package/lib/codegen/latin1.d.ts.map +0 -1
- package/lib/codegen/latin1.js +0 -126
- package/lib/codegen/latin1.js.map +0 -1
- package/lib/codegen/members.d.ts +0 -32
- package/lib/codegen/members.d.ts.map +0 -1
- package/lib/codegen/members.js +0 -62
- package/lib/codegen/members.js.map +0 -1
- package/lib/codegen/model-diff.d.ts +0 -10
- package/lib/codegen/model-diff.d.ts.map +0 -1
- package/lib/codegen/model-diff.js +0 -67
- package/lib/codegen/model-diff.js.map +0 -1
- package/lib/codegen/naming.d.ts +0 -29
- package/lib/codegen/naming.d.ts.map +0 -1
- package/lib/codegen/naming.js +0 -74
- package/lib/codegen/naming.js.map +0 -1
- package/lib/codegen/openapi-cli.d.ts +0 -52
- package/lib/codegen/openapi-cli.d.ts.map +0 -1
- package/lib/codegen/openapi-cli.js +0 -84
- package/lib/codegen/openapi-cli.js.map +0 -1
- package/lib/codegen/openapi.d.ts +0 -209
- package/lib/codegen/openapi.d.ts.map +0 -1
- package/lib/codegen/openapi.js +0 -1548
- package/lib/codegen/openapi.js.map +0 -1
- package/lib/codegen/operations.d.ts +0 -24
- package/lib/codegen/operations.d.ts.map +0 -1
- package/lib/codegen/operations.js +0 -56
- package/lib/codegen/operations.js.map +0 -1
- package/lib/codegen/pagination.d.ts +0 -39
- package/lib/codegen/pagination.d.ts.map +0 -1
- package/lib/codegen/pagination.js +0 -31
- package/lib/codegen/pagination.js.map +0 -1
- package/lib/codegen/patch-audit.d.ts +0 -84
- package/lib/codegen/patch-audit.d.ts.map +0 -1
- package/lib/codegen/patch-audit.js +0 -366
- package/lib/codegen/patch-audit.js.map +0 -1
- package/lib/codegen/patches.d.ts +0 -129
- package/lib/codegen/patches.d.ts.map +0 -1
- package/lib/codegen/patches.js +0 -472
- package/lib/codegen/patches.js.map +0 -1
- package/lib/codegen/prelude.d.ts +0 -15
- package/lib/codegen/prelude.d.ts.map +0 -1
- package/lib/codegen/prelude.js +0 -60
- package/lib/codegen/prelude.js.map +0 -1
- package/lib/codegen/privatize.d.ts +0 -21
- package/lib/codegen/privatize.d.ts.map +0 -1
- package/lib/codegen/privatize.js +0 -176
- package/lib/codegen/privatize.js.map +0 -1
- package/lib/codegen/proto.d.ts +0 -121
- package/lib/codegen/proto.d.ts.map +0 -1
- package/lib/codegen/proto.js +0 -960
- package/lib/codegen/proto.js.map +0 -1
- package/lib/codegen/pure.d.ts +0 -6
- package/lib/codegen/pure.d.ts.map +0 -1
- package/lib/codegen/pure.js +0 -91
- package/lib/codegen/pure.js.map +0 -1
- package/lib/codegen/rewrite-operation-ids.d.ts +0 -154
- package/lib/codegen/rewrite-operation-ids.d.ts.map +0 -1
- package/lib/codegen/rewrite-operation-ids.js +0 -1117
- package/lib/codegen/rewrite-operation-ids.js.map +0 -1
- package/lib/codegen/spec-path.d.ts +0 -16
- package/lib/codegen/spec-path.d.ts.map +0 -1
- package/lib/codegen/spec-path.js +0 -101
- package/lib/codegen/spec-path.js.map +0 -1
- package/lib/codegen/table.d.ts +0 -5
- package/lib/codegen/table.d.ts.map +0 -1
- package/lib/codegen/table.js +0 -249
- package/lib/codegen/table.js.map +0 -1
- package/lib/json-patch.d.ts +0 -58
- package/lib/json-patch.d.ts.map +0 -1
- package/lib/json-patch.js +0 -2
- package/lib/json-patch.js.map +0 -1
- package/lib/schema-lite-typed.js.map +0 -1
- package/lib/testing.d.ts +0 -40
- package/lib/testing.d.ts.map +0 -1
- package/lib/testing.js +0 -2
- package/lib/testing.js.map +0 -1
- package/src/codegen/boolean-string-enums.ts +0 -155
- package/src/codegen/chunk.ts +0 -147
- package/src/codegen/cli.ts +0 -293
- package/src/codegen/datafy.ts +0 -874
- package/src/codegen/dedupe.ts +0 -173
- package/src/codegen/emit.ts +0 -200
- package/src/codegen/format.ts +0 -49
- package/src/codegen/generated-at.ts +0 -88
- package/src/codegen/generator.ts +0 -1229
- package/src/codegen/graph.ts +0 -151
- package/src/codegen/graphql-client.ts +0 -545
- package/src/codegen/graphql.ts +0 -1145
- package/src/codegen/latin1.ts +0 -131
- package/src/codegen/members.ts +0 -79
- package/src/codegen/model-diff.ts +0 -67
- package/src/codegen/naming.ts +0 -85
- package/src/codegen/openapi-cli.ts +0 -141
- package/src/codegen/openapi.ts +0 -1845
- package/src/codegen/operations.ts +0 -73
- package/src/codegen/pagination.ts +0 -64
- package/src/codegen/patch-audit.ts +0 -480
- package/src/codegen/patches.ts +0 -581
- package/src/codegen/prelude.ts +0 -70
- package/src/codegen/privatize.ts +0 -200
- package/src/codegen/proto.ts +0 -1092
- package/src/codegen/pure.ts +0 -94
- package/src/codegen/rewrite-operation-ids.ts +0 -1219
- package/src/codegen/spec-path.ts +0 -112
- package/src/codegen/table.ts +0 -254
- package/src/json-patch.ts +0 -273
- package/src/testing.ts +0 -74
package/lib/codegen/graphql.js
DELETED
|
@@ -1,786 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
import { toVerbNoun } from "./rewrite-operation-ids.js";
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
export const readIntrospection = (json) => {
|
|
48
|
-
const j = json;
|
|
49
|
-
const schema = j?.data?.__schema ?? j?.__schema ?? (j?.types ? j : undefined);
|
|
50
|
-
if (!schema) {
|
|
51
|
-
throw new Error("introspection JSON has none of `data.__schema`, `__schema`, or a top-level `types`");
|
|
52
|
-
}
|
|
53
|
-
return schema;
|
|
54
|
-
};
|
|
55
|
-
// ============================================================================
|
|
56
|
-
// Smithy prelude targets
|
|
57
|
-
// ============================================================================
|
|
58
|
-
export const PRELUDE = {
|
|
59
|
-
String: "smithy.api#String",
|
|
60
|
-
Boolean: "smithy.api#Boolean",
|
|
61
|
-
Integer: "smithy.api#Integer",
|
|
62
|
-
Long: "smithy.api#Long",
|
|
63
|
-
Double: "smithy.api#Double",
|
|
64
|
-
Timestamp: "smithy.api#Timestamp",
|
|
65
|
-
Document: "smithy.api#Document",
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
const BUILTIN_SCALARS = {
|
|
69
|
-
String: PRELUDE.String,
|
|
70
|
-
ID: PRELUDE.String,
|
|
71
|
-
Int: PRELUDE.Integer,
|
|
72
|
-
Float: PRELUDE.Double,
|
|
73
|
-
Boolean: PRELUDE.Boolean,
|
|
74
|
-
};
|
|
75
|
-
// ============================================================================
|
|
76
|
-
// Small helpers
|
|
77
|
-
// ============================================================================
|
|
78
|
-
const capitalize = (s) => s.charAt(0).toUpperCase() + s.slice(1);
|
|
79
|
-
const toPascalCase = (s) => capitalize(s.replace(/[^a-zA-Z0-9]+(.)/g, (_, c) => c.toUpperCase()));
|
|
80
|
-
const unwrapNonNull = (t) => t.kind === "NON_NULL" && t.ofType
|
|
81
|
-
? { type: t.ofType, nonNull: true }
|
|
82
|
-
: { type: t, nonNull: false };
|
|
83
|
-
|
|
84
|
-
const renderTypeRef = (t) => {
|
|
85
|
-
if (t.kind === "NON_NULL" && t.ofType)
|
|
86
|
-
return `${renderTypeRef(t.ofType)}!`;
|
|
87
|
-
if (t.kind === "LIST" && t.ofType)
|
|
88
|
-
return `[${renderTypeRef(t.ofType)}]`;
|
|
89
|
-
return t.name ?? "Unknown";
|
|
90
|
-
};
|
|
91
|
-
const local = (id) => id.split("#")[1] ?? id;
|
|
92
|
-
const memberIdent = (name) => {
|
|
93
|
-
let out = name.replace(/[^A-Za-z0-9_]/g, "_");
|
|
94
|
-
if (/^[0-9]/.test(out))
|
|
95
|
-
out = `_${out}`;
|
|
96
|
-
return out || "_";
|
|
97
|
-
};
|
|
98
|
-
const enumMemberName = (value) => {
|
|
99
|
-
let out = value
|
|
100
|
-
.toUpperCase()
|
|
101
|
-
.replace(/[^A-Z0-9]+/g, "_")
|
|
102
|
-
.replace(/^_+|_+$/g, "");
|
|
103
|
-
if (out === "")
|
|
104
|
-
out = "VALUE";
|
|
105
|
-
if (/^[0-9]/.test(out))
|
|
106
|
-
out = `_${out}`;
|
|
107
|
-
return out;
|
|
108
|
-
};
|
|
109
|
-
const oneLineDoc = (s) => {
|
|
110
|
-
const t = s?.replace(/\s+/g, " ").trim();
|
|
111
|
-
return t ? t : undefined;
|
|
112
|
-
};
|
|
113
|
-
|
|
114
|
-
const namedType = (ref) => {
|
|
115
|
-
let t = unwrapNonNull(ref).type;
|
|
116
|
-
while (t.kind === "LIST" && t.ofType)
|
|
117
|
-
t = unwrapNonNull(t.ofType).type;
|
|
118
|
-
return t;
|
|
119
|
-
};
|
|
120
|
-
const RELAY_DEFAULTS = {
|
|
121
|
-
after: "after",
|
|
122
|
-
first: "first",
|
|
123
|
-
edges: "edges",
|
|
124
|
-
node: "node",
|
|
125
|
-
pageInfo: "pageInfo",
|
|
126
|
-
endCursor: "endCursor",
|
|
127
|
-
hasNextPage: "hasNextPage",
|
|
128
|
-
mode: "relay",
|
|
129
|
-
};
|
|
130
|
-
const makeRelayCtx = (cfg, typeMap) => {
|
|
131
|
-
const connections = new Map();
|
|
132
|
-
const edges = new Set();
|
|
133
|
-
const pageInfos = new Set();
|
|
134
|
-
const isConnection = (name) => {
|
|
135
|
-
if (!name)
|
|
136
|
-
return false;
|
|
137
|
-
const cached = connections.get(name);
|
|
138
|
-
if (cached !== undefined)
|
|
139
|
-
return cached;
|
|
140
|
-
// Register `false` first: a connection whose node type circles back to
|
|
141
|
-
// the connection must not recurse forever.
|
|
142
|
-
connections.set(name, false);
|
|
143
|
-
const t = typeMap.get(name);
|
|
144
|
-
const fields = t?.kind === "OBJECT" ? (t.fields ?? []) : [];
|
|
145
|
-
const edgesField = fields.find((f) => f.name === cfg.edges);
|
|
146
|
-
const pageInfoField = fields.find((f) => f.name === cfg.pageInfo);
|
|
147
|
-
if (!edgesField || !pageInfoField)
|
|
148
|
-
return false;
|
|
149
|
-
const edgeName = namedType(edgesField.type).name;
|
|
150
|
-
const edgeType = edgeName ? typeMap.get(edgeName) : undefined;
|
|
151
|
-
const hasNode = (edgeType?.fields ?? []).some((f) => f.name === cfg.node);
|
|
152
|
-
if (!hasNode)
|
|
153
|
-
return false;
|
|
154
|
-
const pageInfoName = namedType(pageInfoField.type).name;
|
|
155
|
-
const pageInfoType = pageInfoName ? typeMap.get(pageInfoName) : undefined;
|
|
156
|
-
const hasCursor = (pageInfoType?.fields ?? []).some((f) => f.name === cfg.endCursor);
|
|
157
|
-
if (!hasCursor)
|
|
158
|
-
return false;
|
|
159
|
-
connections.set(name, true);
|
|
160
|
-
if (edgeName)
|
|
161
|
-
edges.add(edgeName);
|
|
162
|
-
if (pageInfoName)
|
|
163
|
-
pageInfos.add(pageInfoName);
|
|
164
|
-
return true;
|
|
165
|
-
};
|
|
166
|
-
// `edges`/`pageInfo` sets are populated as a side effect of recognizing
|
|
167
|
-
// their connection, so classify every object type once up front.
|
|
168
|
-
for (const t of typeMap.values()) {
|
|
169
|
-
if (t.kind === "OBJECT")
|
|
170
|
-
isConnection(t.name);
|
|
171
|
-
}
|
|
172
|
-
return {
|
|
173
|
-
cfg,
|
|
174
|
-
isConnection,
|
|
175
|
-
isEdge: (name) => (name ? edges.has(name) : false),
|
|
176
|
-
isPageInfo: (name) => (name ? pageInfos.has(name) : false),
|
|
177
|
-
};
|
|
178
|
-
};
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
const isTransparentHop = (ctx, parentTypeName, fieldName) => {
|
|
190
|
-
const relay = ctx.relay;
|
|
191
|
-
if (!relay || !parentTypeName)
|
|
192
|
-
return false;
|
|
193
|
-
if (relay.isConnection(parentTypeName)) {
|
|
194
|
-
return fieldName === relay.cfg.edges || fieldName === relay.cfg.pageInfo;
|
|
195
|
-
}
|
|
196
|
-
if (relay.isEdge(parentTypeName))
|
|
197
|
-
return fieldName === relay.cfg.node;
|
|
198
|
-
return false;
|
|
199
|
-
};
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
const expandSelection = (ref, ctx, depth, maxDepth, seen) => {
|
|
206
|
-
const { type } = unwrapNonNull(ref);
|
|
207
|
-
if (type.kind === "LIST" && type.ofType) {
|
|
208
|
-
return expandSelection(type.ofType, ctx, depth, maxDepth, seen);
|
|
209
|
-
}
|
|
210
|
-
if (type.kind !== "OBJECT" && type.kind !== "INTERFACE")
|
|
211
|
-
return undefined;
|
|
212
|
-
if (!type.name)
|
|
213
|
-
return undefined;
|
|
214
|
-
if (seen.has(type.name))
|
|
215
|
-
return undefined;
|
|
216
|
-
if (depth > maxDepth)
|
|
217
|
-
return undefined;
|
|
218
|
-
const concrete = ctx.typeMap.get(type.name);
|
|
219
|
-
if (!concrete?.fields)
|
|
220
|
-
return undefined;
|
|
221
|
-
const nextSeen = new Set([...seen, type.name]);
|
|
222
|
-
const result = [];
|
|
223
|
-
for (const field of concrete.fields) {
|
|
224
|
-
// Skip fields that themselves require args — without user input we can't
|
|
225
|
-
// safely populate them, so we just don't select them.
|
|
226
|
-
if (field.args && field.args.length > 0)
|
|
227
|
-
continue;
|
|
228
|
-
const { type: fieldType } = unwrapNonNull(field.type);
|
|
229
|
-
let actualType = fieldType;
|
|
230
|
-
if (actualType.kind === "LIST" && actualType.ofType) {
|
|
231
|
-
actualType = unwrapNonNull(actualType.ofType).type;
|
|
232
|
-
}
|
|
233
|
-
let children;
|
|
234
|
-
if (actualType.kind === "OBJECT" || actualType.kind === "INTERFACE") {
|
|
235
|
-
const transparent = isTransparentHop(ctx, type.name, field.name);
|
|
236
|
-
children = expandSelection(field.type, ctx, transparent ? depth : depth + 1, maxDepth, nextSeen);
|
|
237
|
-
if (!children || children.length === 0) {
|
|
238
|
-
// Can't recurse further — skip nested object fields beyond depth.
|
|
239
|
-
continue;
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
else if (actualType.kind === "UNION") {
|
|
243
|
-
// Unions need fragments to select fields — skip for the generic walker.
|
|
244
|
-
continue;
|
|
245
|
-
}
|
|
246
|
-
result.push({ name: field.name, type: field.type, children });
|
|
247
|
-
}
|
|
248
|
-
return result;
|
|
249
|
-
};
|
|
250
|
-
|
|
251
|
-
const renderSelectionSet = (fields, indent) => fields
|
|
252
|
-
.map((f) => f.children && f.children.length > 0
|
|
253
|
-
? `${indent}${f.name} {\n${renderSelectionSet(f.children, indent + " ")}\n${indent}}`
|
|
254
|
-
: `${indent}${f.name}`)
|
|
255
|
-
.join("\n");
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
const collectOperationPaths = (field, parentChain, ctx, maxNamespaceDepth, skipDeprecated) => {
|
|
267
|
-
const step = {
|
|
268
|
-
name: field.name,
|
|
269
|
-
args: field.args ?? [],
|
|
270
|
-
returnType: field.type,
|
|
271
|
-
};
|
|
272
|
-
const chain = [...parentChain, step];
|
|
273
|
-
// Try to expand the selection set on this field's return type. If we get a
|
|
274
|
-
// real selection, emit a single op terminating here.
|
|
275
|
-
const selection = expandSelection(field.type, ctx, 1, 3, new Set());
|
|
276
|
-
if (selection && selection.length > 0) {
|
|
277
|
-
return [chain];
|
|
278
|
-
}
|
|
279
|
-
// No selection: this is either a namespace-style field or a scalar leaf.
|
|
280
|
-
const { type: returnType } = unwrapNonNull(field.type);
|
|
281
|
-
let actualReturn = returnType;
|
|
282
|
-
if (actualReturn.kind === "LIST" && actualReturn.ofType) {
|
|
283
|
-
actualReturn = unwrapNonNull(actualReturn.ofType).type;
|
|
284
|
-
}
|
|
285
|
-
const isObject = (actualReturn.kind === "OBJECT" || actualReturn.kind === "INTERFACE") && !!actualReturn.name;
|
|
286
|
-
if (!isObject || chain.length >= maxNamespaceDepth) {
|
|
287
|
-
return [chain];
|
|
288
|
-
}
|
|
289
|
-
const namespaceType = ctx.typeMap.get(actualReturn.name);
|
|
290
|
-
if (!namespaceType?.fields || namespaceType.fields.length === 0) {
|
|
291
|
-
return [chain];
|
|
292
|
-
}
|
|
293
|
-
const paths = [];
|
|
294
|
-
for (const subfield of namespaceType.fields) {
|
|
295
|
-
if (skipDeprecated && subfield.isDeprecated)
|
|
296
|
-
continue;
|
|
297
|
-
paths.push(...collectOperationPaths(subfield, chain, ctx, maxNamespaceDepth, skipDeprecated));
|
|
298
|
-
}
|
|
299
|
-
return paths.length > 0 ? paths : [chain];
|
|
300
|
-
};
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
const pathToFunctionName = (opPath) => {
|
|
306
|
-
if (opPath.length === 0)
|
|
307
|
-
throw new Error("empty path");
|
|
308
|
-
if (opPath.length === 1)
|
|
309
|
-
return opPath[0].name;
|
|
310
|
-
return (opPath[0].name +
|
|
311
|
-
opPath
|
|
312
|
-
.slice(1)
|
|
313
|
-
.map((s) => toPascalCase(s.name))
|
|
314
|
-
.join(""));
|
|
315
|
-
};
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
const buildArgRenames = (opPath) => {
|
|
321
|
-
const argRenames = new Map();
|
|
322
|
-
const usedVarNames = new Set();
|
|
323
|
-
for (const step of opPath) {
|
|
324
|
-
for (const arg of step.args) {
|
|
325
|
-
let varName = arg.name;
|
|
326
|
-
if (usedVarNames.has(varName)) {
|
|
327
|
-
varName = `${step.name}${toPascalCase(arg.name)}`;
|
|
328
|
-
let i = 2;
|
|
329
|
-
while (usedVarNames.has(varName)) {
|
|
330
|
-
varName = `${step.name}${toPascalCase(arg.name)}${i++}`;
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
usedVarNames.add(varName);
|
|
334
|
-
argRenames.set(`${step.name}.${arg.name}`, varName);
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
return argRenames;
|
|
338
|
-
};
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
const buildPathDocument = (type, operationName, opPath, selection, argRenames) => {
|
|
345
|
-
const varDefs = [];
|
|
346
|
-
for (const step of opPath) {
|
|
347
|
-
for (const arg of step.args) {
|
|
348
|
-
const varName = argRenames.get(`${step.name}.${arg.name}`) ?? arg.name;
|
|
349
|
-
varDefs.push(`$${varName}: ${renderTypeRef(arg.type)}`);
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
const header = varDefs.length
|
|
353
|
-
? `${type} ${operationName}(${varDefs.join(", ")})`
|
|
354
|
-
: `${type} ${operationName}`;
|
|
355
|
-
const renderStep = (step, inner, indent) => {
|
|
356
|
-
const argList = step.args
|
|
357
|
-
.map((arg) => {
|
|
358
|
-
const varName = argRenames.get(`${step.name}.${arg.name}`) ?? arg.name;
|
|
359
|
-
return `${arg.name}: $${varName}`;
|
|
360
|
-
})
|
|
361
|
-
.join(", ");
|
|
362
|
-
const call = argList ? `${step.name}(${argList})` : step.name;
|
|
363
|
-
return `${indent}${call} {\n${inner}\n${indent}}`;
|
|
364
|
-
};
|
|
365
|
-
let body;
|
|
366
|
-
const innerIndent = " ".repeat(opPath.length + 1);
|
|
367
|
-
if (selection && selection.length > 0) {
|
|
368
|
-
body = renderSelectionSet(selection, innerIndent);
|
|
369
|
-
}
|
|
370
|
-
else {
|
|
371
|
-
// No selectable subfields — fall back to __typename so the document is
|
|
372
|
-
// always syntactically valid.
|
|
373
|
-
body = `${innerIndent}__typename`;
|
|
374
|
-
}
|
|
375
|
-
let nested = body;
|
|
376
|
-
for (let i = opPath.length - 1; i >= 0; i--) {
|
|
377
|
-
const indent = " ".repeat(i + 1);
|
|
378
|
-
nested = renderStep(opPath[i], nested, indent);
|
|
379
|
-
}
|
|
380
|
-
return `${header} {\n${nested}\n}`;
|
|
381
|
-
};
|
|
382
|
-
|
|
383
|
-
const addShape = (bag, base, def) => {
|
|
384
|
-
let want = memberIdent(base);
|
|
385
|
-
want = capitalize(want);
|
|
386
|
-
let name = want;
|
|
387
|
-
let n = 2;
|
|
388
|
-
while (bag.names.has(name))
|
|
389
|
-
name = `${want}${n++}`;
|
|
390
|
-
bag.names.add(name);
|
|
391
|
-
const id = `${bag.namespace}#${name}`;
|
|
392
|
-
bag.shapes[id] = def;
|
|
393
|
-
return id;
|
|
394
|
-
};
|
|
395
|
-
|
|
396
|
-
const addExact = (bag, name, def) => {
|
|
397
|
-
const id = `${bag.namespace}#${name}`;
|
|
398
|
-
bag.shapes[id] = def;
|
|
399
|
-
return id;
|
|
400
|
-
};
|
|
401
|
-
const makeConverter = (bag, ctx, traits, customScalars) => {
|
|
402
|
-
const enumMemo = new Map();
|
|
403
|
-
const inputMemo = new Map();
|
|
404
|
-
const inputListMemo = new Map();
|
|
405
|
-
const scalarTarget = (name) => BUILTIN_SCALARS[name] ?? customScalars[name] ?? PRELUDE.Document;
|
|
406
|
-
const enumShape = (name) => {
|
|
407
|
-
const cached = enumMemo.get(name);
|
|
408
|
-
if (cached)
|
|
409
|
-
return cached;
|
|
410
|
-
const t = ctx.typeMap.get(name);
|
|
411
|
-
const members = {};
|
|
412
|
-
const used = new Set();
|
|
413
|
-
for (const v of t?.enumValues ?? []) {
|
|
414
|
-
let mn = enumMemberName(v.name);
|
|
415
|
-
let k = 2;
|
|
416
|
-
while (used.has(mn))
|
|
417
|
-
mn = `${enumMemberName(v.name)}_${k++}`;
|
|
418
|
-
used.add(mn);
|
|
419
|
-
members[mn] = {
|
|
420
|
-
target: "smithy.api#Unit",
|
|
421
|
-
traits: { "smithy.api#enumValue": v.name },
|
|
422
|
-
};
|
|
423
|
-
}
|
|
424
|
-
const id = addShape(bag, name, { type: "enum", members });
|
|
425
|
-
enumMemo.set(name, id);
|
|
426
|
-
return id;
|
|
427
|
-
};
|
|
428
|
-
const inputTypeTarget = (ref) => {
|
|
429
|
-
const { type, nonNull } = unwrapNonNull(ref);
|
|
430
|
-
const nullable = !nonNull;
|
|
431
|
-
if (type.kind === "LIST" && type.ofType) {
|
|
432
|
-
const elem = inputTypeTarget(type.ofType);
|
|
433
|
-
const key = `${elem.target}|${elem.nullable}`;
|
|
434
|
-
let listId = inputListMemo.get(key);
|
|
435
|
-
if (!listId) {
|
|
436
|
-
listId = addShape(bag, `${local(elem.target)}List`, {
|
|
437
|
-
type: "list",
|
|
438
|
-
member: { target: elem.target },
|
|
439
|
-
...(elem.nullable ? { traits: { [traits.nullableItems]: {} } } : {}),
|
|
440
|
-
});
|
|
441
|
-
inputListMemo.set(key, listId);
|
|
442
|
-
}
|
|
443
|
-
return { target: listId, nullable };
|
|
444
|
-
}
|
|
445
|
-
if (type.kind === "SCALAR" && type.name) {
|
|
446
|
-
return { target: scalarTarget(type.name), nullable };
|
|
447
|
-
}
|
|
448
|
-
if (type.kind === "ENUM" && type.name) {
|
|
449
|
-
return { target: enumShape(type.name), nullable };
|
|
450
|
-
}
|
|
451
|
-
if (type.kind === "INPUT_OBJECT" && type.name) {
|
|
452
|
-
return { target: inputObjectShape(type.name), nullable };
|
|
453
|
-
}
|
|
454
|
-
return { target: PRELUDE.Document, nullable };
|
|
455
|
-
};
|
|
456
|
-
const inputObjectShape = (name) => {
|
|
457
|
-
const cached = inputMemo.get(name);
|
|
458
|
-
if (cached)
|
|
459
|
-
return cached;
|
|
460
|
-
const t = ctx.typeMap.get(name);
|
|
461
|
-
// Register before filling members so input-object cycles resolve to the
|
|
462
|
-
// shared shape (named smithy shapes reference each other naturally).
|
|
463
|
-
const def = { type: "structure", members: {} };
|
|
464
|
-
const id = addShape(bag, name, def);
|
|
465
|
-
inputMemo.set(name, id);
|
|
466
|
-
const doc = oneLineDoc(t?.description);
|
|
467
|
-
if (doc)
|
|
468
|
-
def.traits = { "smithy.api#documentation": doc };
|
|
469
|
-
for (const f of t?.inputFields ?? []) {
|
|
470
|
-
const { nonNull } = unwrapNonNull(f.type);
|
|
471
|
-
const { target, nullable } = inputTypeTarget(f.type);
|
|
472
|
-
const memberTraits = {};
|
|
473
|
-
if (nonNull)
|
|
474
|
-
memberTraits["smithy.api#required"] = {};
|
|
475
|
-
if (nullable)
|
|
476
|
-
memberTraits[traits.nullable] = {};
|
|
477
|
-
const fdoc = oneLineDoc(f.description);
|
|
478
|
-
if (fdoc)
|
|
479
|
-
memberTraits["smithy.api#documentation"] = fdoc;
|
|
480
|
-
def.members[memberIdent(f.name)] = {
|
|
481
|
-
target,
|
|
482
|
-
...(Object.keys(memberTraits).length ? { traits: memberTraits } : {}),
|
|
483
|
-
};
|
|
484
|
-
}
|
|
485
|
-
return id;
|
|
486
|
-
};
|
|
487
|
-
return {
|
|
488
|
-
bag,
|
|
489
|
-
ctx,
|
|
490
|
-
traits,
|
|
491
|
-
scalarTarget,
|
|
492
|
-
enumShape,
|
|
493
|
-
inputObjectShape,
|
|
494
|
-
inputTypeTarget,
|
|
495
|
-
};
|
|
496
|
-
};
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
const buildOutputTarget = (conv, ref, children, hint) => {
|
|
502
|
-
const { type, nonNull } = unwrapNonNull(ref);
|
|
503
|
-
const nullable = !nonNull;
|
|
504
|
-
if (type.kind === "LIST" && type.ofType) {
|
|
505
|
-
const elem = buildOutputTarget(conv, type.ofType, children, `${hint}Item`);
|
|
506
|
-
const target = addShape(conv.bag, `${hint}List`, {
|
|
507
|
-
type: "list",
|
|
508
|
-
member: { target: elem.target },
|
|
509
|
-
...(elem.nullable ? { traits: { [conv.traits.nullableItems]: {} } } : {}),
|
|
510
|
-
});
|
|
511
|
-
return { target, nullable };
|
|
512
|
-
}
|
|
513
|
-
if (type.kind === "SCALAR" && type.name) {
|
|
514
|
-
return { target: conv.scalarTarget(type.name), nullable };
|
|
515
|
-
}
|
|
516
|
-
if (type.kind === "ENUM" && type.name) {
|
|
517
|
-
return { target: conv.enumShape(type.name), nullable };
|
|
518
|
-
}
|
|
519
|
-
if ((type.kind === "OBJECT" || type.kind === "INTERFACE") && children && children.length > 0) {
|
|
520
|
-
const members = buildSelectionMembers(conv, children, hint);
|
|
521
|
-
const target = addShape(conv.bag, hint, { type: "structure", members });
|
|
522
|
-
return { target, nullable };
|
|
523
|
-
}
|
|
524
|
-
// UNION, selection-less objects, unknowns → opaque.
|
|
525
|
-
return { target: PRELUDE.Document, nullable };
|
|
526
|
-
};
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
const buildSelectionMembers = (conv, fields, hint) => {
|
|
533
|
-
const members = {};
|
|
534
|
-
for (const f of fields) {
|
|
535
|
-
const sub = buildOutputTarget(conv, f.type, f.children, `${hint}${toPascalCase(f.name)}`);
|
|
536
|
-
const memberTraits = { "smithy.api#required": {} };
|
|
537
|
-
if (sub.nullable)
|
|
538
|
-
memberTraits[conv.traits.nullable] = {};
|
|
539
|
-
members[memberIdent(f.name)] = { target: sub.target, traits: memberTraits };
|
|
540
|
-
}
|
|
541
|
-
return members;
|
|
542
|
-
};
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
export const convertGraphQLToSmithy = (options) => {
|
|
551
|
-
const { schema, namespace, serviceName, serviceTitle, serviceDocumentation, serviceVersion = "1.0", endpoint, traits, maxDepth = 3, maxNamespaceDepth = 3, skipDeprecated = true, skipRootField = () => false, customScalars = {}, relay = false, operationNaming = "verbNoun", } = options;
|
|
552
|
-
const typeMap = new Map();
|
|
553
|
-
for (const t of schema.types)
|
|
554
|
-
typeMap.set(t.name, t);
|
|
555
|
-
const relayCfg = relay ? { ...RELAY_DEFAULTS, ...relay } : undefined;
|
|
556
|
-
const ctx = {
|
|
557
|
-
typeMap,
|
|
558
|
-
relay: relayCfg ? makeRelayCtx(relayCfg, typeMap) : undefined,
|
|
559
|
-
};
|
|
560
|
-
// ---- Discover operation paths (queries first, then mutations; names are
|
|
561
|
-
// deduped globally so a query and a mutation can't collide) ----
|
|
562
|
-
const pending = [];
|
|
563
|
-
const seenNames = new Set();
|
|
564
|
-
const collectRoot = (rootTypeName, type) => {
|
|
565
|
-
const rootType = typeMap.get(rootTypeName);
|
|
566
|
-
if (!rootType?.fields)
|
|
567
|
-
return;
|
|
568
|
-
for (const field of rootType.fields) {
|
|
569
|
-
if (skipDeprecated && field.isDeprecated)
|
|
570
|
-
continue;
|
|
571
|
-
if (skipRootField(field.name))
|
|
572
|
-
continue;
|
|
573
|
-
const paths = collectOperationPaths(field, [], ctx, maxNamespaceDepth, skipDeprecated);
|
|
574
|
-
for (const opPath of paths) {
|
|
575
|
-
const functionName = pathToFunctionName(opPath);
|
|
576
|
-
const sdkName = operationNaming === "verbNoun" ? toVerbNoun(functionName) : functionName;
|
|
577
|
-
if (seenNames.has(sdkName)) {
|
|
578
|
-
// Two schema fields (or the same field under two paths) map to
|
|
579
|
-
// one SDK name; the first wins. Silent drops hide real ops.
|
|
580
|
-
if (sdkName !== functionName) {
|
|
581
|
-
console.warn(` ⚠️ verbNoun collision: ${functionName} → ${sdkName} already taken (dropped)`);
|
|
582
|
-
}
|
|
583
|
-
continue;
|
|
584
|
-
}
|
|
585
|
-
seenNames.add(sdkName);
|
|
586
|
-
pending.push({
|
|
587
|
-
functionName,
|
|
588
|
-
opName: toPascalCase(sdkName),
|
|
589
|
-
type,
|
|
590
|
-
path: opPath,
|
|
591
|
-
description: opPath.length === 1 ? oneLineDoc(field.description) : undefined,
|
|
592
|
-
});
|
|
593
|
-
}
|
|
594
|
-
}
|
|
595
|
-
};
|
|
596
|
-
collectRoot(schema.queryType.name, "query");
|
|
597
|
-
if (schema.mutationType)
|
|
598
|
-
collectRoot(schema.mutationType.name, "mutation");
|
|
599
|
-
// ---- Build the smithy model ----
|
|
600
|
-
const bag = { shapes: {}, names: new Set(), namespace };
|
|
601
|
-
// Reserve the op-derived shape names up front so lazily-created shared
|
|
602
|
-
// type shapes (enums, input objects) can never steal them — the operation
|
|
603
|
-
// shape's local name IS the exported const name (via lowerFirst).
|
|
604
|
-
bag.names.add(serviceName);
|
|
605
|
-
for (const op of pending) {
|
|
606
|
-
bag.names.add(op.opName);
|
|
607
|
-
bag.names.add(`${op.opName}Request`);
|
|
608
|
-
bag.names.add(`${op.opName}Response`);
|
|
609
|
-
}
|
|
610
|
-
const conv = makeConverter(bag, ctx, traits, customScalars);
|
|
611
|
-
const serviceOps = [];
|
|
612
|
-
let converted = 0;
|
|
613
|
-
let failed = 0;
|
|
614
|
-
let paginated = 0;
|
|
615
|
-
for (const op of pending) {
|
|
616
|
-
try {
|
|
617
|
-
const argRenames = buildArgRenames(op.path);
|
|
618
|
-
const leaf = op.path[op.path.length - 1];
|
|
619
|
-
const selection = expandSelection(leaf.returnType, ctx, 1, maxDepth, new Set());
|
|
620
|
-
const document = buildPathDocument(op.type, op.functionName, op.path, selection, argRenames);
|
|
621
|
-
const responsePath = op.path.map((s) => s.name).join(".");
|
|
622
|
-
// ---- Input (the GraphQL variables) ----
|
|
623
|
-
const inputMembers = {};
|
|
624
|
-
for (const step of op.path) {
|
|
625
|
-
for (const arg of step.args) {
|
|
626
|
-
const varName = argRenames.get(`${step.name}.${arg.name}`);
|
|
627
|
-
const { nonNull } = unwrapNonNull(arg.type);
|
|
628
|
-
const { target, nullable } = conv.inputTypeTarget(arg.type);
|
|
629
|
-
const memberTraits = {};
|
|
630
|
-
if (nonNull)
|
|
631
|
-
memberTraits["smithy.api#required"] = {};
|
|
632
|
-
if (nullable)
|
|
633
|
-
memberTraits[traits.nullable] = {};
|
|
634
|
-
const adoc = oneLineDoc(arg.description);
|
|
635
|
-
if (adoc)
|
|
636
|
-
memberTraits["smithy.api#documentation"] = adoc;
|
|
637
|
-
inputMembers[memberIdent(varName)] = {
|
|
638
|
-
target,
|
|
639
|
-
...(Object.keys(memberTraits).length ? { traits: memberTraits } : {}),
|
|
640
|
-
};
|
|
641
|
-
}
|
|
642
|
-
}
|
|
643
|
-
const inputId = addExact(bag, `${op.opName}Request`, {
|
|
644
|
-
type: "structure",
|
|
645
|
-
members: inputMembers,
|
|
646
|
-
traits: {
|
|
647
|
-
"smithy.api#input": {},
|
|
648
|
-
[traits.operation]: {
|
|
649
|
-
query: document,
|
|
650
|
-
operationName: op.functionName,
|
|
651
|
-
type: op.type,
|
|
652
|
-
},
|
|
653
|
-
},
|
|
654
|
-
});
|
|
655
|
-
// ---- Output (the selection set under `data.<responsePath>`) ----
|
|
656
|
-
const { type: retType } = unwrapNonNull(leaf.returnType);
|
|
657
|
-
const isBareObject = (retType.kind === "OBJECT" || retType.kind === "INTERFACE") &&
|
|
658
|
-
selection !== undefined &&
|
|
659
|
-
selection.length > 0;
|
|
660
|
-
let outputId;
|
|
661
|
-
if (isBareObject) {
|
|
662
|
-
// Object result: the response struct's members ARE the selection.
|
|
663
|
-
outputId = addExact(bag, `${op.opName}Response`, {
|
|
664
|
-
type: "structure",
|
|
665
|
-
members: buildSelectionMembers(conv, selection, `${op.opName}Response`),
|
|
666
|
-
traits: {
|
|
667
|
-
"smithy.api#output": {},
|
|
668
|
-
[traits.responsePath]: responsePath,
|
|
669
|
-
"smithy.api#documentation": `Selection set for \`${responsePath}\` (unwrapped from the GraphQL \`data\` envelope).`,
|
|
670
|
-
},
|
|
671
|
-
});
|
|
672
|
-
}
|
|
673
|
-
else {
|
|
674
|
-
// List/scalar/enum/opaque result: a sole `result` member carries the
|
|
675
|
-
// whole value; the payload trait makes the generated response type
|
|
676
|
-
// the value itself.
|
|
677
|
-
const inner = buildOutputTarget(conv, leaf.returnType, selection, `${op.opName}Result`);
|
|
678
|
-
outputId = addExact(bag, `${op.opName}Response`, {
|
|
679
|
-
type: "structure",
|
|
680
|
-
members: {
|
|
681
|
-
result: {
|
|
682
|
-
target: inner.target,
|
|
683
|
-
traits: {
|
|
684
|
-
[traits.payload]: {},
|
|
685
|
-
"smithy.api#required": {},
|
|
686
|
-
...(inner.nullable ? { [traits.nullable]: {} } : {}),
|
|
687
|
-
"smithy.api#documentation": `The value of \`data.${responsePath}\`.`,
|
|
688
|
-
},
|
|
689
|
-
},
|
|
690
|
-
},
|
|
691
|
-
traits: {
|
|
692
|
-
"smithy.api#output": {},
|
|
693
|
-
[traits.responsePath]: responsePath,
|
|
694
|
-
},
|
|
695
|
-
});
|
|
696
|
-
}
|
|
697
|
-
// ---- Operation ----
|
|
698
|
-
const opTraits = {
|
|
699
|
-
"smithy.api#http": { method: "POST", uri: endpoint, code: 200 },
|
|
700
|
-
};
|
|
701
|
-
if (op.description) {
|
|
702
|
-
opTraits["smithy.api#documentation"] = op.description;
|
|
703
|
-
}
|
|
704
|
-
if (op.type === "query")
|
|
705
|
-
opTraits["smithy.api#readonly"] = {};
|
|
706
|
-
// Relay connections paginate. The operation must accept the cursor and
|
|
707
|
-
// page-size arguments AND return a connection; anything else (a plain
|
|
708
|
-
// list, a connection reached through a namespace hop whose leaf we
|
|
709
|
-
// didn't select) stays a one-shot call.
|
|
710
|
-
const pg = relayCfg && isBareObject ? relayPaginatedTrait(relayCfg, ctx, leaf, argRenames) : undefined;
|
|
711
|
-
if (pg) {
|
|
712
|
-
opTraits["smithy.api#paginated"] = pg;
|
|
713
|
-
paginated++;
|
|
714
|
-
}
|
|
715
|
-
const opId = addExact(bag, op.opName, {
|
|
716
|
-
type: "operation",
|
|
717
|
-
input: { target: inputId },
|
|
718
|
-
output: { target: outputId },
|
|
719
|
-
traits: opTraits,
|
|
720
|
-
});
|
|
721
|
-
serviceOps.push({ target: opId });
|
|
722
|
-
converted++;
|
|
723
|
-
}
|
|
724
|
-
catch (err) {
|
|
725
|
-
failed++;
|
|
726
|
-
console.error(`❌ ${op.type} ${op.functionName}:`, err);
|
|
727
|
-
}
|
|
728
|
-
}
|
|
729
|
-
addExact(bag, serviceName, {
|
|
730
|
-
type: "service",
|
|
731
|
-
version: serviceVersion,
|
|
732
|
-
operations: serviceOps,
|
|
733
|
-
traits: {
|
|
734
|
-
"smithy.api#title": serviceTitle,
|
|
735
|
-
...(serviceDocumentation ? { "smithy.api#documentation": serviceDocumentation } : {}),
|
|
736
|
-
},
|
|
737
|
-
});
|
|
738
|
-
return {
|
|
739
|
-
model: {
|
|
740
|
-
smithy: "2.0",
|
|
741
|
-
metadata: {
|
|
742
|
-
suppressions: [
|
|
743
|
-
// Every operation is POST <endpoint> — the whole point of GraphQL.
|
|
744
|
-
{ id: "HttpUriConflict", namespace: "*" },
|
|
745
|
-
{ id: "HttpMethodSemantics", namespace: "*" },
|
|
746
|
-
{ id: "UnreferencedShape", namespace: "*" },
|
|
747
|
-
],
|
|
748
|
-
},
|
|
749
|
-
shapes: bag.shapes,
|
|
750
|
-
},
|
|
751
|
-
converted,
|
|
752
|
-
failed,
|
|
753
|
-
paginated,
|
|
754
|
-
shapeCount: Object.keys(bag.shapes).length,
|
|
755
|
-
};
|
|
756
|
-
};
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
const relayPaginatedTrait = (cfg, ctx, leaf, argRenames) => {
|
|
766
|
-
const relay = ctx.relay;
|
|
767
|
-
if (!relay)
|
|
768
|
-
return undefined;
|
|
769
|
-
if (!relay.isConnection(namedType(leaf.returnType).name))
|
|
770
|
-
return undefined;
|
|
771
|
-
const hasArg = (name) => leaf.args.some((a) => a.name === name);
|
|
772
|
-
if (!hasArg(cfg.after) || !hasArg(cfg.first))
|
|
773
|
-
return undefined;
|
|
774
|
-
const inputToken = argRenames.get(`${leaf.name}.${cfg.after}`) ?? cfg.after;
|
|
775
|
-
const pageSize = argRenames.get(`${leaf.name}.${cfg.first}`) ?? cfg.first;
|
|
776
|
-
return {
|
|
777
|
-
mode: cfg.mode,
|
|
778
|
-
inputToken,
|
|
779
|
-
outputToken: `${cfg.pageInfo}.${cfg.endCursor}`,
|
|
780
|
-
hasNextPage: `${cfg.pageInfo}.${cfg.hasNextPage}`,
|
|
781
|
-
// Points *through* the edges so `.items()` streams nodes, not wrappers.
|
|
782
|
-
items: `${cfg.edges}.${cfg.node}`,
|
|
783
|
-
pageSize,
|
|
784
|
-
};
|
|
785
|
-
};
|
|
786
|
-
//# sourceMappingURL=graphql.js.map
|