@aws-amplify/data-schema 1.9.1 → 1.10.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.
- package/dist/cjs/{ModelRelationalField.js → ModelRelationshipField.js} +8 -5
- package/dist/cjs/ModelRelationshipField.js.map +1 -0
- package/dist/cjs/SchemaProcessor.js +34 -25
- package/dist/cjs/SchemaProcessor.js.map +1 -1
- package/dist/cjs/a.js +4 -4
- package/dist/cjs/a.js.map +1 -1
- package/dist/cjs/ai/ConversationSchemaTypes.js +6 -7
- package/dist/cjs/ai/ConversationSchemaTypes.js.map +1 -1
- package/dist/cjs/runtime/internals/APIClient.js +8 -8
- package/dist/cjs/runtime/internals/APIClient.js.map +1 -1
- package/dist/esm/Authorization.d.ts +7 -0
- package/dist/esm/ClientSchema/Core/ClientModel.d.ts +3 -3
- package/dist/esm/ClientSchema/utilities/ResolveField.d.ts +5 -5
- package/dist/esm/CustomOperation.d.ts +7 -0
- package/dist/esm/CustomType.d.ts +5 -0
- package/dist/esm/EnumType.d.ts +5 -0
- package/dist/esm/MappedTypes/ModelMetadata.d.ts +5 -5
- package/dist/esm/MappedTypes/ResolveFieldProperties.d.ts +9 -9
- package/dist/esm/MappedTypes/ResolveSchema.d.ts +3 -3
- package/dist/esm/ModelField.d.ts +5 -0
- package/dist/esm/{ModelRelationalField.d.ts → ModelRelationshipField.d.ts} +31 -14
- package/dist/esm/{ModelRelationalField.mjs → ModelRelationshipField.mjs} +8 -5
- package/dist/esm/ModelRelationshipField.mjs.map +1 -0
- package/dist/esm/ModelSchema.d.ts +9 -3
- package/dist/esm/ModelType.d.ts +18 -5
- package/dist/esm/RefType.d.ts +6 -0
- package/dist/esm/SchemaProcessor.mjs +26 -17
- package/dist/esm/SchemaProcessor.mjs.map +1 -1
- package/dist/esm/a.d.ts +1 -1
- package/dist/esm/a.mjs +1 -1
- package/dist/esm/a.mjs.map +1 -1
- package/dist/esm/ai/ConversationSchemaTypes.d.ts +5 -1
- package/dist/esm/ai/ConversationSchemaTypes.mjs +6 -7
- package/dist/esm/ai/ConversationSchemaTypes.mjs.map +1 -1
- package/dist/esm/ai/ConversationType.d.ts +1 -1
- package/dist/esm/index.d.ts +9 -0
- package/dist/esm/runtime/client/index.d.ts +3 -3
- package/dist/esm/runtime/internals/APIClient.mjs +8 -8
- package/dist/esm/runtime/internals/APIClient.mjs.map +1 -1
- package/dist/meta/cjs.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/Authorization.ts +7 -0
- package/src/ClientSchema/Core/ClientModel.ts +3 -3
- package/src/ClientSchema/utilities/ResolveField.ts +11 -12
- package/src/CustomOperation.ts +7 -0
- package/src/CustomType.ts +8 -3
- package/src/EnumType.ts +5 -0
- package/src/MappedTypes/ModelMetadata.ts +7 -7
- package/src/MappedTypes/ResolveFieldProperties.ts +13 -13
- package/src/MappedTypes/ResolveSchema.ts +5 -5
- package/src/ModelField.ts +5 -3
- package/src/{ModelRelationalField.ts → ModelRelationshipField.ts} +55 -35
- package/src/ModelSchema.ts +16 -6
- package/src/ModelType.ts +21 -8
- package/src/RefType.ts +6 -0
- package/src/SchemaProcessor.ts +47 -25
- package/src/a.ts +1 -1
- package/src/ai/ConversationSchemaTypes.ts +8 -7
- package/src/ai/ConversationType.ts +1 -1
- package/src/index.ts +14 -0
- package/src/runtime/client/index.ts +7 -3
- package/src/runtime/internals/APIClient.ts +8 -8
- package/dist/cjs/ModelRelationalField.js.map +0 -1
- package/dist/esm/ModelRelationalField.mjs.map +0 -1
|
@@ -7,6 +7,9 @@ const Authorization_1 = require("./Authorization");
|
|
|
7
7
|
* Used to "attach" auth types to ModelField without exposing them on the builder.
|
|
8
8
|
*/
|
|
9
9
|
exports.__auth = Symbol('__auth');
|
|
10
|
+
/**
|
|
11
|
+
* Model relationship types
|
|
12
|
+
*/
|
|
10
13
|
var ModelRelationshipTypes;
|
|
11
14
|
(function (ModelRelationshipTypes) {
|
|
12
15
|
ModelRelationshipTypes["hasOne"] = "hasOne";
|
|
@@ -18,7 +21,7 @@ const relationModifierMap = {
|
|
|
18
21
|
hasMany: ['valueRequired', 'authorization'],
|
|
19
22
|
hasOne: ['required', 'authorization'],
|
|
20
23
|
};
|
|
21
|
-
function
|
|
24
|
+
function _modelRelationshipField(type, relatedModel, references) {
|
|
22
25
|
const data = {
|
|
23
26
|
relatedModel,
|
|
24
27
|
type,
|
|
@@ -80,7 +83,7 @@ function _modelRelationalField(type, relatedModel, references) {
|
|
|
80
83
|
* @returns a one-to-one relationship definition
|
|
81
84
|
*/
|
|
82
85
|
function hasOne(relatedModel, references) {
|
|
83
|
-
return
|
|
86
|
+
return _modelRelationshipField(ModelRelationshipTypes.hasOne, relatedModel, Array.isArray(references) ? references : [references]);
|
|
84
87
|
}
|
|
85
88
|
exports.hasOne = hasOne;
|
|
86
89
|
/**
|
|
@@ -110,7 +113,7 @@ exports.hasOne = hasOne;
|
|
|
110
113
|
* @returns a one-to-many relationship definition
|
|
111
114
|
*/
|
|
112
115
|
function hasMany(relatedModel, references) {
|
|
113
|
-
return
|
|
116
|
+
return _modelRelationshipField(ModelRelationshipTypes.hasMany, relatedModel, Array.isArray(references) ? references : [references]);
|
|
114
117
|
}
|
|
115
118
|
exports.hasMany = hasMany;
|
|
116
119
|
/**
|
|
@@ -161,7 +164,7 @@ exports.hasMany = hasMany;
|
|
|
161
164
|
* @returns a belong-to relationship definition
|
|
162
165
|
*/
|
|
163
166
|
function belongsTo(relatedModel, references) {
|
|
164
|
-
return
|
|
167
|
+
return _modelRelationshipField(ModelRelationshipTypes.belongsTo, relatedModel, Array.isArray(references) ? references : [references]);
|
|
165
168
|
}
|
|
166
169
|
exports.belongsTo = belongsTo;
|
|
167
|
-
//# sourceMappingURL=
|
|
170
|
+
//# sourceMappingURL=ModelRelationshipField.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ModelRelationshipField.js","sources":["../../src/ModelRelationshipField.ts"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.belongsTo = exports.hasMany = exports.hasOne = exports.ModelRelationshipTypes = exports.__auth = void 0;\nconst Authorization_1 = require(\"./Authorization\");\n/**\n * Used to \"attach\" auth types to ModelField without exposing them on the builder.\n */\nexports.__auth = Symbol('__auth');\nconst brandName = 'modelRelationshipField';\n/**\n * Model relationship types\n */\nvar ModelRelationshipTypes;\n(function (ModelRelationshipTypes) {\n ModelRelationshipTypes[\"hasOne\"] = \"hasOne\";\n ModelRelationshipTypes[\"hasMany\"] = \"hasMany\";\n ModelRelationshipTypes[\"belongsTo\"] = \"belongsTo\";\n})(ModelRelationshipTypes || (exports.ModelRelationshipTypes = ModelRelationshipTypes = {}));\nconst relationshipModifiers = [\n 'required',\n 'valueRequired',\n 'authorization',\n];\nconst relationModifierMap = {\n belongsTo: ['authorization'],\n hasMany: ['valueRequired', 'authorization'],\n hasOne: ['required', 'authorization'],\n};\nfunction _modelRelationshipField(type, relatedModel, references) {\n const data = {\n relatedModel,\n type,\n fieldType: 'model',\n array: false,\n valueRequired: false,\n arrayRequired: false,\n references,\n authorization: [],\n };\n data.array = type === 'hasMany';\n const relationshipBuilderFunctions = {\n required() {\n data.arrayRequired = true;\n return this;\n },\n valueRequired() {\n data.valueRequired = true;\n return this;\n },\n authorization(callback) {\n const rules = callback(Authorization_1.allow);\n data.authorization = Array.isArray(rules) ? rules : [rules];\n return this;\n },\n };\n const builder = Object.fromEntries(relationModifierMap[type].map((key) => [\n key,\n relationshipBuilderFunctions[key],\n ]));\n return {\n ...builder,\n data,\n };\n}\n/**\n * Create one-to-one relationship between two models using the `hasOne(\"MODEL_NAME\", \"REFERENCE_FIELD(s)\")` method.\n * A hasOne relationship always uses a reference to the related model's identifier. Typically this is the `id` field\n * unless overwritten with the `identifier()` method.\n * @example\n * const schema = a.schema({\n * Cart: a.model({\n * items: a.string().required().array(),\n * // 1. Create reference field\n * customerId: a.id(),\n * // 2. Create relationship field with the reference field\n * customer: a.belongsTo('Customer', 'customerId'),\n * }),\n * Customer: a.model({\n * name: a.string(),\n * // 3. Create relationship field with the reference field\n * // from the Cart model\n * activeCart: a.hasOne('Cart', 'customerId')\n * }),\n * });\n * @see {@link https://docs.amplify.aws/react/build-a-backend/data/data-modeling/relationships/#model-a-one-to-one-relationship}\n * @param relatedModel the name of the related model\n * @param references the field(s) that should be used to reference the related model\n * @returns a one-to-one relationship definition\n */\nfunction hasOne(relatedModel, references) {\n return _modelRelationshipField(ModelRelationshipTypes.hasOne, relatedModel, Array.isArray(references) ? references : [references]);\n}\nexports.hasOne = hasOne;\n/**\n * Create a one-directional one-to-many relationship between two models using the `hasMany(\"MODEL_NAME\", \"REFERENCE_FIELD(s)\")` method.\n * @example\n * const schema = a.schema({\n * Member: a.model({\n * name: a.string().required(),\n * // 1. Create a reference field\n * teamId: a.id(),\n * // 2. Create a belongsTo relationship with the reference field\n * team: a.belongsTo('Team', 'teamId'),\n * })\n * .authorization(allow => [allow.publicApiKey()]),\n *\n * Team: a.model({\n * mantra: a.string().required(),\n * // 3. Create a hasMany relationship with the reference field\n * // from the `Member`s model.\n * members: a.hasMany('Member', 'teamId'),\n * })\n * .authorization(allow => [allow.publicApiKey()]),\n * });\n * @see {@link https://docs.amplify.aws/react/build-a-backend/data/data-modeling/relationships/#model-one-to-many-relationships}\n * @param relatedModel the name of the related model\n * @param references the field(s) that should be used to reference the related model\n * @returns a one-to-many relationship definition\n */\nfunction hasMany(relatedModel, references) {\n return _modelRelationshipField(ModelRelationshipTypes.hasMany, relatedModel, Array.isArray(references) ? references : [references]);\n}\nexports.hasMany = hasMany;\n/**\n * Use `belongsTo()` to create a field to query the related `hasOne()` or `hasMany()` relationship.\n * The belongsTo() method requires that a hasOne() or hasMany() relationship already exists from\n * parent to the related model.\n *\n * @example\n * // one-to-many relationship\n * const schema = a.schema({\n * Member: a.model({\n * name: a.string().required(),\n * // 1. Create a reference field\n * teamId: a.id(),\n * // 2. Create a belongsTo relationship with the reference field\n * team: a.belongsTo('Team', 'teamId'),\n * })\n * .authorization(allow => [allow.publicApiKey()]),\n *\n * Team: a.model({\n * mantra: a.string().required(),\n * // 3. Create a hasMany relationship with the reference field\n * // from the `Member`s model.\n * members: a.hasMany('Member', 'teamId'),\n * })\n * .authorization(allow => [allow.publicApiKey()]),\n * });\n * @example\n * // one-to-one relationship\n * const schema = a.schema({\n * Cart: a.model({\n * items: a.string().required().array(),\n * // 1. Create reference field\n * customerId: a.id(),\n * // 2. Create relationship field with the reference field\n * customer: a.belongsTo('Customer', 'customerId'),\n * }),\n * Customer: a.model({\n * name: a.string(),\n * // 3. Create relationship field with the reference field\n * // from the Cart model\n * activeCart: a.hasOne('Cart', 'customerId')\n * }),\n * });\n * @see {@link https://docs.amplify.aws/react/build-a-backend/data/data-modeling/relationships/}\n * @param relatedModel name of the related `.hasOne()` or `.hasMany()` model\n * @param references the field(s) that should be used to reference the related model\n * @returns a belong-to relationship definition\n */\nfunction belongsTo(relatedModel, references) {\n return _modelRelationshipField(ModelRelationshipTypes.belongsTo, relatedModel, Array.isArray(references) ? references : [references]);\n}\nexports.belongsTo = belongsTo;\n"],"names":[],"mappings":";;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,SAAS,GAAG,OAAO,CAAC,OAAO,GAAG,OAAO,CAAC,MAAM,GAAG,OAAO,CAAC,sBAAsB,GAAG,OAAO,CAAC,MAAM,GAAG,KAAK,CAAC,CAAC;AAChH,MAAM,eAAe,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;AACnD;AACA;AACA;AACA,OAAO,CAAC,MAAM,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC;AAElC;AACA;AACA;AACA,IAAI,sBAAsB,CAAC;AAC3B,CAAC,UAAU,sBAAsB,EAAE;AACnC,IAAI,sBAAsB,CAAC,QAAQ,CAAC,GAAG,QAAQ,CAAC;AAChD,IAAI,sBAAsB,CA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ACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS,SAAS,CAAC,YAAY,EAAE,UAAU,EAAE;AAC7C,IAAI,OAAO,uBAAuB,CAAC,sBAAsB,CAAC,SAAS,EAAE,YAAY,EAAE,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,GAAG,UAAU,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC;AAC1I,CAAC;AACD,OAAO,CAAC,SAAS,GAAG,SAAS;;"}
|
|
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
4
4
|
exports.processSchema = void 0;
|
|
5
5
|
const tslib_1 = require("tslib");
|
|
6
6
|
const ModelField_1 = require("./ModelField");
|
|
7
|
-
const
|
|
7
|
+
const ModelRelationshipField_1 = require("./ModelRelationshipField");
|
|
8
8
|
const Authorization_1 = require("./Authorization");
|
|
9
9
|
const CustomOperation_1 = require("./CustomOperation");
|
|
10
10
|
const util_1 = require("./util");
|
|
@@ -163,7 +163,9 @@ function transformFunctionHandler(handlers, functionFieldName) {
|
|
|
163
163
|
else if (typeof handlerData.handler.getInstance === 'function') {
|
|
164
164
|
const fnName = `Fn${capitalize(functionFieldName)}${idx === 0 ? '' : `${idx + 1}`}`;
|
|
165
165
|
lambdaFunctionDefinition[fnName] = handlerData.handler;
|
|
166
|
-
const invocationTypeArg = handlerData.invocationType === 'Event'
|
|
166
|
+
const invocationTypeArg = handlerData.invocationType === 'Event'
|
|
167
|
+
? ', invocationType: Event)'
|
|
168
|
+
: ')';
|
|
167
169
|
gqlHandlerContent += `@function(name: "${fnName}"${invocationTypeArg} `;
|
|
168
170
|
}
|
|
169
171
|
else {
|
|
@@ -842,11 +844,12 @@ const schemaPreprocessor = (schema) => {
|
|
|
842
844
|
// - it only happens once per schema
|
|
843
845
|
// - downstream validation based on `getRefTypeForSchema` finds the EventInvocationResponse type
|
|
844
846
|
const containsAsyncLambdaCustomOperation = Object.entries(schema.data.types).find(([_, typeDef]) => {
|
|
845
|
-
return isCustomOperation(typeDef)
|
|
846
|
-
|
|
847
|
+
return (isCustomOperation(typeDef) &&
|
|
848
|
+
finalHandlerIsAsyncFunctionHandler(typeDef.data.handlers));
|
|
847
849
|
});
|
|
848
850
|
if (containsAsyncLambdaCustomOperation) {
|
|
849
|
-
schema.data.types['EventInvocationResponse'] =
|
|
851
|
+
schema.data.types['EventInvocationResponse'] =
|
|
852
|
+
eventInvocationResponseCustomType;
|
|
850
853
|
}
|
|
851
854
|
const topLevelTypes = sortTopLevelTypes(Object.entries(schema.data.types));
|
|
852
855
|
const { schemaAuth, functionSchemaAccess } = extractFunctionSchemaAccess(schema.data.authorization);
|
|
@@ -917,7 +920,9 @@ const schemaPreprocessor = (schema) => {
|
|
|
917
920
|
}
|
|
918
921
|
else if (isConversationRoute(typeDef)) {
|
|
919
922
|
// TODO: add inferenceConfiguration values to directive.
|
|
920
|
-
|
|
923
|
+
const { field, functionHandler } = (0, ConversationSchemaTypes_1.createConversationField)(typeDef, typeName);
|
|
924
|
+
customMutations.push(field);
|
|
925
|
+
Object.assign(lambdaFunctions, functionHandler);
|
|
921
926
|
shouldAddConversationTypes = true;
|
|
922
927
|
}
|
|
923
928
|
}
|
|
@@ -1022,7 +1027,9 @@ function validateCustomOperations(typeDef, typeName, authRules, getRefType) {
|
|
|
1022
1027
|
(opType === 'Query' || opType === 'Mutation' || opType === 'Generation')) {
|
|
1023
1028
|
// TODO: There should be a more elegant and readable way to handle this check.
|
|
1024
1029
|
// Maybe it's not even necessary anymore since we're the setting returnType in the handler() method.
|
|
1025
|
-
if (!handlers ||
|
|
1030
|
+
if (!handlers ||
|
|
1031
|
+
handlers.length === 0 ||
|
|
1032
|
+
handlers[handlers.length - 1][Brand_1.brandSymbol] !== 'asyncFunctionHandler') {
|
|
1026
1033
|
const typeDescription = opType === 'Generation' ? 'Generation Route' : `Custom ${opType}`;
|
|
1027
1034
|
throw new Error(`Invalid ${typeDescription} definition. A ${typeDescription} must include a return type. ${typeName} has no return type specified.`);
|
|
1028
1035
|
}
|
|
@@ -1080,10 +1087,12 @@ const isCustomHandler = (handler) => {
|
|
|
1080
1087
|
return Array.isArray(handler) && (0, util_1.getBrand)(handler[0]) === 'customHandler';
|
|
1081
1088
|
};
|
|
1082
1089
|
const isFunctionHandler = (handler) => {
|
|
1083
|
-
return Array.isArray(handler) &&
|
|
1090
|
+
return (Array.isArray(handler) &&
|
|
1091
|
+
['functionHandler', 'asyncFunctionHandler'].includes((0, util_1.getBrand)(handler[0])));
|
|
1084
1092
|
};
|
|
1085
1093
|
const finalHandlerIsAsyncFunctionHandler = (handler) => {
|
|
1086
|
-
return Array.isArray(handler) &&
|
|
1094
|
+
return (Array.isArray(handler) &&
|
|
1095
|
+
(0, util_1.getBrand)(handler[handler.length - 1]) === 'asyncFunctionHandler');
|
|
1087
1096
|
};
|
|
1088
1097
|
const normalizeDataSourceName = (dataSource) => {
|
|
1089
1098
|
// default data source
|
|
@@ -1146,11 +1155,11 @@ const eventInvocationResponseCustomType = {
|
|
|
1146
1155
|
required: true,
|
|
1147
1156
|
array: false,
|
|
1148
1157
|
arrayRequired: false,
|
|
1149
|
-
}
|
|
1150
|
-
}
|
|
1158
|
+
},
|
|
1159
|
+
},
|
|
1151
1160
|
},
|
|
1152
|
-
type: 'customType'
|
|
1153
|
-
}
|
|
1161
|
+
type: 'customType',
|
|
1162
|
+
},
|
|
1154
1163
|
};
|
|
1155
1164
|
function transformCustomOperations(typeDef, typeName, authRules, databaseType, getRefType) {
|
|
1156
1165
|
const { typeName: opType, handlers } = typeDef.data;
|
|
@@ -1242,8 +1251,8 @@ function validateRelationships(typeName, record, getInternalModel) {
|
|
|
1242
1251
|
// Create a structure representing the relationship for validation.
|
|
1243
1252
|
const relationship = getModelRelationship(typeName, { name: name, def: field.data }, getInternalModel);
|
|
1244
1253
|
// Validate that the references defined in the relationship follow the
|
|
1245
|
-
//
|
|
1246
|
-
|
|
1254
|
+
// relationship definition rules.
|
|
1255
|
+
validateRelationshipReferences(relationship);
|
|
1247
1256
|
}
|
|
1248
1257
|
}
|
|
1249
1258
|
/**
|
|
@@ -1269,7 +1278,7 @@ function describeConnectFieldRelationship(sourceField, sourceModelName) {
|
|
|
1269
1278
|
* Validates that the types of child model's reference fields match the types of the parent model's identifier fields.
|
|
1270
1279
|
* @param relationship The {@link ModelRelationship} to validate.
|
|
1271
1280
|
*/
|
|
1272
|
-
function
|
|
1281
|
+
function validateRelationshipReferences(relationship) {
|
|
1273
1282
|
const { parent, parentConnectionField, child, childConnectionField, references, } = relationship;
|
|
1274
1283
|
const parentIdentifiers = getIndentifierTypes(parent);
|
|
1275
1284
|
const childReferenceTypes = [];
|
|
@@ -1324,11 +1333,11 @@ function validateRelationalReferences(relationship) {
|
|
|
1324
1333
|
*/
|
|
1325
1334
|
function associatedRelationshipTypes(relationshipType) {
|
|
1326
1335
|
switch (relationshipType) {
|
|
1327
|
-
case
|
|
1328
|
-
case
|
|
1329
|
-
return [
|
|
1330
|
-
case
|
|
1331
|
-
return [
|
|
1336
|
+
case ModelRelationshipField_1.ModelRelationshipTypes.hasOne:
|
|
1337
|
+
case ModelRelationshipField_1.ModelRelationshipTypes.hasMany:
|
|
1338
|
+
return [ModelRelationshipField_1.ModelRelationshipTypes.belongsTo];
|
|
1339
|
+
case ModelRelationshipField_1.ModelRelationshipTypes.belongsTo:
|
|
1340
|
+
return [ModelRelationshipField_1.ModelRelationshipTypes.hasOne, ModelRelationshipField_1.ModelRelationshipTypes.hasMany];
|
|
1332
1341
|
default:
|
|
1333
1342
|
return []; // TODO: Remove this case on types are updated.
|
|
1334
1343
|
}
|
|
@@ -1376,7 +1385,7 @@ function getAssociatedConnectionField(sourceModelName, sourceConnectionField, as
|
|
|
1376
1385
|
}
|
|
1377
1386
|
// In order to find that associated connection field, we need to do some validation that we'll depend on further downstream.
|
|
1378
1387
|
// 1. Field type matches the source model's type.
|
|
1379
|
-
// 2. A valid counterpart
|
|
1388
|
+
// 2. A valid counterpart relationship modifier is defined on the field. See `associatedRelationshipTypes` for more information.
|
|
1380
1389
|
// 3. The reference arguments provided to the field match (element count + string comparison) references passed to the source connection field.
|
|
1381
1390
|
return (connectionField.data.relatedModel === sourceModelName &&
|
|
1382
1391
|
associatedRelationshipOptions.includes(connectionField.data.type) &&
|
|
@@ -1425,8 +1434,8 @@ function getModelRelationship(sourceModelName, sourceModelConnectionField, getIn
|
|
|
1425
1434
|
const associatedModel = getInternalModel(sourceModelConnectionField.def.relatedModel, sourceModelName);
|
|
1426
1435
|
const relatedModelConnectionField = getAssociatedConnectionField(sourceModelName, sourceModelConnectionField, associatedModel);
|
|
1427
1436
|
switch (sourceModelConnectionField.def.type) {
|
|
1428
|
-
case
|
|
1429
|
-
case
|
|
1437
|
+
case ModelRelationshipField_1.ModelRelationshipTypes.hasOne:
|
|
1438
|
+
case ModelRelationshipField_1.ModelRelationshipTypes.hasMany:
|
|
1430
1439
|
return {
|
|
1431
1440
|
parent: sourceModel,
|
|
1432
1441
|
parentConnectionField: sourceModelConnectionField,
|
|
@@ -1434,7 +1443,7 @@ function getModelRelationship(sourceModelName, sourceModelConnectionField, getIn
|
|
|
1434
1443
|
childConnectionField: relatedModelConnectionField,
|
|
1435
1444
|
references: sourceModelConnectionField.def.references,
|
|
1436
1445
|
};
|
|
1437
|
-
case
|
|
1446
|
+
case ModelRelationshipField_1.ModelRelationshipTypes.belongsTo:
|
|
1438
1447
|
return {
|
|
1439
1448
|
parent: associatedModel,
|
|
1440
1449
|
parentConnectionField: relatedModelConnectionField,
|