@omnigraph/json-schema 1.0.0-alpha-20230424111644-b7c761da0 → 1.0.0-alpha-20230522105300-fe9c79867
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/cjs/addRootFieldResolver.js +1 -1
- package/cjs/directives.js +9 -2
- package/cjs/getComposerFromJSONSchema.js +17 -9
- package/cjs/getTypeResolverFromOutputTCs.js +23 -2
- package/cjs/getUnionTypeComposers.js +6 -1
- package/esm/addRootFieldResolver.js +1 -1
- package/esm/directives.js +9 -2
- package/esm/getComposerFromJSONSchema.js +17 -9
- package/esm/getTypeResolverFromOutputTCs.js +24 -3
- package/esm/getUnionTypeComposers.js +7 -2
- package/package.json +7 -7
|
@@ -58,7 +58,7 @@ function addHTTPRootFieldResolver(schema, field, logger, globalFetch, { path, op
|
|
|
58
58
|
headers,
|
|
59
59
|
};
|
|
60
60
|
if (timeout) {
|
|
61
|
-
requestInit.signal =
|
|
61
|
+
requestInit.signal = AbortSignal.timeout(timeout);
|
|
62
62
|
}
|
|
63
63
|
// Handle binary data
|
|
64
64
|
if (isBinary) {
|
package/cjs/directives.js
CHANGED
|
@@ -64,8 +64,11 @@ exports.ResolveRootDirective = new graphql_1.GraphQLDirective({
|
|
|
64
64
|
name: 'resolveRoot',
|
|
65
65
|
locations: [graphql_1.DirectiveLocation.FIELD_DEFINITION],
|
|
66
66
|
});
|
|
67
|
+
function rootResolver(root) {
|
|
68
|
+
return root;
|
|
69
|
+
}
|
|
67
70
|
function processResolveRootAnnotations(field) {
|
|
68
|
-
field.resolve =
|
|
71
|
+
field.resolve = rootResolver;
|
|
69
72
|
}
|
|
70
73
|
exports.processResolveRootAnnotations = processResolveRootAnnotations;
|
|
71
74
|
exports.ResolveRootFieldDirective = new graphql_1.GraphQLDirective({
|
|
@@ -560,7 +563,11 @@ exports.EnumDirective = new graphql_1.GraphQLDirective({
|
|
|
560
563
|
});
|
|
561
564
|
exports.OneOfDirective = new graphql_1.GraphQLDirective({
|
|
562
565
|
name: 'oneOf',
|
|
563
|
-
locations: [
|
|
566
|
+
locations: [
|
|
567
|
+
graphql_1.DirectiveLocation.OBJECT,
|
|
568
|
+
graphql_1.DirectiveLocation.INTERFACE,
|
|
569
|
+
graphql_1.DirectiveLocation.INPUT_OBJECT,
|
|
570
|
+
],
|
|
564
571
|
});
|
|
565
572
|
exports.ExampleDirective = new graphql_1.GraphQLDirective({
|
|
566
573
|
name: 'example',
|
|
@@ -605,15 +605,23 @@ function getComposerFromJSONSchema(schema, logger) {
|
|
|
605
605
|
...subSchema,
|
|
606
606
|
};
|
|
607
607
|
case 'Query':
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
608
|
+
if (path === '/properties/query') {
|
|
609
|
+
return {
|
|
610
|
+
output: schemaComposer.Query,
|
|
611
|
+
...subSchema,
|
|
612
|
+
};
|
|
613
|
+
}
|
|
614
|
+
subSchema.title += '_';
|
|
615
|
+
break;
|
|
612
616
|
case 'Mutation':
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
+
if (path === '/properties/mutation') {
|
|
618
|
+
return {
|
|
619
|
+
output: schemaComposer.Mutation,
|
|
620
|
+
...subSchema,
|
|
621
|
+
};
|
|
622
|
+
}
|
|
623
|
+
subSchema.title += '_';
|
|
624
|
+
break;
|
|
617
625
|
case 'Subscription':
|
|
618
626
|
if (path === '/properties/subscription') {
|
|
619
627
|
return {
|
|
@@ -621,7 +629,7 @@ function getComposerFromJSONSchema(schema, logger) {
|
|
|
621
629
|
...subSchema,
|
|
622
630
|
};
|
|
623
631
|
}
|
|
624
|
-
subSchema.title
|
|
632
|
+
subSchema.title += '_';
|
|
625
633
|
break;
|
|
626
634
|
}
|
|
627
635
|
}
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.getTypeResolverFromOutputTCs = void 0;
|
|
4
4
|
const utils_1 = require("@graphql-tools/utils");
|
|
5
5
|
function getTypeResolverFromOutputTCs({ possibleTypes, discriminatorField, discriminatorMapping, statusCodeTypeNameMap, }) {
|
|
6
|
-
return function resolveType(data) {
|
|
6
|
+
return function resolveType(data, _ctx, info) {
|
|
7
7
|
if (data.__typename) {
|
|
8
8
|
return data.__typename;
|
|
9
9
|
}
|
|
@@ -17,8 +17,29 @@ function getTypeResolverFromOutputTCs({ possibleTypes, discriminatorField, discr
|
|
|
17
17
|
return typeName;
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
|
+
const dataTypeOf = typeof data;
|
|
21
|
+
if (dataTypeOf !== 'object') {
|
|
22
|
+
for (const possibleType of possibleTypes) {
|
|
23
|
+
const fieldMap = possibleType.getFields();
|
|
24
|
+
const fields = Object.values(fieldMap);
|
|
25
|
+
if (fields.length === 1) {
|
|
26
|
+
const field = fields[0];
|
|
27
|
+
const directiveObjs = (0, utils_1.getDirective)(info.schema, field, 'resolveRoot');
|
|
28
|
+
if (directiveObjs === null || directiveObjs === void 0 ? void 0 : directiveObjs.length) {
|
|
29
|
+
const fieldType = field.type;
|
|
30
|
+
if ('parseValue' in fieldType) {
|
|
31
|
+
try {
|
|
32
|
+
fieldType.parseValue(data);
|
|
33
|
+
return possibleType.name;
|
|
34
|
+
}
|
|
35
|
+
catch (e) { }
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
20
41
|
// const validationErrors: Record<string, ErrorObject[]> = {};
|
|
21
|
-
const dataKeys =
|
|
42
|
+
const dataKeys = dataTypeOf
|
|
22
43
|
? Object.keys(data)
|
|
23
44
|
// Remove metadata fields used to pass data
|
|
24
45
|
.filter(property => !property.toString().startsWith('$'))
|
|
@@ -5,10 +5,15 @@ const graphql_compose_1 = require("graphql-compose");
|
|
|
5
5
|
const directives_js_1 = require("./directives.js");
|
|
6
6
|
function getContainerTC(schemaComposer, output) {
|
|
7
7
|
const containerTypeName = `${output.getTypeName()}_container`;
|
|
8
|
+
schemaComposer.addDirective(directives_js_1.ResolveRootDirective);
|
|
8
9
|
return schemaComposer.getOrCreateOTC(containerTypeName, otc => otc.addFields({
|
|
9
10
|
[output.getTypeName()]: {
|
|
10
11
|
type: output,
|
|
11
|
-
|
|
12
|
+
directives: [
|
|
13
|
+
{
|
|
14
|
+
name: 'resolveRoot',
|
|
15
|
+
},
|
|
16
|
+
],
|
|
12
17
|
},
|
|
13
18
|
}));
|
|
14
19
|
}
|
|
@@ -6,7 +6,7 @@ import { process } from '@graphql-mesh/cross-helpers';
|
|
|
6
6
|
import { stringInterpolator } from '@graphql-mesh/string-interpolation';
|
|
7
7
|
import { getHeadersObj } from '@graphql-mesh/utils';
|
|
8
8
|
import { createGraphQLError, memoize1 } from '@graphql-tools/utils';
|
|
9
|
-
import {
|
|
9
|
+
import { Blob, File, FormData } from '@whatwg-node/fetch';
|
|
10
10
|
import { resolveDataByUnionInputType } from './resolveDataByUnionInputType.js';
|
|
11
11
|
import { isFileUpload } from './utils.js';
|
|
12
12
|
const isListTypeOrNonNullListType = memoize1(function isListTypeOrNonNullListType(type) {
|
package/esm/directives.js
CHANGED
|
@@ -59,8 +59,11 @@ export const ResolveRootDirective = new GraphQLDirective({
|
|
|
59
59
|
name: 'resolveRoot',
|
|
60
60
|
locations: [DirectiveLocation.FIELD_DEFINITION],
|
|
61
61
|
});
|
|
62
|
+
function rootResolver(root) {
|
|
63
|
+
return root;
|
|
64
|
+
}
|
|
62
65
|
export function processResolveRootAnnotations(field) {
|
|
63
|
-
field.resolve =
|
|
66
|
+
field.resolve = rootResolver;
|
|
64
67
|
}
|
|
65
68
|
export const ResolveRootFieldDirective = new GraphQLDirective({
|
|
66
69
|
name: 'resolveRootField',
|
|
@@ -545,7 +548,11 @@ export const EnumDirective = new GraphQLDirective({
|
|
|
545
548
|
});
|
|
546
549
|
export const OneOfDirective = new GraphQLDirective({
|
|
547
550
|
name: 'oneOf',
|
|
548
|
-
locations: [
|
|
551
|
+
locations: [
|
|
552
|
+
DirectiveLocation.OBJECT,
|
|
553
|
+
DirectiveLocation.INTERFACE,
|
|
554
|
+
DirectiveLocation.INPUT_OBJECT,
|
|
555
|
+
],
|
|
549
556
|
});
|
|
550
557
|
export const ExampleDirective = new GraphQLDirective({
|
|
551
558
|
name: 'example',
|
|
@@ -602,15 +602,23 @@ export function getComposerFromJSONSchema(schema, logger) {
|
|
|
602
602
|
...subSchema,
|
|
603
603
|
};
|
|
604
604
|
case 'Query':
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
605
|
+
if (path === '/properties/query') {
|
|
606
|
+
return {
|
|
607
|
+
output: schemaComposer.Query,
|
|
608
|
+
...subSchema,
|
|
609
|
+
};
|
|
610
|
+
}
|
|
611
|
+
subSchema.title += '_';
|
|
612
|
+
break;
|
|
609
613
|
case 'Mutation':
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
+
if (path === '/properties/mutation') {
|
|
615
|
+
return {
|
|
616
|
+
output: schemaComposer.Mutation,
|
|
617
|
+
...subSchema,
|
|
618
|
+
};
|
|
619
|
+
}
|
|
620
|
+
subSchema.title += '_';
|
|
621
|
+
break;
|
|
614
622
|
case 'Subscription':
|
|
615
623
|
if (path === '/properties/subscription') {
|
|
616
624
|
return {
|
|
@@ -618,7 +626,7 @@ export function getComposerFromJSONSchema(schema, logger) {
|
|
|
618
626
|
...subSchema,
|
|
619
627
|
};
|
|
620
628
|
}
|
|
621
|
-
subSchema.title
|
|
629
|
+
subSchema.title += '_';
|
|
622
630
|
break;
|
|
623
631
|
}
|
|
624
632
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { createGraphQLError } from '@graphql-tools/utils';
|
|
1
|
+
import { createGraphQLError, getDirective } from '@graphql-tools/utils';
|
|
2
2
|
export function getTypeResolverFromOutputTCs({ possibleTypes, discriminatorField, discriminatorMapping, statusCodeTypeNameMap, }) {
|
|
3
|
-
return function resolveType(data) {
|
|
3
|
+
return function resolveType(data, _ctx, info) {
|
|
4
4
|
if (data.__typename) {
|
|
5
5
|
return data.__typename;
|
|
6
6
|
}
|
|
@@ -14,8 +14,29 @@ export function getTypeResolverFromOutputTCs({ possibleTypes, discriminatorField
|
|
|
14
14
|
return typeName;
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
|
+
const dataTypeOf = typeof data;
|
|
18
|
+
if (dataTypeOf !== 'object') {
|
|
19
|
+
for (const possibleType of possibleTypes) {
|
|
20
|
+
const fieldMap = possibleType.getFields();
|
|
21
|
+
const fields = Object.values(fieldMap);
|
|
22
|
+
if (fields.length === 1) {
|
|
23
|
+
const field = fields[0];
|
|
24
|
+
const directiveObjs = getDirective(info.schema, field, 'resolveRoot');
|
|
25
|
+
if (directiveObjs === null || directiveObjs === void 0 ? void 0 : directiveObjs.length) {
|
|
26
|
+
const fieldType = field.type;
|
|
27
|
+
if ('parseValue' in fieldType) {
|
|
28
|
+
try {
|
|
29
|
+
fieldType.parseValue(data);
|
|
30
|
+
return possibleType.name;
|
|
31
|
+
}
|
|
32
|
+
catch (e) { }
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
17
38
|
// const validationErrors: Record<string, ErrorObject[]> = {};
|
|
18
|
-
const dataKeys =
|
|
39
|
+
const dataKeys = dataTypeOf
|
|
19
40
|
? Object.keys(data)
|
|
20
41
|
// Remove metadata fields used to pass data
|
|
21
42
|
.filter(property => !property.toString().startsWith('$'))
|
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
import { isSomeInputTypeComposer, } from 'graphql-compose';
|
|
2
|
-
import { StatusCodeTypeNameDirective } from './directives.js';
|
|
2
|
+
import { ResolveRootDirective, StatusCodeTypeNameDirective } from './directives.js';
|
|
3
3
|
export function getContainerTC(schemaComposer, output) {
|
|
4
4
|
const containerTypeName = `${output.getTypeName()}_container`;
|
|
5
|
+
schemaComposer.addDirective(ResolveRootDirective);
|
|
5
6
|
return schemaComposer.getOrCreateOTC(containerTypeName, otc => otc.addFields({
|
|
6
7
|
[output.getTypeName()]: {
|
|
7
8
|
type: output,
|
|
8
|
-
|
|
9
|
+
directives: [
|
|
10
|
+
{
|
|
11
|
+
name: 'resolveRoot',
|
|
12
|
+
},
|
|
13
|
+
],
|
|
9
14
|
},
|
|
10
15
|
}));
|
|
11
16
|
}
|
package/package.json
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@omnigraph/json-schema",
|
|
3
|
-
"version": "1.0.0-alpha-
|
|
3
|
+
"version": "1.0.0-alpha-20230522105300-fe9c79867",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"peerDependencies": {
|
|
6
|
-
"@graphql-mesh/cross-helpers": "
|
|
7
|
-
"@graphql-mesh/types": "1.0.0-alpha-
|
|
8
|
-
"@graphql-mesh/utils": "1.0.0-alpha-
|
|
6
|
+
"@graphql-mesh/cross-helpers": "0.4.0-alpha-20230522105300-fe9c79867",
|
|
7
|
+
"@graphql-mesh/types": "1.0.0-alpha-20230522105300-fe9c79867",
|
|
8
|
+
"@graphql-mesh/utils": "1.0.0-alpha-20230522105300-fe9c79867",
|
|
9
9
|
"@graphql-tools/utils": "^9.2.1",
|
|
10
10
|
"graphql": "*",
|
|
11
11
|
"tslib": "^2.4.0"
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@graphql-mesh/string-interpolation": "0.
|
|
14
|
+
"@graphql-mesh/string-interpolation": "0.5.0-alpha-20230522105300-fe9c79867",
|
|
15
15
|
"@json-schema-tools/meta-schema": "1.7.0",
|
|
16
16
|
"@whatwg-node/fetch": "^0.8.3",
|
|
17
17
|
"ajv": "8.12.0",
|
|
@@ -19,9 +19,9 @@
|
|
|
19
19
|
"dset": "3.1.2",
|
|
20
20
|
"graphql-compose": "9.0.10",
|
|
21
21
|
"graphql-scalars": "^1.20.4",
|
|
22
|
-
"json-machete": "1.0.0-alpha-
|
|
22
|
+
"json-machete": "1.0.0-alpha-20230522105300-fe9c79867",
|
|
23
23
|
"pascal-case": "3.1.2",
|
|
24
|
-
"qs": "6.11.
|
|
24
|
+
"qs": "6.11.2",
|
|
25
25
|
"to-json-schema": "0.2.5",
|
|
26
26
|
"url-join": "4.0.1"
|
|
27
27
|
},
|