Skip to content

Mapping of GraphQL Schema to Relational Schema

Olaf Hartig edited this page Aug 14, 2019 · 7 revisions

This document provides an informal definition of how the elements of the LinGBM GraphQL schema map to the database schema of the benchmark dataset.

When designing the LinGBM GraphQL schema, we first have created an initial sketch of this schema that closely resembles the database schema. Thereafter, we have extended this initial version with additional fields and types that we needed to define the query workloads of the benchmark.

In the following we first outline the general approach adopted to create the initial sketch of the LinGBM GraphQL schema. Thereafter, we define the mapping in detail by focusing on the object types of the schema, one after another.


Table of Contents

  1. General Idea
  2. The Mapping in Detail

General Idea

1. Map Tables of Relational Models using Object Type

The object types of GraphQL schema map to the tables of Relational Models. That is, for every table in the relational model, there must exist an object type in the GrphQL schema whose the name is the same as the name of the table.

2. Map attributes of Relational tables using Field

The attributes of the table could be mapped as fields of corresponding Object Type of GraphQL schema. If the attribute value is a scalar type or an enumeration type, then the type of field must be of that type; If the attribute is a non-nullable value, then the type of field is a non-nullable type.

3. Map relationship of Relational Models using Feild

The relationship of the table can also be mapped as fields of the corresponding table. If the cardinality ratio is 1 to N, then the type of field is a list type (wrapping an object type). If the cardinality is X (could be 1 or N) to 1, then the type of field is an object type. If the relationship is a participation constraint, then the type of the field must be a non-nullable type.

The Mapping in Detail

Mapping of Vendor Objects

GraphQL schema:

type Vendor {
  nr: ID!
  label: String
  comment: String
  homepage: String
  country: Country
  publisher: Int
  publishDate: Date
  offers: [Offer]
}

scalar Date

relational schema:

Vendor (nr, label, comment, homepage, country, publisher, publishDate)
Offer (nr, product, producer, vendor, price, validFrom, validTo, deliveryDays, offerWebpage, publisher, publishDate)

Mapping:

The object type Vendor in the GraphQL schema corresponds to the table Vendor in the relational model. That is, for every row in the Vendor table, there exists an object of type Vendor. For this object, the values of its fields are determined as follows:

  • The value of the field nr is the value of the attribute nr that the corresponding row has in the table Vendor;

  • The value of the field label is the value of the attribute label that corresponding row has in the table Vendor;

  • The value of the field comment is the value of the attribute comment that corresponding row has in the table Vendor;

  • The value of the field homepage is the value of the attribute homepage that corresponding row has in the table Vendor;

  • The value of the field country is the value of the attribute country that corresponding row has in the table Vendor;

  • The value of the field publisher is the value of the attribute publisher that corresponding row has in the table Vendor;

  • The value of the field publishDate is the value of the attribute publishDate that corresponding row has in the table Vendor;

  • The value of the offers field is an array containing each Offer object (created as described for the Offer type) whose corresponding row in the Offers table has the nr attribute of this vendor as its 'vendor' attribute value.

Mapping of Offer Objects

GraphQL schema:

type Offer {
  nr: ID!
  price: Float
  validFrom: String
  validTo: String
  deliveryDays: Int
  offerWebpage: String
  product: Product
  vendor: Vendor
}

relational schema:

Offer (nr, product, producer, vendor, price, validFrom, validTo, deliveryDays, offerWebpage, publisher, publishDate)

Vendor (nr, label, comment, homepage, country, publisher, publishDate)
Product (nr, label, comment, producer, propertyNum1, propertyNum2, propertyNum3, propertyNum4, propertyNum5, propertyNum6, propertyTex1, propertyTex2, propertyTex3, propertyTex4, propertyTex5, propertyTex6, publisher, publishDate)

Mapping:

The object type Offer in the GraphQL schema corresponds to the table Offer in the relational model. That is, for every row in the Offer table, there exists an object of type Offer. For this object, the values of its fields are determined as follows:

  • The value of the field nr is the value of the attribute nr that the corresponding row has in the table Offer;

  • The value of the field price is the value of the attribute nr that the corresponding row has in the table Offer;

  • The value of the field validFrom is the value of the attribute nr that the corresponding row has in the table Offer;

  • The value of the field validTo is the value of the attribute nr that the corresponding row has in the table Offer;

  • The value of the field deliveryDays is the value of the attribute nr that the corresponding row has in the table Offer;

  • The value of the field offerWebpage is the value of the attribute nr that the corresponding row has in the table Offer;

  • The value of the field product is the value of the Product object (created as described for the Product type) whose corresponding row in the Product table has the nr attribute, whose value is the same as the 'product' attribute value of this Offer.

  • The value of the field vendor is the value of the Vendor object (created as described for the Vendor type) whose corresponding row in the Vendor table has the nr attribute, whose value is the same as the 'vendor' attribute value of this Offer.

Mapping of Product Objects

GraphQL schema:

type Product {
  nr: ID!
  label: String
  comment: String
  offers: [Offer]
  producer: Producer
  type: ProductType
  productFeature: [ProductFeature] 
  reviews: [Review]
}

