Amplify GraphQL Transformer V2 vs V1

Relationship mapping/connection changes:

  • @hasOne creates a “one-to-one” relationship with the target model.
  • @hasMany creates a "one-to-many" relationship with the target model.
  • @belongsTo facilitates a bi-directional relationship between two models. For example, use the @belongsTo directive on a @hasMany-relationship’s target model to create a relationship back to the source model.
  • @manyToMany creates a new relationship cardinality for Amplify’s GraphQL Transformer.
type User @model @auth(rules: [{allow: public}]) {
id: ID!
username: String!
address: String!
email: String!
phone_number: String!
}

type Vehicle @model @auth(rules: [{allow: public}]) {
id: ID!
type: String!
latitude: Float,
longitude: Float,
isActive: Boolean
heading: Float,
userId: ID!
user: User @connection(fields: ["userId"])
}
type User @model @auth(rules: [{ allow: public }]) {
id: ID!
username: String!
address: String!
image: String
name: String
email: String!
given_name: String!
phone_number: String!
}

type Vehicle @model @auth(rules: [{ allow: public }]) {
id: ID!
type: String!
latitude: Float
longitude: Float
isActive: Boolean
heading: Float
userId: ID!
user: User @hasOne(fields: ["userId"])
}

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store