Closed hmisonne closed 3 years ago
@hmisonne Thanks for the detailed issue description 👏 .
I started fresh and followed your reproduction steps and It's working just fine. I can create the new users with userGroceryListID: null
and undefined
both worked fine.
The working repo can be access at wei/amplify-js-6965
4.30.0
and latest node packages.npmPackages: @babel/core: ~7.9.0 => 7.9.6 @react-native-community/netinfo: ^5.9.7 => 5.9.7 aws-amplify: ^3.3.4 => 3.3.4 aws-amplify-react-native: ^4.2.7 => 4.2.7 expo: ~39.0.2 => 39.0.3 expo-status-bar: ~1.0.2 => 1.0.2 ini: ^1.3.5 => 1.3.5 inquirer: ^6.5.1 => 6.5.2 react: 16.13.1 => 16.13.1 react-dom: 16.13.1 => 16.13.1 react-native: https://github.com/expo/react-native/archive/sdk-39.0.3.tar.gz => 0.63.2 react-native-web: ~0.13.12 => 0.13.18
Please let us know if this is still an issue you can reproduce from scratch. If so, please try to reproduce on top of my repo or create a fresh/minimal example repo using the latest CLI and packages. Thank you!
Thank you @wei it does work now.
It looks like running the command amplify-modelgen is now generating : (string | null)[]
for an optional field instead of just string[]
export declare class User {
readonly id: string;
readonly userGroceryListID?: (string | null)[];
constructor(init: ModelInit<User>);
static copyOf(source: User, mutator: (draft: MutableModel<User>) => MutableModel<User> | void): User;
}
@hmisonne Amazing! Thanks for getting back to us with your success update! 🎉
This issue has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs.
Looking for a help forum? We recommend joining the Amplify Community Discord server *-help
channels or Discussions for those types of questions.
I just want to mention that this is my first time trying to report a bug :bowtie:. I came across this issue while working on a React Native app with AWS amplify :rocket:!
I would appreciate any feedback :pray:.
Describe the bug
A GraphQL schema model with an optional string field (without exclamation mark) will throw an error if its content is null even:
datastore.js:222 Uncaught (in promise) Error: Field userGroceryListID should be of type string[], object received. null
To Reproduce Steps to reproduce the behavior:
Create an AWS amplify react native app by following this tutorial
Create a model in schema.graphql file
Update the API and database :
amplify update api
Add a DataStore by following this tutorial
Update the App.js file with the following code:
Expected behavior The application should run without errors
Code Snippet Here is the link to my repository
Config After running
npx envinfo --system --binaries --browsers --npmPackages --npmGlobalPackages
Platform:
Suggestion to fix the issue
On the datastore file located here:
C:\...\node_modules\@aws-amplify\datastore\lib-esm\datastore\datastore.js
, I added the conditionisRequired
on the if statements on line 220 and 229.