@orion-js/graphql 4.0.9 → 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 -46
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +74 -60
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
package/dist/index.cjs
CHANGED
|
@@ -648,57 +648,70 @@ function getStaticFields(schema) {
|
|
|
648
648
|
}
|
|
649
649
|
|
|
650
650
|
// src/buildSchema/getArgs/getField.ts
|
|
651
|
-
|
|
652
|
-
var
|
|
653
|
-
var getCachedModelInput = (model, fields) => {
|
|
654
|
-
if (!storedModelInput[model.name]) {
|
|
655
|
-
storedModelInput[model.name] = new import_graphql4.GraphQLInputObjectType({
|
|
656
|
-
name: `${model.name}Input`,
|
|
657
|
-
fields
|
|
658
|
-
});
|
|
659
|
-
}
|
|
660
|
-
return storedModelInput[model.name];
|
|
661
|
-
};
|
|
662
|
-
var resolveModelFields = (model) => {
|
|
663
|
-
const fields = {};
|
|
664
|
-
for (const field of getStaticFields(model)) {
|
|
665
|
-
fields[field.key] = { type: resolveType(field.type) };
|
|
666
|
-
}
|
|
667
|
-
return fields;
|
|
668
|
-
};
|
|
669
|
-
var resolveArrayType = (type2) => new import_graphql4.GraphQLList(resolveType(type2[0]));
|
|
670
|
-
var resolvePlainObjectOrModelType = (type2) => {
|
|
671
|
-
const model = type2.__isModel ? type2 : type2.__model;
|
|
672
|
-
if (!model || !model.__isModel) {
|
|
673
|
-
throw new Error("A type is not a Model");
|
|
674
|
-
}
|
|
675
|
-
const fields = resolveModelFields(model);
|
|
676
|
-
return getCachedModelInput(model, fields);
|
|
677
|
-
};
|
|
678
|
-
var resolveType = (type2) => {
|
|
651
|
+
var registeredGraphQLTypes = /* @__PURE__ */ new Map();
|
|
652
|
+
var resolveType = (type2, options) => {
|
|
679
653
|
var _a;
|
|
680
654
|
if (!type2) throw new Error("No type specified");
|
|
681
655
|
if ((_a = type2 == null ? void 0 : type2[Symbol.metadata]) == null ? void 0 : _a._getModel) {
|
|
682
656
|
const model = type2[Symbol.metadata]._getModel();
|
|
683
|
-
return resolveType(model);
|
|
657
|
+
return resolveType(model, options);
|
|
684
658
|
}
|
|
685
|
-
if (Array.isArray(type2))
|
|
686
|
-
|
|
687
|
-
|
|
659
|
+
if (Array.isArray(type2)) {
|
|
660
|
+
return new import_graphql4.GraphQLList(resolveType(type2[0], options));
|
|
661
|
+
}
|
|
662
|
+
if ((0, import_schema2.isSchemaLike)(type2)) {
|
|
663
|
+
const schema = (0, import_schema2.getSchemaWithMetadataFromAnyOrionForm)(type2);
|
|
664
|
+
const modelName = `${schema.__modelName}Input`;
|
|
665
|
+
if (schema.__graphQLType) {
|
|
666
|
+
return schema.__graphQLType;
|
|
667
|
+
}
|
|
668
|
+
if (!schema.__modelName) {
|
|
669
|
+
throw new Error(
|
|
670
|
+
`Schema name is not defined. Register a name with schemaWithName. Schema: ${JSON.stringify(schema)}`
|
|
671
|
+
);
|
|
672
|
+
}
|
|
673
|
+
if (registeredGraphQLTypes.has(modelName)) {
|
|
674
|
+
const { graphQLType: graphQLType2, schema: registeredSchema } = registeredGraphQLTypes.get(modelName);
|
|
675
|
+
if (equals(registeredSchema, schema)) {
|
|
676
|
+
return graphQLType2;
|
|
677
|
+
}
|
|
678
|
+
throw new Error(`Schema named "${modelName}" already registered`);
|
|
679
|
+
}
|
|
680
|
+
const graphQLType = createGraphQLInputType(modelName, schema, options);
|
|
681
|
+
registeredGraphQLTypes.set(modelName, { schema, graphQLType });
|
|
682
|
+
return graphQLType;
|
|
688
683
|
}
|
|
689
684
|
const schemaType = (0, import_schema2.getFieldType)(type2);
|
|
690
685
|
return getScalar_default(schemaType);
|
|
691
686
|
};
|
|
692
687
|
var getField_default = resolveType;
|
|
688
|
+
var createGraphQLInputType = (modelName, schema, options) => new import_graphql4.GraphQLInputObjectType({
|
|
689
|
+
name: modelName,
|
|
690
|
+
fields: () => buildFields(schema, options)
|
|
691
|
+
});
|
|
692
|
+
var buildFields = (schema, options) => {
|
|
693
|
+
const fields = {};
|
|
694
|
+
const addStaticFields = () => {
|
|
695
|
+
for (const field of getStaticFields(schema)) {
|
|
696
|
+
try {
|
|
697
|
+
fields[field.key] = { type: resolveType(field.type, options) };
|
|
698
|
+
} catch (error) {
|
|
699
|
+
throw new Error(`Error getting type for ${field.key}: ${error.message}`);
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
};
|
|
703
|
+
addStaticFields();
|
|
704
|
+
return fields;
|
|
705
|
+
};
|
|
693
706
|
|
|
694
707
|
// src/buildSchema/getArgs/index.ts
|
|
695
|
-
async function getArgs_default(params) {
|
|
708
|
+
async function getArgs_default(params, options) {
|
|
696
709
|
if (!params) return;
|
|
697
710
|
if (Object.keys(params).length === 0) return;
|
|
698
711
|
const fields = {};
|
|
699
712
|
for (const key of Object.keys(params).filter((key2) => !key2.startsWith("__"))) {
|
|
700
713
|
try {
|
|
701
|
-
const type2 = getField_default(params[key].type);
|
|
714
|
+
const type2 = getField_default(params[key].type, options);
|
|
702
715
|
fields[key] = { type: type2 };
|
|
703
716
|
} catch (error) {
|
|
704
717
|
throw new Error(`Error creating GraphQL resolver params argument ${key}: ${error.message}`);
|
|
@@ -742,7 +755,7 @@ function errorHandler(error, data) {
|
|
|
742
755
|
// src/buildSchema/getType/getTypeAsResolver.ts
|
|
743
756
|
function getTypeAsResolver_default({ resolver, getGraphQLType: getGraphQLType2, options, schema }) {
|
|
744
757
|
const type2 = getGraphQLType2(resolver.returns, options);
|
|
745
|
-
const args = getArgs_default(resolver.params);
|
|
758
|
+
const args = getArgs_default(resolver.params, options);
|
|
746
759
|
return {
|
|
747
760
|
type: type2,
|
|
748
761
|
args,
|
|
@@ -800,9 +813,9 @@ function getModelLoadedResolvers(schema, options) {
|
|
|
800
813
|
// src/buildSchema/getType/index.ts
|
|
801
814
|
var createGraphQLObjectType = (modelName, schema, options) => new import_graphql6.GraphQLObjectType({
|
|
802
815
|
name: modelName,
|
|
803
|
-
fields: () =>
|
|
816
|
+
fields: () => buildFields2(schema, options)
|
|
804
817
|
});
|
|
805
|
-
var
|
|
818
|
+
var buildFields2 = (schema, options) => {
|
|
806
819
|
const fields = {};
|
|
807
820
|
const addStaticFields = () => {
|
|
808
821
|
for (const field of getStaticFields(schema)) {
|
|
@@ -840,7 +853,7 @@ var buildFields = (schema, options) => {
|
|
|
840
853
|
addModelLoadedResolvers();
|
|
841
854
|
return fields;
|
|
842
855
|
};
|
|
843
|
-
var
|
|
856
|
+
var registeredGraphQLTypes2 = /* @__PURE__ */ new Map();
|
|
844
857
|
function getGraphQLType(type2, options) {
|
|
845
858
|
if (!type2) throw new Error("Type is undefined");
|
|
846
859
|
if (Array.isArray(type2)) {
|
|
@@ -857,15 +870,15 @@ function getGraphQLType(type2, options) {
|
|
|
857
870
|
`Schema name is not defined. Register a name with schemaWithName. Schema: ${JSON.stringify(schema)}`
|
|
858
871
|
);
|
|
859
872
|
}
|
|
860
|
-
if (
|
|
861
|
-
const { graphQLType: graphQLType2, schema: registeredSchema } =
|
|
873
|
+
if (registeredGraphQLTypes2.has(modelName)) {
|
|
874
|
+
const { graphQLType: graphQLType2, schema: registeredSchema } = registeredGraphQLTypes2.get(modelName);
|
|
862
875
|
if (equals(registeredSchema, schema)) {
|
|
863
876
|
return graphQLType2;
|
|
864
877
|
}
|
|
865
878
|
throw new Error(`Schema named "${modelName}" already registered`);
|
|
866
879
|
}
|
|
867
880
|
const graphQLType = createGraphQLObjectType(modelName, schema, options);
|
|
868
|
-
|
|
881
|
+
registeredGraphQLTypes2.set(modelName, { schema, graphQLType });
|
|
869
882
|
return graphQLType;
|
|
870
883
|
}
|
|
871
884
|
return getScalar_default((0, import_schema3.getFieldType)(type2));
|
|
@@ -887,7 +900,7 @@ async function getResolvers_default(options, mutation) {
|
|
|
887
900
|
for (const { resolver, name } of filteredResolvers) {
|
|
888
901
|
resolversStore[name] = resolver;
|
|
889
902
|
const type2 = await getGraphQLType(resolver.returns, options);
|
|
890
|
-
const args = await getArgs_default(resolver.params);
|
|
903
|
+
const args = await getArgs_default(resolver.params, options);
|
|
891
904
|
fields[name] = {
|
|
892
905
|
type: type2,
|
|
893
906
|
args,
|
|
@@ -937,7 +950,7 @@ async function getSubscriptions_default(options) {
|
|
|
937
950
|
const subscription = subscriptions[key];
|
|
938
951
|
subscription.name = subscription.name || key;
|
|
939
952
|
const type2 = await getGraphQLType(subscription.returns, options);
|
|
940
|
-
const args = await getArgs_default(subscription.params);
|
|
953
|
+
const args = await getArgs_default(subscription.params, options);
|
|
941
954
|
fields[subscription.name] = {
|
|
942
955
|
type: type2,
|
|
943
956
|
args,
|
|
@@ -1167,13 +1180,10 @@ async function serializeSchema(params) {
|
|
|
1167
1180
|
const schema = (0, import_schema6.getSchemaFromAnyOrionForm)(params);
|
|
1168
1181
|
if (Object.keys(schema).length === 0) return;
|
|
1169
1182
|
const fields = {};
|
|
1170
|
-
console.log(schema, "schema");
|
|
1171
1183
|
for (const key of Object.keys(schema).filter((key2) => !key2.startsWith("__"))) {
|
|
1172
1184
|
const field = schema[key];
|
|
1173
1185
|
fields[key] = await getParams(field);
|
|
1174
|
-
console.log(fields[key], field);
|
|
1175
1186
|
}
|
|
1176
|
-
console.log(fields, "fields");
|
|
1177
1187
|
return fields;
|
|
1178
1188
|
}
|
|
1179
1189
|
|