relational schema:

Product (nr, label, comment, producer, propertyNum1, propertyNum2, propertyNum3, propertyNum4, propertyNum5, propertyNum6, propertyTex1, propertyTex2, propertyTex3, propertyTex4, propertyTex5, propertyTex6, publisher, publishDate)

Offer (nr, product, producer, vendor, price, validFrom, validTo, deliveryDays, offerWebpage, publisher, publishDate)
Producer (nr, label, comment, homepage, country, publisher, publishDate)
ProductFeature (nr, label, comment, publisher, publishDate)
ProductFeatureProduct (product, productFeature)
ProductType (nr, label, comment, parent, publisher, publishDate)
ProductTypeProduct (product, productType)
Review (nr, product, producer, person, reviewDate, title, text, language, rating1, rating2, rating3, rating4, publisher, publishDate, ratingSite)

Mapping:

The object type Product in the GraphQL schema corresponds to the table Product in the relational model. That is, for every row in the Product table, there exists an object of type Product. For this object, the values of its fields are determined as follows:

  • The value of the field nr is the value of the attribute nr that the corresponding row has in the table Product;

  • The value of the field label is the value of the attribute label that the corresponding row has in the table Product;

  • The value of the field comment is the value of the attribute comment that the corresponding row has in the table Product;

  • The value of the offers field is an array containing each Offer object (created as described for the Offer type) whose corresponding row in the Offer table has the nr attribute of this product as its 'product' attribute value.

  • The value of the field producer is the value of the Producer object (created as described for the Producer type) whose corresponding row in the Producer table has nr attribute, whose value is the same as the 'producer' attribute value of this product.

  • The value of the field type is the value of the ProductType object (created as described for the ProductType type) whose corresponding row in the ProductType table has the nr attribute, whose value is the value of the attribute 'productType' that the corresponding row has in the table ProductTypeProduct, where the corresponding row in the ProductTypeProduct table has the nr attribute of this Product as its 'product' attribute value.

  • The value of the field productFeature is an array containing each ProductFeature object (created as described for the ProductFeature type) whose corresponding row in the ProductFeature table has the nr attribute, whose value is the value of the attribute 'productFeature' that the corresponding row has in the table ProductFeatureProduct, where the corresponding row in the ProductFeatureProduct table has the nr attribute of this product as its 'product' attribute value.

  • The value of the reviews field is an array containing each Review object (created as des cribed for the Review type) whose corresponding row in the Review table has the nr attribute of this product as its 'product' attribute value.

Mapping of ProductType Objects

ProductType(nr, label, comment, parent, publisher, publishDate)

GraphQL schema:

type ProductType {
  nr: ID!
  label: String
  comment: String
  parent: ProductType
  products: [Product]
}

relational schema:

ProductType (nr, label, comment, parent, publisher, publishDate)

Product (nr, label, comment, producer, propertyNum1, propertyNum2, propertyNum3, propertyNum4, propertyNum5, propertyNum6, propertyTex1, propertyTex2, propertyTex3, propertyTex4, propertyTex5, propertyTex6, publisher, publishDate)
ProductTypeProduct (product, productType)

Mapping:

The object type ProductType in the GraphQL schema corresponds to the table ProductType in the relational model. That is, for every row in the ProductType table, there exists an object of type ProductType. For this object, the values of its fields are determined as follows:

  • The value of the field nr is the value of the attribute nr that the corresponding row has in the table ProductType;

  • The value of the field label is the value of the attribute label that the corresponding row has in the table ProductType;

  • The value of the field comment is the value of the attribute comment that the corresponding row has in the table ProductType;

  • The value of the field parent is the value of the ProductType object (created as described for the parent type) whose corresponding row in the ProductType table has nr attribute, whose value is the same as the 'parent' attribute value of this ProductType.

  • The value of the field products is the value of the Product object (created as described for the Product type) whose corresponding row in the Product table has the nr attribute, whose value is the value of the attribute 'product' that the corresponding row has in the table ProductTypeProduct, where the corresponding row in the ProductTypeProduct table has the nr attribute of this ProductType as its 'ProductType' attribute value.

Mapping of ProductFeature Objects

GraphQL schema:

type ProductFeature {
  nr: ID!
  label: String
  comment: String
  products: [Product]
}

relational schema:

ProductFeature (nr, label, comment, publisher, publishDate)
Product (nr, label, comment, producer, propertyNum1, propertyNum2, propertyNum3, propertyNum4, propertyNum5, propertyNum6, propertyTex1, propertyTex2, propertyTex3, propertyTex4, propertyTex5, propertyTex6, publisher, publishDate)
ProductFeatureProduct (product, productFeature)

Mapping:

