@microsoft/rayfin-data 1.21.0 → 1.22.0
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.
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { getPrimaryKeyField } from '@microsoft/rayfin-core';
|
|
2
2
|
import { deserializeDabResponse } from '../utils/serialization';
|
|
3
3
|
import { GraphQLQueryBuilder } from './GraphQLQueryBuilder';
|
|
4
|
+
import { formatGraphQLValue } from './formatValue';
|
|
4
5
|
export class GraphQLEntityClient {
|
|
5
6
|
graphqlClient;
|
|
6
7
|
entityNameString;
|
|
@@ -45,10 +46,11 @@ export class GraphQLEntityClient {
|
|
|
45
46
|
}
|
|
46
47
|
async findById(id) {
|
|
47
48
|
const queryName = `${this.lowercaseFirstLetter(this.entityNameString)}_by_pk`;
|
|
49
|
+
const pkField = getPrimaryKeyField();
|
|
48
50
|
const query = `
|
|
49
51
|
query {
|
|
50
|
-
${queryName}(${
|
|
51
|
-
${
|
|
52
|
+
${queryName}(${pkField}: ${this.formatValue(id)}) {
|
|
53
|
+
${pkField}
|
|
52
54
|
}
|
|
53
55
|
}
|
|
54
56
|
`;
|
|
@@ -112,12 +114,13 @@ export class GraphQLEntityClient {
|
|
|
112
114
|
}
|
|
113
115
|
buildUpdateMutationString(where, data) {
|
|
114
116
|
const mutationName = `update${this.entityNameString}`;
|
|
117
|
+
const pkField = getPrimaryKeyField();
|
|
115
118
|
const id = this.extractId(where);
|
|
116
119
|
const fieldsToReturn = this.getDefaultFields(data);
|
|
117
120
|
return `
|
|
118
121
|
mutation {
|
|
119
122
|
${mutationName}(
|
|
120
|
-
${
|
|
123
|
+
${pkField}: ${this.formatValue(id)},
|
|
121
124
|
item: ${this.formatMutationInput(data)}
|
|
122
125
|
) {
|
|
123
126
|
${fieldsToReturn}
|
|
@@ -127,11 +130,12 @@ export class GraphQLEntityClient {
|
|
|
127
130
|
}
|
|
128
131
|
buildDeleteMutationString(where) {
|
|
129
132
|
const mutationName = `delete${this.entityNameString}`;
|
|
133
|
+
const pkField = getPrimaryKeyField();
|
|
130
134
|
const id = this.extractId(where);
|
|
131
135
|
return `
|
|
132
136
|
mutation {
|
|
133
|
-
${mutationName}(${
|
|
134
|
-
${
|
|
137
|
+
${mutationName}(${pkField}: ${this.formatValue(id)}) {
|
|
138
|
+
${pkField}
|
|
135
139
|
}
|
|
136
140
|
}
|
|
137
141
|
`.trim();
|
|
@@ -217,27 +221,7 @@ export class GraphQLEntityClient {
|
|
|
217
221
|
}
|
|
218
222
|
// === PRIVATE HELPER METHODS ===
|
|
219
223
|
formatValue(value) {
|
|
220
|
-
|
|
221
|
-
return `"${value
|
|
222
|
-
.replace(/\\/g, '\\\\')
|
|
223
|
-
.replace(/"/g, '\\"')
|
|
224
|
-
.replace(/\n/g, '\\n')
|
|
225
|
-
.replace(/\r/g, '\\r')
|
|
226
|
-
.replace(/\t/g, '\\t')}"`;
|
|
227
|
-
}
|
|
228
|
-
if (typeof value === 'boolean') {
|
|
229
|
-
return String(value);
|
|
230
|
-
}
|
|
231
|
-
if (typeof value === 'number') {
|
|
232
|
-
return String(value);
|
|
233
|
-
}
|
|
234
|
-
if (value instanceof Date) {
|
|
235
|
-
return `"${value.toISOString()}"`;
|
|
236
|
-
}
|
|
237
|
-
if (value === null || value === undefined) {
|
|
238
|
-
return 'null';
|
|
239
|
-
}
|
|
240
|
-
return `"${String(value)}"`;
|
|
224
|
+
return formatGraphQLValue(value);
|
|
241
225
|
}
|
|
242
226
|
extractId(where) {
|
|
243
227
|
return where[getPrimaryKeyField()];
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { getPrimaryKeyField } from '@microsoft/rayfin-core';
|
|
2
2
|
import { EntityNameResolver } from '@microsoft/rayfin-lib';
|
|
3
3
|
import { ResponseHandler } from './ResponseHandler';
|
|
4
|
+
import { formatGraphQLValue } from './formatValue';
|
|
4
5
|
/**
|
|
5
6
|
* Fluent GraphQL query builder for constructing and executing complex queries.
|
|
6
7
|
*
|
|
@@ -295,25 +296,7 @@ export class GraphQLQueryBuilder {
|
|
|
295
296
|
return `{ ${orderEntries.join(', ')} }`;
|
|
296
297
|
}
|
|
297
298
|
formatValue(value) {
|
|
298
|
-
|
|
299
|
-
return `"${value.replace(/"/g, '\\"')}"`;
|
|
300
|
-
}
|
|
301
|
-
if (typeof value === 'boolean') {
|
|
302
|
-
return String(value);
|
|
303
|
-
}
|
|
304
|
-
if (typeof value === 'number') {
|
|
305
|
-
return String(value);
|
|
306
|
-
}
|
|
307
|
-
if (value instanceof Date) {
|
|
308
|
-
return `"${value.toISOString()}"`;
|
|
309
|
-
}
|
|
310
|
-
if (Array.isArray(value)) {
|
|
311
|
-
return `[${value.map((v) => this.formatValue(v)).join(', ')}]`;
|
|
312
|
-
}
|
|
313
|
-
if (value === null) {
|
|
314
|
-
return 'null';
|
|
315
|
-
}
|
|
316
|
-
return `"${String(value)}"`;
|
|
299
|
+
return formatGraphQLValue(value);
|
|
317
300
|
}
|
|
318
301
|
mergeFilters(existing, additional) {
|
|
319
302
|
if (Object.keys(existing).length === 0) {
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Formats a value for inline use in a GraphQL query string.
|
|
3
|
+
* Applies proper escaping for strings (backslash, quote, newline, carriage return, tab).
|
|
4
|
+
*/
|
|
5
|
+
export declare function formatGraphQLValue(value: any): string;
|
|
6
|
+
//# sourceMappingURL=formatValue.d.ts.map
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Formats a value for inline use in a GraphQL query string.
|
|
3
|
+
* Applies proper escaping for strings (backslash, quote, newline, carriage return, tab).
|
|
4
|
+
*/
|
|
5
|
+
export function formatGraphQLValue(value) {
|
|
6
|
+
if (typeof value === 'string') {
|
|
7
|
+
return `"${value
|
|
8
|
+
.replace(/\\/g, '\\\\')
|
|
9
|
+
.replace(/"/g, '\\"')
|
|
10
|
+
.replace(/\n/g, '\\n')
|
|
11
|
+
.replace(/\r/g, '\\r')
|
|
12
|
+
.replace(/\t/g, '\\t')}"`;
|
|
13
|
+
}
|
|
14
|
+
if (typeof value === 'boolean') {
|
|
15
|
+
return String(value);
|
|
16
|
+
}
|
|
17
|
+
if (typeof value === 'number') {
|
|
18
|
+
return String(value);
|
|
19
|
+
}
|
|
20
|
+
if (value instanceof Date) {
|
|
21
|
+
return `"${value.toISOString()}"`;
|
|
22
|
+
}
|
|
23
|
+
if (Array.isArray(value)) {
|
|
24
|
+
return `[${value.map((v) => formatGraphQLValue(v)).join(', ')}]`;
|
|
25
|
+
}
|
|
26
|
+
if (value === null || value === undefined) {
|
|
27
|
+
return 'null';
|
|
28
|
+
}
|
|
29
|
+
return `"${String(value)}"`;
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=formatValue.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@microsoft/rayfin-data",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.22.0",
|
|
4
4
|
"description": "Type-safe client library for Data API Builder endpoints",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -12,8 +12,8 @@
|
|
|
12
12
|
"LICENSE"
|
|
13
13
|
],
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@microsoft/rayfin-core": "1.
|
|
16
|
-
"@microsoft/rayfin-lib": "1.
|
|
15
|
+
"@microsoft/rayfin-core": "1.22.0",
|
|
16
|
+
"@microsoft/rayfin-lib": "1.22.0"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
19
|
"@types/node": "^20.0.0",
|