Open morepe opened 1 year ago
Hi @morepe 👋 , Thank you for raising the issue. I find problems with the name structure in the supplied schema. Please try the below-listed schema. I changed @hasmany to @hasmany and @hasmany to @Index.
type Variations @model @auth(rules: [{allow: public}]) {
id: ID!
displayName: String
productID: ID! @index(name: "byProduct")
}
type Store @model @auth(rules: [{allow: public}]) {
id: ID!
key: String!
displayName: String!
Products: [Product] @hasMany(indexName: "byStore", fields: ["id"])
}
type Product @model @auth(rules: [{allow: public}]) {
id: ID!
key: String!
displayName: String!
minimalPrice: Float!
storeID: ID! @index(name: "byStore")
Variations: [Variations] @hasMany(indexName: "byProduct", fields: ["id"])
}
Hi,
I just took the Schema that you provided, copied into my procjet and executed
amplify build
amplify mock
But I still got the same error:
Is there some kind cleanup or something I would need to perform? The schema looks straight forward to me.
@morepe, did you execute "amplify push" ? and try "amplify mock api".
No I did not do amplify push before. As I already added more models to my initial work and did not want to lose it, I tried the following:
Now the amplify mock works.
However, then I tried to add one more simple model (ProductCategories). It started to fail again with the same error and I can't make it work. So with the new model the schema now looks like this:
# This "input" configures a global authorization rule to enable public access to
# all models in this schema. Learn more about authorization rules here: https://docs.amplify.aws/cli/graphql/authorization-rules
input AMPLIFY { globalAuthRule: AuthRule = { allow: public } } # FOR TESTING ONLY!
type Variations @model @auth(rules: [{allow: public}]) {
id: ID!
displayName: String
productID: ID! @index(name: "byProduct")
}
type Store @model @auth(rules: [{allow: public}]) {
id: ID!
key: String!
displayName: String!
Products: [Product] @hasMany(indexName: "byStore", fields: ["id"])
}
type Product @model @auth(rules: [{allow: public}]) {
id: ID!
key: String!
displayName: String!
minimalPrice: Float!
storeID: ID! @index(name: "byStore")
Variations: [Variations] @hasMany(indexName: "byProduct", fields: ["id"])
productcategoriesID: ID! @index(name: "byProductCategories")
}
type ProductCategories @model @auth(rules: [{allow: public}]) {
id: ID!
key: String!
displayName: String!
Products: [Product] @hasMany(indexName: "byProductCategories", fields: ["id"])
}
The complete steps I did:
> amplify init
Note: It is recommended to run this command from the root of your app directory
? Enter a name for the project test
The following configuration will be applied:
Project information
| Name: test
| Environment: dev
| Default editor: Visual Studio Code
| App type: javascript
| Javascript framework: none
| Source Directory Path: src
| Distribution Directory Path: dist
| Build Command: npm run-script build
| Start Command: npm run-script start
> amplify add api
==> pastet graphgl content from https://github.com/aws-amplify/amplify-category-api/issues/1234#issuecomment-1422718374
> amplify mock
==> worked
> added product categories while mock was running
==> failed
Creating new table ProductCategoriesTable
Reloading failed with error
TypeError [ERR_INVALID_CALLBACK]: Callback must be a function. Received undefined
GraphQL Schema change detected. Reloading...
> removed again
=> was working again
> amplify push
=> tried to add product categories again, did not work
> amplify push (now with product categories that did not work locally)
=> same error still persists
Has it something to do with that the properties in the newly added model have the same name as onces in an existing model?
Hi @morepe, The issue has been reproduced, and it has been marked as a bug for the team to examine further. In the meantime, as a temporary solution you can try deleting the amplify/mock-data folder and let us know if that resolves the problem.
Thank you, deleting the amplify/mock-data works. However, its a bad workaround as I lose all my created testdata. So I am eagerly awaiting the bugfix :)
Hey, I believe I ran into something very similar, if not the same error. After forking the AmplifyCLI repo and building it in amplify-dev
mode, I was able to track the issue down to what looks like a tiny error in the source code of the amplify-util-mock package. Specifically line 91
in the following file: /amplify-cli/packages/amplify-util-mock/lib/api/api.js
It's a very long if-statement:
if (((_a = appSyncConfig === null || appSyncConfig === void 0 ? void 0 : appSyncConfig.tables) === null || _a === void 0 ? void 0 : _a.some((table) => table === null || table === void 0 ? void 0 : table.isSearchable)) && !(0, amplify_cli_core_1.isWindowsPlatform)) {
this.opensearchURL = await this.startOpensearchLocalServer(context, isLocalDBEmpty);
}
The if statement seems to have extraneous parentheses after this property: .isWindowsPlatform()
After removing them, the mock API built just fine. I've committed the changes locally but I'm not sure how to put in a pull request. This is the TypeScript file visible in the published GitHub repo: https://github.com/aws-amplify/amplify-cli/blob/dev/packages/amplify-util-mock/src/api/api.ts
Would love to hear if anyone else can verify.
How did you install the Amplify CLI?
npm
If applicable, what version of Node.js are you using?
v16.17.1
Amplify CLI Version
10.7.1
What operating system are you using?
Ubuntu (running in WSL2 on Windows)
Did you make any manual changes to the cloud resources managed by Amplify? Please describe the changes made.
No
Describe the bug
I can not start the mocking after I added some models connected to each other. It fails with: "MockProcessFault: Failed to start API Mocking.. Reason: Callback must be a function. Received undefined"
The API itself works fine if I access it in Amplify
Schema that I used:
type Variations @model @auth(rules: [{allow: public}]) { id: ID! displayName: String productID: ID! @index(name: "byProduct") }
type Store @model @auth(rules: [{allow: public}]) { id: ID! key: String! displayName: String! Products: [Product] @hasMany(indexName: "byStore", fields: ["id"]) }
type Product @model @auth(rules: [{allow: public}]) { id: ID! key: String! displayName: String! minimalPrice: Float! storeID: ID! @index(name: "byStore") Variations: [Variations] @hasMany(indexName: "byProduct", fields: ["id"]) }
Expected behavior
Mocking should start
Reproduction steps
Project Identifier
fb64912b3b591b6c0a306f250c9e5824
Log output
Additional information
No response
Before submitting, please confirm: