@orion-js/graphql 4.0.10 → 4.0.12
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 +5 -5
package/dist/index.cjs
CHANGED
|
@@ -648,54 +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 = (0, import_schema2.getSchemaFromAnyOrionForm)(type2);
|
|
672
|
-
const fields = resolveModelFields(model);
|
|
673
|
-
return getCachedModelInput(model, fields);
|
|
674
|
-
};
|
|
675
|
-
var resolveType = (type2) => {
|
|
651
|
+
var registeredGraphQLTypes = /* @__PURE__ */ new Map();
|
|
652
|
+
var resolveType = (type2, options) => {
|
|
676
653
|
var _a;
|
|
677
654
|
if (!type2) throw new Error("No type specified");
|
|
678
655
|
if ((_a = type2 == null ? void 0 : type2[Symbol.metadata]) == null ? void 0 : _a._getModel) {
|
|
679
656
|
const model = type2[Symbol.metadata]._getModel();
|
|
680
|
-
return resolveType(model);
|
|
657
|
+
return resolveType(model, options);
|
|
681
658
|
}
|
|
682
|
-
if (Array.isArray(type2))
|
|
683
|
-
|
|
684
|
-
|
|
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;
|
|
685
683
|
}
|
|
686
684
|
const schemaType = (0, import_schema2.getFieldType)(type2);
|
|
687
685
|
return getScalar_default(schemaType);
|
|
688
686
|
};
|
|
689
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
|
+
};
|
|
690
706
|
|
|
691
707
|
// src/buildSchema/getArgs/index.ts
|
|
692
|
-
async function getArgs_default(params) {
|
|
708
|
+
async function getArgs_default(params, options) {
|
|
693
709
|
if (!params) return;
|
|
694
710
|
if (Object.keys(params).length === 0) return;
|
|
695
711
|
const fields = {};
|
|
696
712
|
for (const key of Object.keys(params).filter((key2) => !key2.startsWith("__"))) {
|
|
697
713
|
try {
|
|
698
|
-
const type2 = getField_default(params[key].type);
|
|
714
|
+
const type2 = getField_default(params[key].type, options);
|
|
699
715
|
fields[key] = { type: type2 };
|
|
700
716
|
} catch (error) {
|
|
701
717
|
throw new Error(`Error creating GraphQL resolver params argument ${key}: ${error.message}`);
|
|
@@ -739,7 +755,7 @@ function errorHandler(error, data) {
|
|
|
739
755
|
// src/buildSchema/getType/getTypeAsResolver.ts
|
|
740
756
|
function getTypeAsResolver_default({ resolver, getGraphQLType: getGraphQLType2, options, schema }) {
|
|
741
757
|
const type2 = getGraphQLType2(resolver.returns, options);
|
|
742
|
-
const args = getArgs_default(resolver.params);
|
|
758
|
+
const args = getArgs_default(resolver.params, options);
|
|
743
759
|
return {
|
|
744
760
|
type: type2,
|
|
745
761
|
args,
|
|
@@ -797,9 +813,9 @@ function getModelLoadedResolvers(schema, options) {
|
|
|
797
813
|
// src/buildSchema/getType/index.ts
|
|
798
814
|
var createGraphQLObjectType = (modelName, schema, options) => new import_graphql6.GraphQLObjectType({
|
|
799
815
|
name: modelName,
|
|
800
|
-
fields: () =>
|
|
816
|
+
fields: () => buildFields2(schema, options)
|
|
801
817
|
});
|
|
802
|
-
var
|
|
818
|
+
var buildFields2 = (schema, options) => {
|
|
803
819
|
const fields = {};
|
|
804
820
|
const addStaticFields = () => {
|
|
805
821
|
for (const field of getStaticFields(schema)) {
|
|
@@ -837,7 +853,7 @@ var buildFields = (schema, options) => {
|
|
|
837
853
|
addModelLoadedResolvers();
|
|
838
854
|
return fields;
|
|
839
855
|
};
|
|
840
|
-
var
|
|
856
|
+
var registeredGraphQLTypes2 = /* @__PURE__ */ new Map();
|
|
841
857
|
function getGraphQLType(type2, options) {
|
|
842
858
|
if (!type2) throw new Error("Type is undefined");
|
|
843
859
|
if (Array.isArray(type2)) {
|
|
@@ -854,15 +870,15 @@ function getGraphQLType(type2, options) {
|
|
|
854
870
|
`Schema name is not defined. Register a name with schemaWithName. Schema: ${JSON.stringify(schema)}`
|
|
855
871
|
);
|
|
856
872
|
}
|
|
857
|
-
if (
|
|
858
|
-
const { graphQLType: graphQLType2, schema: registeredSchema } =
|
|
873
|
+
if (registeredGraphQLTypes2.has(modelName)) {
|
|
874
|
+
const { graphQLType: graphQLType2, schema: registeredSchema } = registeredGraphQLTypes2.get(modelName);
|
|
859
875
|
if (equals(registeredSchema, schema)) {
|
|
860
876
|
return graphQLType2;
|
|
861
877
|
}
|
|
862
878
|
throw new Error(`Schema named "${modelName}" already registered`);
|
|
863
879
|
}
|
|
864
880
|
const graphQLType = createGraphQLObjectType(modelName, schema, options);
|
|
865
|
-
|
|
881
|
+
registeredGraphQLTypes2.set(modelName, { schema, graphQLType });
|
|
866
882
|
return graphQLType;
|
|
867
883
|
}
|
|
868
884
|
return getScalar_default((0, import_schema3.getFieldType)(type2));
|
|
@@ -884,7 +900,7 @@ async function getResolvers_default(options, mutation) {
|
|
|
884
900
|
for (const { resolver, name } of filteredResolvers) {
|
|
885
901
|
resolversStore[name] = resolver;
|
|
886
902
|
const type2 = await getGraphQLType(resolver.returns, options);
|
|
887
|
-
const args = await getArgs_default(resolver.params);
|
|
903
|
+
const args = await getArgs_default(resolver.params, options);
|
|
888
904
|
fields[name] = {
|
|
889
905
|
type: type2,
|
|
890
906
|
args,
|
|
@@ -934,7 +950,7 @@ async function getSubscriptions_default(options) {
|
|
|
934
950
|
const subscription = subscriptions[key];
|
|
935
951
|
subscription.name = subscription.name || key;
|
|
936
952
|
const type2 = await getGraphQLType(subscription.returns, options);
|
|
937
|
-
const args = await getArgs_default(subscription.params);
|
|
953
|
+
const args = await getArgs_default(subscription.params, options);
|
|
938
954
|
fields[subscription.name] = {
|
|
939
955
|
type: type2,
|
|
940
956
|
args,
|
|
@@ -1164,13 +1180,10 @@ async function serializeSchema(params) {
|
|
|
1164
1180
|
const schema = (0, import_schema6.getSchemaFromAnyOrionForm)(params);
|
|
1165
1181
|
if (Object.keys(schema).length === 0) return;
|
|
1166
1182
|
const fields = {};
|
|
1167
|
-
console.log(schema, "schema");
|
|
1168
1183
|
for (const key of Object.keys(schema).filter((key2) => !key2.startsWith("__"))) {
|
|
1169
1184
|
const field = schema[key];
|
|
1170
1185
|
fields[key] = await getParams(field);
|
|
1171
|
-
console.log(fields[key], field);
|
|
1172
1186
|
}
|
|
1173
|
-
console.log(fields, "fields");
|
|
1174
1187
|
return fields;
|
|
1175
1188
|
}
|
|
1176
1189
|
|