我正在开发一个应用程序,该应用程序将 AppSync 与来自 aws 的 graphql 结合使用,但每当我运行以下代码行 DataStore.start() 时,都会出现以下错误:
[错误] 数据存储 - 架构未初始化。 DataStore 将无法按预期运行。如果您安装了多个版本的 DataStore,则可能会发生这种情况。请参阅https://docs.amplify.aws/lib/troubleshooting/upgrading/q/platform/js/#check-for-duplicate-versions
我不知道还能做什么。我什至从0开始一个应用程序,也出现了同样的问题。我已经删除了 node_modules 文件夹并再次安装了所有内容,但它不会,而且我想不出一种方法来映射可能的错误。下面是代码和包。
import Amplify, { API, Auth, DataStore, Hub, Storage } from 'aws-amplify';
import awsmobile from './src/aws-exports';
import awsapigateway from './src/aws-api-gateway';
Amplify.Logger.LOG_LEVEL = 'DEBUG';
Amplify.configure(awsmobile);
API.configure(awsapigateway);
DataStore.start()
.then(() => console.log('DataStore started'))
.catch(e => console.log('Error init datastore: ', e))
.finally(() => console.log('DataStore finally'));
package.json
"dependencies": {
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.16.7",
"@babel/plugin-proposal-optional-chaining": "^7.16.7",
"@babel/plugin-syntax-flow": "^7.14.5",
"@babel/plugin-transform-react-jsx": "^7.14.9",
"@react-native-async-storage/async-storage": "^1.17.7",
"@react-native-community/geolocation": "^2.0.2",
"@react-native-community/netinfo": "^9.3.0",
"@react-native-picker/picker": "^2.4.0",
"@react-navigation/bottom-tabs": "^6.2.0",
"@react-navigation/native": "^6.0.8",
"@react-navigation/stack": "^6.1.1",
"amazon-cognito-identity-js": "^5.2.8",
"aws-amplify": "^4.3.26",
"graphql": "16.5.0",
"graphql-tools": "^8.3.0",
"moment": "^2.29.1",
"prettier": "^2.6.0",
"prop-types": "^15.8.1",
"radio-buttons-react-native": "^1.0.4",
"react": "^17.0.2",
"react-native": "^0.68.2",
"react-native-android-location-services-dialog-box": "^2.8.2",
"react-native-bootsplash": "^4.1.4",
"react-native-debugger": "^1.1.0",
"react-native-elements": "^3.4.2",
"react-native-fs": "^2.19.0",
"react-native-gesture-handler": "2.5.0",
"react-native-get-random-values": "^1.7.2",
"react-native-image-pan-zoom": "^2.1.12",
"react-native-linear-gradient": "^2.5.6",
"react-native-loading-spinner-overlay": "^3.0.0",
"react-native-permissions": "^3.3.1",
"react-native-pressable-opacity": "^1.0.8",
"react-native-reanimated": "^2.8.0",
"react-native-safe-area-context": "^3.1.9",
"react-native-screens": ">= 3.0.0",
"react-native-sqlite-storage": "^6.0.1",
"react-native-static-safe-area-insets": "^2.1.1",
"react-native-vector-icons": "^9.1.0",
"react-native-vision-camera": "^2.13.3",
"typescript": "^4.6.2",
"uuid": "^8.3.2",
"vision-camera-code-scanner": "^0.2.0"
},
"devDependencies": {
"@babel/core": "7.18.6",
"@babel/preset-env": "7.18.6",
"@babel/runtime": "^7.17.8",
"@react-native-community/eslint-config": "^2.0.0",
"@react-native-community/eslint-plugin": "^1.1.0",
"babel-eslint": "^10.1.0",
"babel-jest": "^28.1.1",
"eslint": "^7.32.0",
"eslint-config-airbnb": "^19.0.4",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-import": "^2.25.4",
"eslint-plugin-jsx-a11y": "^6.5.1",
"eslint-plugin-react": "^7.29.4",
"eslint-plugin-react-hooks": "^4.3.0",
"ini": "^1.3.5",
"inquirer": "^6.5.1",
"jest": "^28.1.1",
"metro-react-native-babel-preset": "^0.71.2",
"react-test-renderer": "^17.0.2"
},
schema.graphql:"
type Subpoena @model @auth(rules: [{allow: public}]) {
id: id!
status: SyncStatus!
localImageStorage: AWSJSON
}
enum SyncStatus {
PENDING
DONATE
ERROR
}
最佳答案
我与类似的事情斗争了整整 24 小时,互联网上现有的答案/文档毫无用处。事实证明我正在做类似的事情:
import {MyModel} from `@src/models`;
如果您查看该文件,您会发现它调用了 initSchema()
,这是需要调用以避免错误 DataStore - Schema is notinitialized 的函数
。不幸的是,如果您不在任何地方使用该模型,import
就会被优化,并且 initSchema()
永远不会被调用。
恕我直言,亚马逊方面存在相当严重的错误。您可能希望在不调用代码中的 .save()
或 .query()
的情况下测试打开同步,这似乎是合理的。
在我的例子中,简单地添加这个就足够了:
console.log(MyModel);
关于amazon-web-services - 数据存储 - 架构未初始化。 DataStore 将无法按预期运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72806172/