'Problem with setting up API connection with AWS Amplify
I am currently developing an eCommerce App in React Native Expo that utilizes AWS amplify and I am trying to connect the API and database to it.
After running 'amplify push', I get the following error message:
� An error occurred during the push operation: Unknown directive 'connection'. Either remove the directive from the schema or add a transformer to handle it.
For some reason, it doesn't recognize @connection as its own directive.
The block of code in the schema.graphql that utilizes this directive is the following:
type CartProduct @model @auth(rules: [{allow: public}]){
id: ID!
userSub: String!
quantity: Int!
option: String
productID: ID!
product: Product @connection(fields: ["productID"])
}
I haven't found a solution anywhere and I appreciate anyone who can help me with this.
Solution 1:[1]
This github issue in the aws-amplify repo helped me solve a similar error. The gist of the problem is the graphql transformer version that interprets the schema definition was upgraded to v2 and the @key and @connection directives are in a version 1 directives.
For version 2 I used @hasMany and @hasOne directives.
type PurchaseOrder @model @auth(rules: [{ allow: owner }]) {
id: ID!
poNumber: String
dateOrdered: AWSDateTime
dateRequested: AWSDateTime
dateReceived: AWSDateTime
notes: String
subtotal: Float
taxRate: Float
salesTax: Float
priceAdjustment: Float
discount: Float
total: Float
requestor: String
paymentTerms: String
shipping: Float
comments: String
billingAddress: Address @hasOne
shippingAddress: Address @hasOne
shippingInformation: String
customerId: String
createdAt: AWSDateTime!
updatedAt: AWSDateTime!
poItems: [PoItem] @hasMany
attachments: [Attachment] @hasMany
vendorID: ID!
vendor: Vendor @hasOne
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Brayton Stafford |
