Open mauroaccornero opened 2 years ago
Hey, @mauroaccornero. I'm sorry to hear you're having trouble making http-middleware and data work together. Do you happen to have your project published on GitHub? If you create a reproduction repository/sandbox I can help you look into the issue.
Hi @kettanaito, here is a little repository with a test to replicate the issue https://github.com/mauroaccornero/mswjs-test.
Looks like db.book.create() only accepts references for a related entity, it's possible to get the same error with:
db.book.create({
"title": "asdasdas",
"year": 2013,
"author": {
"id": "b463b8bb-76cf-46a9-b266-5ab5730b69ba",
"name": "Ms. Bessie Daniel"
}
})
while it works with a reference
const author = db.author.create()
db.book.create({author})
Let me know if I can do something to help and thanks for your support!
Hello,
I'm trying to use mswjs/data with mswjs/http-middleware with this code:
db.js
server.js
I start the server with
almost everything works fine but when I try to create a new book with a POST to localhost:9090/books and a JSON payload like:
I get a 500 status code with this message:
I verified that the author was correct and if I try to create a book without the author, the book it's correctly saved.
I tried different payloads with Postman, but without luck.
I'm using
with node v16.14.0
probably I'm missing something, any suggestion it's welcome.
update: Looks like the error comes from msw/data https://github.com/mswjs/data/blob/main/src/relations/Relation.ts#L172