@orion-js/graphql 4.0.10 → 4.0.11
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/index.cjs +56 -43
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +79 -62
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
package/dist/index.js
CHANGED
|
@@ -264,8 +264,8 @@ import { GraphQLObjectType as GraphQLObjectType2 } from "graphql";
|
|
|
264
264
|
import { GraphQLList as GraphQLList2, GraphQLObjectType } from "graphql";
|
|
265
265
|
import {
|
|
266
266
|
getFieldType as getFieldType2,
|
|
267
|
-
getSchemaWithMetadataFromAnyOrionForm,
|
|
268
|
-
isSchemaLike
|
|
267
|
+
getSchemaWithMetadataFromAnyOrionForm as getSchemaWithMetadataFromAnyOrionForm2,
|
|
268
|
+
isSchemaLike as isSchemaLike2
|
|
269
269
|
} from "@orion-js/schema";
|
|
270
270
|
|
|
271
271
|
// ../../node_modules/.pnpm/rambdax@11.3.1/node_modules/rambdax/src/type.js
|
|
@@ -567,8 +567,12 @@ function getScalar_default(fieldType) {
|
|
|
567
567
|
}
|
|
568
568
|
|
|
569
569
|
// src/buildSchema/getArgs/getField.ts
|
|
570
|
-
import {
|
|
571
|
-
import {
|
|
570
|
+
import { GraphQLInputObjectType, GraphQLList } from "graphql";
|
|
571
|
+
import {
|
|
572
|
+
getFieldType,
|
|
573
|
+
getSchemaWithMetadataFromAnyOrionForm,
|
|
574
|
+
isSchemaLike
|
|
575
|
+
} from "@orion-js/schema";
|
|
572
576
|
|
|
573
577
|
// src/resolversSchemas/getStaticFields.ts
|
|
574
578
|
function getStaticFields(schema) {
|
|
@@ -587,54 +591,70 @@ function getStaticFields(schema) {
|
|
|
587
591
|
}
|
|
588
592
|
|
|
589
593
|
// src/buildSchema/getArgs/getField.ts
|
|
590
|
-
|
|
591
|
-
var
|
|
592
|
-
var getCachedModelInput = (model, fields) => {
|
|
593
|
-
if (!storedModelInput[model.name]) {
|
|
594
|
-
storedModelInput[model.name] = new GraphQLInputObjectType({
|
|
595
|
-
name: `${model.name}Input`,
|
|
596
|
-
fields
|
|
597
|
-
});
|
|
598
|
-
}
|
|
599
|
-
return storedModelInput[model.name];
|
|
600
|
-
};
|
|
601
|
-
var resolveModelFields = (model) => {
|
|
602
|
-
const fields = {};
|
|
603
|
-
for (const field of getStaticFields(model)) {
|
|
604
|
-
fields[field.key] = { type: resolveType(field.type) };
|
|
605
|
-
}
|
|
606
|
-
return fields;
|
|
607
|
-
};
|
|
608
|
-
var resolveArrayType = (type2) => new GraphQLList(resolveType(type2[0]));
|
|
609
|
-
var resolvePlainObjectOrModelType = (type2) => {
|
|
610
|
-
const model = getSchemaFromAnyOrionForm2(type2);
|
|
611
|
-
const fields = resolveModelFields(model);
|
|
612
|
-
return getCachedModelInput(model, fields);
|
|
613
|
-
};
|
|
614
|
-
var resolveType = (type2) => {
|
|
594
|
+
var registeredGraphQLTypes = /* @__PURE__ */ new Map();
|
|
595
|
+
var resolveType = (type2, options) => {
|
|
615
596
|
var _a;
|
|
616
597
|
if (!type2) throw new Error("No type specified");
|
|
617
598
|
if ((_a = type2 == null ? void 0 : type2[Symbol.metadata]) == null ? void 0 : _a._getModel) {
|
|
618
599
|
const model = type2[Symbol.metadata]._getModel();
|
|
619
|
-
return resolveType(model);
|
|
600
|
+
return resolveType(model, options);
|
|
620
601
|
}
|
|
621
|
-
if (Array.isArray(type2))
|
|
622
|
-
|
|
623
|
-
|
|
602
|
+
if (Array.isArray(type2)) {
|
|
603
|
+
return new GraphQLList(resolveType(type2[0], options));
|
|
604
|
+
}
|
|
605
|
+
if (isSchemaLike(type2)) {
|
|
606
|
+
const schema = getSchemaWithMetadataFromAnyOrionForm(type2);
|
|
607
|
+
const modelName = `${schema.__modelName}Input`;
|
|
608
|
+
if (schema.__graphQLType) {
|
|
609
|
+
return schema.__graphQLType;
|
|
610
|
+
}
|
|
611
|
+
if (!schema.__modelName) {
|
|
612
|
+
throw new Error(
|
|
613
|
+
`Schema name is not defined. Register a name with schemaWithName. Schema: ${JSON.stringify(schema)}`
|
|
614
|
+
);
|
|
615
|
+
}
|
|
616
|
+
if (registeredGraphQLTypes.has(modelName)) {
|
|
617
|
+
const { graphQLType: graphQLType2, schema: registeredSchema } = registeredGraphQLTypes.get(modelName);
|
|
618
|
+
if (equals(registeredSchema, schema)) {
|
|
619
|
+
return graphQLType2;
|
|
620
|
+
}
|
|
621
|
+
throw new Error(`Schema named "${modelName}" already registered`);
|
|
622
|
+
}
|
|
623
|
+
const graphQLType = createGraphQLInputType(modelName, schema, options);
|
|
624
|
+
registeredGraphQLTypes.set(modelName, { schema, graphQLType });
|
|
625
|
+
return graphQLType;
|
|
624
626
|
}
|
|
625
627
|
const schemaType = getFieldType(type2);
|
|
626
628
|
return getScalar_default(schemaType);
|
|
627
629
|
};
|
|
628
630
|
var getField_default = resolveType;
|
|
631
|
+
var createGraphQLInputType = (modelName, schema, options) => new GraphQLInputObjectType({
|
|
632
|
+
name: modelName,
|
|
633
|
+
fields: () => buildFields(schema, options)
|
|
634
|
+
});
|
|
635
|
+
var buildFields = (schema, options) => {
|
|
636
|
+
const fields = {};
|
|
637
|
+
const addStaticFields = () => {
|
|
638
|
+
for (const field of getStaticFields(schema)) {
|
|
639
|
+
try {
|
|
640
|
+
fields[field.key] = { type: resolveType(field.type, options) };
|
|
641
|
+
} catch (error) {
|
|
642
|
+
throw new Error(`Error getting type for ${field.key}: ${error.message}`);
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
};
|
|
646
|
+
addStaticFields();
|
|
647
|
+
return fields;
|
|
648
|
+
};
|
|
629
649
|
|
|
630
650
|
// src/buildSchema/getArgs/index.ts
|
|
631
|
-
async function getArgs_default(params) {
|
|
651
|
+
async function getArgs_default(params, options) {
|
|
632
652
|
if (!params) return;
|
|
633
653
|
if (Object.keys(params).length === 0) return;
|
|
634
654
|
const fields = {};
|
|
635
655
|
for (const key of Object.keys(params).filter((key2) => !key2.startsWith("__"))) {
|
|
636
656
|
try {
|
|
637
|
-
const type2 = getField_default(params[key].type);
|
|
657
|
+
const type2 = getField_default(params[key].type, options);
|
|
638
658
|
fields[key] = { type: type2 };
|
|
639
659
|
} catch (error) {
|
|
640
660
|
throw new Error(`Error creating GraphQL resolver params argument ${key}: ${error.message}`);
|
|
@@ -678,7 +698,7 @@ function errorHandler(error, data) {
|
|
|
678
698
|
// src/buildSchema/getType/getTypeAsResolver.ts
|
|
679
699
|
function getTypeAsResolver_default({ resolver, getGraphQLType: getGraphQLType2, options, schema }) {
|
|
680
700
|
const type2 = getGraphQLType2(resolver.returns, options);
|
|
681
|
-
const args = getArgs_default(resolver.params);
|
|
701
|
+
const args = getArgs_default(resolver.params, options);
|
|
682
702
|
return {
|
|
683
703
|
type: type2,
|
|
684
704
|
args,
|
|
@@ -736,9 +756,9 @@ function getModelLoadedResolvers(schema, options) {
|
|
|
736
756
|
// src/buildSchema/getType/index.ts
|
|
737
757
|
var createGraphQLObjectType = (modelName, schema, options) => new GraphQLObjectType({
|
|
738
758
|
name: modelName,
|
|
739
|
-
fields: () =>
|
|
759
|
+
fields: () => buildFields2(schema, options)
|
|
740
760
|
});
|
|
741
|
-
var
|
|
761
|
+
var buildFields2 = (schema, options) => {
|
|
742
762
|
const fields = {};
|
|
743
763
|
const addStaticFields = () => {
|
|
744
764
|
for (const field of getStaticFields(schema)) {
|
|
@@ -776,14 +796,14 @@ var buildFields = (schema, options) => {
|
|
|
776
796
|
addModelLoadedResolvers();
|
|
777
797
|
return fields;
|
|
778
798
|
};
|
|
779
|
-
var
|
|
799
|
+
var registeredGraphQLTypes2 = /* @__PURE__ */ new Map();
|
|
780
800
|
function getGraphQLType(type2, options) {
|
|
781
801
|
if (!type2) throw new Error("Type is undefined");
|
|
782
802
|
if (Array.isArray(type2)) {
|
|
783
803
|
return new GraphQLList2(getGraphQLType(type2[0], options));
|
|
784
804
|
}
|
|
785
|
-
if (
|
|
786
|
-
const schema =
|
|
805
|
+
if (isSchemaLike2(type2)) {
|
|
806
|
+
const schema = getSchemaWithMetadataFromAnyOrionForm2(type2);
|
|
787
807
|
const modelName = schema.__modelName;
|
|
788
808
|
if (schema.__graphQLType) {
|
|
789
809
|
return schema.__graphQLType;
|
|
@@ -793,15 +813,15 @@ function getGraphQLType(type2, options) {
|
|
|
793
813
|
`Schema name is not defined. Register a name with schemaWithName. Schema: ${JSON.stringify(schema)}`
|
|
794
814
|
);
|
|
795
815
|
}
|
|
796
|
-
if (
|
|
797
|
-
const { graphQLType: graphQLType2, schema: registeredSchema } =
|
|
816
|
+
if (registeredGraphQLTypes2.has(modelName)) {
|
|
817
|
+
const { graphQLType: graphQLType2, schema: registeredSchema } = registeredGraphQLTypes2.get(modelName);
|
|
798
818
|
if (equals(registeredSchema, schema)) {
|
|
799
819
|
return graphQLType2;
|
|
800
820
|
}
|
|
801
821
|
throw new Error(`Schema named "${modelName}" already registered`);
|
|
802
822
|
}
|
|
803
823
|
const graphQLType = createGraphQLObjectType(modelName, schema, options);
|
|
804
|
-
|
|
824
|
+
registeredGraphQLTypes2.set(modelName, { schema, graphQLType });
|
|
805
825
|
return graphQLType;
|
|
806
826
|
}
|
|
807
827
|
return getScalar_default(getFieldType2(type2));
|
|
@@ -823,7 +843,7 @@ async function getResolvers_default(options, mutation) {
|
|
|
823
843
|
for (const { resolver, name } of filteredResolvers) {
|
|
824
844
|
resolversStore[name] = resolver;
|
|
825
845
|
const type2 = await getGraphQLType(resolver.returns, options);
|
|
826
|
-
const args = await getArgs_default(resolver.params);
|
|
846
|
+
const args = await getArgs_default(resolver.params, options);
|
|
827
847
|
fields[name] = {
|
|
828
848
|
type: type2,
|
|
829
849
|
args,
|
|
@@ -873,7 +893,7 @@ async function getSubscriptions_default(options) {
|
|
|
873
893
|
const subscription = subscriptions[key];
|
|
874
894
|
subscription.name = subscription.name || key;
|
|
875
895
|
const type2 = await getGraphQLType(subscription.returns, options);
|
|
876
|
-
const args = await getArgs_default(subscription.params);
|
|
896
|
+
const args = await getArgs_default(subscription.params, options);
|
|
877
897
|
fields[subscription.name] = {
|
|
878
898
|
type: type2,
|
|
879
899
|
args,
|
|
@@ -1056,13 +1076,13 @@ var ResolverParamsInfo_default = schemaWithName("ResolverParams", {
|
|
|
1056
1076
|
});
|
|
1057
1077
|
|
|
1058
1078
|
// src/resolversSchemas/serializeSchema.ts
|
|
1059
|
-
import { getSchemaFromAnyOrionForm as
|
|
1079
|
+
import { getSchemaFromAnyOrionForm as getSchemaFromAnyOrionForm2 } from "@orion-js/schema";
|
|
1060
1080
|
|
|
1061
1081
|
// src/resolversSchemas/getField.ts
|
|
1062
1082
|
import {
|
|
1063
1083
|
getFieldType as getFieldType3,
|
|
1064
|
-
getSchemaWithMetadataFromAnyOrionForm as
|
|
1065
|
-
isSchemaLike as
|
|
1084
|
+
getSchemaWithMetadataFromAnyOrionForm as getSchemaWithMetadataFromAnyOrionForm3,
|
|
1085
|
+
isSchemaLike as isSchemaLike3
|
|
1066
1086
|
} from "@orion-js/schema";
|
|
1067
1087
|
async function getParams(field) {
|
|
1068
1088
|
const { type: type2 } = field;
|
|
@@ -1074,9 +1094,9 @@ async function getParams(field) {
|
|
|
1074
1094
|
__graphQLType: `[${serialized.__graphQLType}]`
|
|
1075
1095
|
};
|
|
1076
1096
|
}
|
|
1077
|
-
const isSchema =
|
|
1097
|
+
const isSchema = isSchemaLike3(type2);
|
|
1078
1098
|
if (isSchema) {
|
|
1079
|
-
const schemaOfType =
|
|
1099
|
+
const schemaOfType = getSchemaWithMetadataFromAnyOrionForm3(type2);
|
|
1080
1100
|
const modelName = schemaOfType.__modelName;
|
|
1081
1101
|
if (!modelName) {
|
|
1082
1102
|
throw new Error("The schema needs a model name to be serialized for GraphQL");
|
|
@@ -1104,24 +1124,21 @@ async function getParams(field) {
|
|
|
1104
1124
|
// src/resolversSchemas/serializeSchema.ts
|
|
1105
1125
|
async function serializeSchema(params) {
|
|
1106
1126
|
if (!params) return;
|
|
1107
|
-
const schema =
|
|
1127
|
+
const schema = getSchemaFromAnyOrionForm2(params);
|
|
1108
1128
|
if (Object.keys(schema).length === 0) return;
|
|
1109
1129
|
const fields = {};
|
|
1110
|
-
console.log(schema, "schema");
|
|
1111
1130
|
for (const key of Object.keys(schema).filter((key2) => !key2.startsWith("__"))) {
|
|
1112
1131
|
const field = schema[key];
|
|
1113
1132
|
fields[key] = await getParams(field);
|
|
1114
|
-
console.log(fields[key], field);
|
|
1115
1133
|
}
|
|
1116
|
-
console.log(fields, "fields");
|
|
1117
1134
|
return fields;
|
|
1118
1135
|
}
|
|
1119
1136
|
|
|
1120
1137
|
// src/resolversSchemas/params.ts
|
|
1121
|
-
import { getSchemaFromAnyOrionForm as
|
|
1138
|
+
import { getSchemaFromAnyOrionForm as getSchemaFromAnyOrionForm4, isSchemaLike as isSchemaLike5 } from "@orion-js/schema";
|
|
1122
1139
|
|
|
1123
1140
|
// src/resolversSchemas/getBasicResultQuery.ts
|
|
1124
|
-
import { getSchemaFromAnyOrionForm as
|
|
1141
|
+
import { getSchemaFromAnyOrionForm as getSchemaFromAnyOrionForm3, isSchemaLike as isSchemaLike4 } from "@orion-js/schema";
|
|
1125
1142
|
async function getBasicQuery(field) {
|
|
1126
1143
|
if (!field.type) return "";
|
|
1127
1144
|
if (Array.isArray(field.type)) {
|
|
@@ -1130,10 +1147,10 @@ async function getBasicQuery(field) {
|
|
|
1130
1147
|
type: field.type[0]
|
|
1131
1148
|
});
|
|
1132
1149
|
}
|
|
1133
|
-
if (!
|
|
1150
|
+
if (!isSchemaLike4(field.type)) {
|
|
1134
1151
|
return field.key;
|
|
1135
1152
|
}
|
|
1136
|
-
const schema =
|
|
1153
|
+
const schema = getSchemaFromAnyOrionForm3(field.type);
|
|
1137
1154
|
const fields = [];
|
|
1138
1155
|
for (const field2 of getStaticFields(schema)) {
|
|
1139
1156
|
fields.push(await getBasicQuery(field2));
|
|
@@ -1145,14 +1162,14 @@ async function getBasicQuery(field) {
|
|
|
1145
1162
|
// src/resolversSchemas/params.ts
|
|
1146
1163
|
function getResultTypeName(type2) {
|
|
1147
1164
|
const returns = Array.isArray(type2) ? type2[0] : type2;
|
|
1148
|
-
const schema =
|
|
1165
|
+
const schema = getSchemaFromAnyOrionForm4(returns);
|
|
1149
1166
|
if (schema == null ? void 0 : schema.__modelName) return schema.__modelName;
|
|
1150
1167
|
return;
|
|
1151
1168
|
}
|
|
1152
1169
|
async function getInternalBasicResultQuery(type2) {
|
|
1153
1170
|
const returns = Array.isArray(type2) ? type2[0] : type2;
|
|
1154
|
-
if (
|
|
1155
|
-
const schema =
|
|
1171
|
+
if (isSchemaLike5(returns)) {
|
|
1172
|
+
const schema = getSchemaFromAnyOrionForm4(returns);
|
|
1156
1173
|
return await getBasicQuery({
|
|
1157
1174
|
type: schema
|
|
1158
1175
|
});
|