Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: improve object stringify and verbiage for relationship identifier errors #8344

Merged
merged 1 commit into from
Dec 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions packages/record-data/addon/-private/graph/-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,21 +224,25 @@ export function assertRelationshipData(store, identifier, data, meta) {
assert(
`Encountered a relationship identifier without a type for the ${meta.kind} relationship '${meta.key}' on <${
identifier.type
}:${identifier.id}>, expected a json-api identifier with type '${meta.type}' but found '${JSON.stringify(
data
)}'. Please check your serializer and make sure it is serializing the relationship payload into a JSON API format.`,
}:${identifier.id}>, expected an identifier with type '${meta.type}' but found\n\n'${JSON.stringify(
data,
null,
2
)}'\n\nPlease check your serializer and make sure it is serializing the relationship payload into a JSON API format.`,
data === null || (typeof data.type === 'string' && data.type.length)
);
assert(
`Encountered a relationship identifier without an id for the ${meta.kind} relationship '${meta.key}' on <${
identifier.type
}:${identifier.id}>, expected a json-api identifier but found '${JSON.stringify(
data
)}'. Please check your serializer and make sure it is serializing the relationship payload into a JSON API format.`,
}:${identifier.id}>, expected an identifier but found\n\n'${JSON.stringify(
data,
null,
2
)}'\n\nPlease check your serializer and make sure it is serializing the relationship payload into a JSON API format.`,
data === null || !!coerceId(data.id)
);
assert(
`Encountered a relationship identifier with type '${data.type}' for the ${meta.kind} relationship '${meta.key}' on <${identifier.type}:${identifier.id}>, Expected a json-api identifier with type '${meta.type}'. No model was found for '${data.type}'.`,
`Encountered a relationship identifier with type '${data.type}' for the ${meta.kind} relationship '${meta.key}' on <${identifier.type}:${identifier.id}>, Expected an identifier with type '${meta.type}'. No model was found for '${data.type}'.`,
data === null || !data.type || store.getSchemaDefinitionService().doesTypeExist(data.type)
);
}
6 changes: 3 additions & 3 deletions tests/main/tests/integration/relationships/belongs-to-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ module('integration/relationship/belongs_to Belongs-To Relationships', function
});
post.user;
});
}, `Assertion Failed: Encountered a relationship identifier without an id for the belongsTo relationship 'user' on <post:1>, expected a json-api identifier but found '{"id":null,"type":"user"}'. Please check your serializer and make sure it is serializing the relationship payload into a JSON API format.`);
}, /Assertion Failed: Encountered a relationship identifier without an id for the belongsTo relationship 'user' on <post:1>, expected an identifier but found/);
});

testInDebug('Invalid belongsTo relationship identifiers throw errors for null type', function (assert) {
Expand All @@ -570,7 +570,7 @@ module('integration/relationship/belongs_to Belongs-To Relationships', function
});
post.user;
});
}, `Assertion Failed: Encountered a relationship identifier without a type for the belongsTo relationship 'user' on <post:2>, expected a json-api identifier with type 'user' but found '{"id":"1","type":null}'. Please check your serializer and make sure it is serializing the relationship payload into a JSON API format.`);
}, /Assertion Failed: Encountered a relationship identifier without a type for the belongsTo relationship 'user' on <post:2>, expected an identifier with type 'user' but found/);
});

testInDebug(
Expand Down Expand Up @@ -1993,7 +1993,7 @@ module('integration/relationship/belongs_to Belongs-To Relationships', function
});
chapter.book;
});
}, /Encountered a relationship identifier without a type for the belongsTo relationship 'book' on <chapter:1>, expected a json-api identifier with type 'book'/);
}, /Encountered a relationship identifier without a type for the belongsTo relationship 'book' on <chapter:1>, expected an identifier with type 'book'/);
});

test("belongsTo relationship with links doesn't trigger extra change notifications - #4942", function (assert) {
Expand Down
4 changes: 2 additions & 2 deletions tests/main/tests/integration/relationships/has-many-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ module('integration/relationships/has_many - Has-Many Relationships', function (

post.comments;
});
}, `Assertion Failed: Encountered a relationship identifier without an id for the hasMany relationship 'comments' on <post:1>, expected a json-api identifier but found '{"id":null,"type":"comment"}'. Please check your serializer and make sure it is serializing the relationship payload into a JSON API format.`);
}, /Assertion Failed: Encountered a relationship identifier without an id for the hasMany relationship 'comments' on <post:1>, expected an identifier but found/);
});

testInDebug('Invalid hasMany relationship identifiers throw errors for missing type', function (assert) {
Expand All @@ -197,7 +197,7 @@ module('integration/relationships/has_many - Has-Many Relationships', function (
});
post.comments;
});
}, `Assertion Failed: Encountered a relationship identifier without a type for the hasMany relationship 'comments' on <post:2>, expected a json-api identifier with type 'comment' but found '{"id":"1","type":null}'. Please check your serializer and make sure it is serializing the relationship payload into a JSON API format.`);
}, /Assertion Failed: Encountered a relationship identifier without a type for the hasMany relationship 'comments' on <post:2>, expected an identifier with type 'comment' but found/);
});

test("When a hasMany relationship is accessed, the adapter's findMany method should not be called if all the records in the relationship are already loaded", function (assert) {
Expand Down