0

In datamodel.graphql

type Ride {
 rideId: String
 productId: String
 passenger: Passenger
 origin: Origin
 destination: Destination
 dateTime: DateTime
 feedback: String
}


type Passenger {
 id: ID! @unique
 firstName: String
 lastName: String
}

type Destination {
 # The unique ID of the destination.
 id: ID! @unique
 latitude: Float
 longitude: Float
 address: String
}

type Origin {
 id: ID! @unique
 latitude: Float
 longitude: Float
 address: String
}


type Report {

 productId: String
 passenger: Passenger
 description: String
}

I deployed this data model and generates a MySql Db, auto queries, mutations with this.

It creates a "Ride", "Passenger", "Report" and "Origin" table in MySql. But it didn't create any column for passenger, origin, destination in "Ride" table.

It separates creates a relation table for this like _PassengerToRide, _OriginToRide, and _DestinationToRide.

Lack of relation establishment in "Ride" table, I couldn't get the details from Passenger, Origin and Destination tables when I query "rides()". Is this the correct way to define the datamodel.graphql. (edited)

John Davis
  • 413
  • 5
  • 12

1 Answers1

0

Based on your description, this query should "just work":

query {
  rides {
    feedback
    passenger {
      id
    }
    origin {
      id
    }
    destination {
      id
    }
  }
}

Prisma uses the relation table approach you mentioned to keep track if relations between two nodes, for example table _OriginToRide relates to relation @relation(name: "OriginToRide") from your datamodel.

You don't have to change anything on the SQL level to connect the relations afterwards.

Note: The above applies to Prisma database connectors with activated migrations. If your connector doesn't do migrations, different approaches to represent relations are supported. The respective datamodel to support this can be generated by introspecting your existing database schema.

marktani
  • 7,578
  • 6
  • 37
  • 60