gpt4 book ai didi

react-native - 在 React Native 项目中向 Amplify API 添加模拟时出错

转载 作者:行者123 更新时间:2023-12-03 07:53:10 34 4
gpt4 key购买 nike

我目前正在开发一个 React Native 项目,其中使用 AWS Amplify 作为我的后端 API。我尝试向 Amplify API 添加模拟以进行测试,但使用此命令时遇到错误:

amplify mock api

导致此错误消息:

Edit your schema at 
/***/***/***/***/amplify/backend/api/***/schema.graphql or place .graphql files in a directory at /***/***/***/***/amplify/backend/api/***/schema
Failed to start API Mocking. Running cleanup tasks.
Reason: Error: Parse error on resolvers/Query.syncCouriers.req.vtl:11:50
Parse error on line 12:
...tx.stash.authFilter.or ) #if( $fil
-----------------------^
Expecting 'ID', 'CONTENT', got '||'

我不确定到底是什么导致了此错误以及如何解决它。我已经检查了我的架构文件并确保其格式正确。我还尝试在指定目录中创建单独的 .graphql 文件,但错误仍然存​​在。

package.json:

{
"name": "ubereatsuser",
"version": "1.0.0",
"main": "node_modules/expo/AppEntry.js",
"scripts": {
"start": "expo start",
"android": "expo start --android",
"ios": "expo start --ios",
"web": "expo start --web",
"eject": "expo eject"
},
"dependencies": {
"@react-native-async-storage/async-storage": "1.17.11",
"@react-native-community/netinfo": "9.3.5",
"@react-native-picker/picker": "2.4.8",
"@react-navigation/bottom-tabs": "^6.3.1",
"@react-navigation/material-bottom-tabs": "^6.2.1",
"@react-navigation/material-top-tabs": "^6.2.1",
"@react-navigation/native": "^6.0.10",
"@react-navigation/native-stack": "^6.6.1",
"aws-amplify": "^4.3.20",
"aws-amplify-react-native": "^6.0.4",
"expo": "~47.0.0",
"expo-status-bar": "~1.4.4",
"graphql": "^14.7.0",
"react": "18.1.0",
"react-dom": "18.1.0",
"react-native": "0.70.8",
"react-native-maps": "1.3.2",
"react-native-pager-view": "6.0.1",
"react-native-paper": "^4.12.0",
"react-native-safe-area-context": "4.4.1",
"react-native-screens": "~3.18.0",
"react-native-tab-view": "^3.1.1",
"react-native-vector-icons": "^9.1.0",
"react-native-web": "~0.18.10"
},
"devDependencies": {
"@babel/core": "^7.12.9",
"@types/react": "~18.0.27",
"@types/react-native": "~0.64.12",
"typescript": "^4.9.4"
},
"private": true
}

schema.graphql:

enum TransportationModes {
DRIVING
BICYCLING
}

type Courier @model @auth(rules: [{allow: public}]) {
id: ID!
name: String!
sub: String!
lat: Float
lng: Float
transportationMode: TransportationModes!
}

type Basket @model @auth(rules: [{allow: public}]) {
id: ID!
BasketDishes: [BasketDish] @hasMany(indexName: "byBasket", fields: ["id"])
userID: ID! @index(name: "byUser")
restaurantID: ID! @index(name: "byRestaurant")
}

enum OrderStatus {
NEW
COOKING
READY_FOR_PICKUP
PICKED_UP
COMPLETED
ACCEPTED
}

type OrderDish @model @auth(rules: [{allow: public}]) {
id: ID!
quantity: Int!
Dish: Dish @hasOne
orderID: ID! @index(name: "byOrder")
}

type Order @model @auth(rules: [{allow: public}]) {
id: ID!
userID: ID! @index(name: "byUser")
Restaurant: Restaurant @hasOne
total: Float!
status: OrderStatus!
OrderDishes: [OrderDish] @hasMany(indexName: "byOrder", fields: ["id"])
Courier: Courier @hasOne
}

type BasketDish @model @auth(rules: [{allow: public}]) {
id: ID!
quantity: Int!
Dish: Dish @hasOne
basketID: ID! @index(name: "byBasket")
}

type User @model @auth(rules: [{allow: public}]) {
id: ID!
name: String!
address: String!
lat: Float!
lng: Float!
Orders: [Order] @hasMany(indexName: "byUser", fields: ["id"])
Baskets: [Basket] @hasMany(indexName: "byUser", fields: ["id"])
sub: String!
}

type Dish @model @auth(rules: [{allow: public}]) {
id: ID!
name: String!
image: String
description: String
price: Float!
restaurantID: ID! @index(name: "byRestaurant")
}

type Restaurant @model @auth(rules: [{allow: public}]) {
id: ID!
name: String!
image: String!
deliveryFee: Float!
minDeliveryTime: Int!
maxDeliveryTime: Int!
rating: Float
address: String!
lat: Float!
lng: Float!
Dishes: [Dish] @hasMany(indexName: "byRestaurant", fields: ["id"])
Baskets: [Basket] @hasMany(indexName: "byRestaurant", fields: ["id"])
}
````
Thank you for your help!

最佳答案

我最终能够通过将我的放大版本降级到"@aws-amplify/cli/@12.0.0来解决这个问题。 .

首先,我使用 npm uninstall -g @aws-amplify/cli 卸载了当前版本。然后重新安装旧版本npm install -g @aws-amplify/<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a9cac5c0e9989b87998799" rel="noreferrer noopener nofollow">[email protected]</a> .

我还遵循了 amplify page 上的建议上面说使用 openjdk 16.0.1。 java 版本本身并没有解决问题 - 但同时拥有这个版本的 jdk 和这个版本的 amplify-cli 我无法成功模拟。

关于react-native - 在 React Native 项目中向 Amplify API 添加模拟时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76657098/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com