Closed ajiteshchhatani closed 2 years ago
Hi, @ajiteshchhatani. Thanks for reaching out.
I believe I know what the issue is, it's in the way you define primaryKey
for the user
model. The primaryKey
function expects either a constructor (to infer the type) or a getter function. In contrast, you're passing a resolved value of calling uuidv4()
.
Here's how to represent your intention:
export const db = factory({
user: {
- id: primaryKey(uuidv4()),
+ id: primaryKey(uuidv4), // notice no parentheses
userName: String
}
})
You can see us showcasing how to use Faker in particular:
https://github.com/mswjs/data/blob/2639a1fc147dcf43e83bc7a65f150c8128a95e22/README.md?plain=1#L990
Hey @kettanaito thank you for this.
The solution worked. It was a mistake on my part. I didn't look at it close enough.
Apologies for opening this issue. Thank you once again.
Hi! I am playing around with msw and mswjs/data in a small react-app. I was successfully able to follow the documentation and create handlers for the msw and a small basic model using mswjs/data.
However the moment I try to generate some data based on the model I get an error in my React app which says
Uncaught TypeError: propertyDefinition.getPrimaryKeyValue is not a function
which points to the generateUser() function that creates some data.Code snippet as below
mocks/handlers.js
mocks/browser.js
My React app entry point
src/index.js
All packages msw and mswjs/data along with react have their latest versions.
Anything wrong with what I am doing? Any help would be appreciated as I've done everything I could and could not find a resolution.