The object type ProductFeature in the GraphQL schema corresponds to the table ProductFeature in the relational model. That is, for every row in the ProductFeature table, there exists an object of type ProductFeature. For this object, the values of its fields are determined as follows:

  • The value of the field nr is the value of the attribute nr that the corresponding row has in the table ProductFeature;

  • The value of the field label is the value of the attribute label that the corresponding row has in the table ProductFeature;

  • The value of the field comment is the value of the attribute comment that the corresponding row has in the table ProductFeature;

  • The value of the field products is the value of the Product object (created as described for the Product type) whose corresponding row in the Product table has the nr attribute, whose value is the value of the attribute 'product' that the corresponding row has in the table ProductFeatureProduct, where the corresponding row in the ProductFeatureProduct table has the nr attribute of this ProductFeature as its 'productFeature' attribute value.

Mapping of Producer Objects

GraphQL schema:

type Producer {
  nr: ID!
  label: String
  comment: String
  homepage: String
  country: Country
  products: [Product]
}

relational schema:

Producer (nr, label, comment, homepage, country, publisher, publishDate)
Product (nr, label, comment, producer, propertyNum1, propertyNum2, propertyNum3, propertyNum4, propertyNum5, propertyNum6, propertyTex1, propertyTex2, propertyTex3, propertyTex4, propertyTex5, propertyTex6, publisher, publishDate)

Mapping:

The object type Producer in the GraphQL schema corresponds to the table Producer in the relational model. That is, for every row in the Producer table, there exists an object of type Producer. For this object, the values of its fields are determined as follows:

  • The value of the field nr is the value of the attribute nr that the corresponding row has in the table Producer;

  • The value of the field label is the value of the attribute label that the corresponding row has in the table Producer;

  • The value of the field comment is the value of the attribute comment that the corresponding row has in the table Producer;

  • The value of the field homepage is the value of the attribute homepage that the corresponding row has in the table Producer;

  • The value of the field country is the value of the attribute country that the corresponding row has in the table Producer;

  • The value of the products field is an array containing each Product object (created as described for the Product type) whose corresponding row in the Product table has the nr attribute of this producer as its 'producer' attribute value.

Mapping of Review Objects

GraphQL schema:

type Review{
  nr: ID!
  title: String
  text: String
  reviewDate: Date
  rating1: Int
  rating2: Int
  rating3: Int
  rating4: Int
  publishDate: Date
  reviewFor: Product
  reviewer: Person
}

relational schema:

Review (nr, product, producer, person, reviewDate, title, text, language, rating1, rating2, rating3, rating4, publisher, publishDate, ratingSite)
Product (nr, label, comment, producer, propertyNum1, propertyNum2, propertyNum3, propertyNum4, propertyNum5, propertyNum6, propertyTex1, propertyTex2, propertyTex3, propertyTex4, propertyTex5, propertyTex6, publisher, publishDate)
Person (nr, name, mbox_sha1sum, country, publisher, publishDate)

Mapping:

The object type Review in the GraphQL schema corresponds to the table Review in the relational model. That is, for every row in the Review table, there exists an object of type Review. For this object, the values of its fields are determined as follows:

  • The value of the field nr is the value of the attribute nr that the corresponding row has in the table Review;

  • The value of the field title is the value of the attribute title that the corresponding row has in the table Review;

  • The value of the field text is the value of the attribute text that the corresponding row has in the table Review;

  • The value of the field reviewDate is the value of the attribute reviewDate that the corresponding row has in the table Review;

  • The value of the field rating1 is the value of the attribute rating1 that the corresponding row has in the table Review;

  • The value of the field rating2 is the value of the attribute rating2 that the corresponding row has in the table Review;

  • The value of the field rating3 is the value of the attribute rating3 that the corresponding row has in the table Review;

  • The value of the field rating4 is the value of the attribute rating4 that the corresponding row has in the table Review;

  • The value of the field publishDate is the value of the attribute publishDate that the corresponding row has in the table Review;

  • The value of the field reviewFor is the value of the Product object (created as described for the Product type) whose corresponding row in the Product table has nr attribute, whose value is the same as the 'product' attribute value of this review.

  • The value of the field reviewer is the value of the Person object (created as described for the Person type) whose corresponding row in the Person table has nr attribute, whose value is the same as the 'person' attribute value of this review.

Mapping of Person Objects

GraphQL schema:

type Person {
  nr: ID!
  name: String
  mbox_sha1sum: String
  country: Country
  reviews: [Review]
}

relational schema:

Review (nr, product, producer, person, reviewDate, title, text, language, rating1, rating2, rating3, rating4, publisher, publishDate, ratingSite)
Person (nr, name, mbox_sha1sum, country, publisher, publishDate)

Mapping:

The object type Person in the GraphQL schema corresponds to the table Person in the relational model. That is, for every row in the Person table, there exists an object of type Person. For this object, the values of its fields are determined as follows:

  • The value of the field nr is the value of the attribute nr that the corresponding row has in the table Person;

  • The value of the field name is the value of the attribute name that the corresponding row has in the table Person;

  • The value of the field mbox_sha1sum is the value of the attribute mbox_sha1sum that the corresponding row has in the table Person;

  • The value of the field country is the value of the attribute country that the corresponding row has in the table Person;

  • The value of the reviews field is an array containing each Review object (created as described for the Review type) whose corresponding row in the Review table has the nr attribute of this person as its 'person' attribute value.

Clone this wiki locally