Mapping of GraphQL Schema to Relational Schema - LiUGraphQL/LinGBM GitHub Wiki

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

The general approach adopted to create the initial sketch of the LinGBM GraphQL schema is based on the following four rules.

  1. For every table in the database schema (except for the tables CoAuthorOfPublication, GraduateStudentTakeCourse and UndergraduateStudentTakeCourse), create an object type in the GraphQL schema; the name of this object type is the same as the name of the table.
  2. For every attribute in these tables, create a field in the corresponding object type; the name of this field is the same as the name of the attribute and the type of the field resembles the domain (datatype) of the attribute.
  3. For an attribute that is a foreign key into some other table, the type of the corresponding field has to be the object type for the table referenced by the foreign key. Additionally, that object type (for the table referenced by the foreign key) is extended with another field to follow the foreign key in the reverse direction (i.e., back to the object type for the table that contains the foreign key); the type of this field is a list type that wraps the object type for the table containing the foreign key.
  4. The many-to-many relationship tables CoAuthorOfPublication GraduateStudentTakeCourse and UndergraduateStudentTakeCourse are captured in a similar manner by adding cross-reference fields in the corresponding object types.

The Mapping in Detail

Mapping of University Objects

Relevant part of the GraphQL schema:

type University  
{ 
  id: ID! 
  undergraduateDegreeFromObtainedByFaculty: [Faculty] 
  mastergraduateDegreeObtainers: [Faculty]
  doctoralDegreeObtainers: [Faculty]
  undergraduateDegreeFromObtainedBystudent: [GraduateStudent]
  departments: [Department] 
} 

Relevant parts of the relational schema:

university (nr)
faculty (nr, telephone, emailAddress, undergraduateDegreeFrom, masterDegreeFrom, doctoralDegreeFrom, worksFor)
graduateStudent (nr, telephone, emailAddress, age, undergraduateDegreeFrom, advisor, memberOf)
department (nr, subOrganizationOf)

Mapping:

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

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

  • The value of the undergraduateDegreeFromObtainedByFaculty field is an array containing each Faculty object (created as described for the Faculty type) whose corresponding row in the faculty table has the nr attribute of this University as its 'undergraduateDegreeFrom' attribute value.

  • The value of the mastergraduateDegreeObtainers field is an array containing each Faculty object (created as described for the Faculty type) whose corresponding row in the faculty table has the nr attribute of this University as its 'masterDegreeFrom' attribute value.

  • The value of the doctoralDegreeObtainers field is an array containing each Faculty object (created as described for the Faculty type) whose corresponding row in the faculty table has the nr attribute of this University as its 'doctoralDegreeFrom' attribute value.

  • The value of the undergraduateDegreeFromObtainedBystudent field is an array containing each GraduateStudent object (created as described for the GraduateStudent type) whose corresponding row in the graduateStudent table has the nr attribute of this University as its 'undergraduateDegreeFrom' attribute value.

  • The value of the departments field is an array containing each Department object (created as described for the Department type) whose corresponding row in the department table has the nr attribute of this University as its 'subOrganizationOf' attribute value.

Mapping of Faculty Objects

Relevant part of the GraphQL schema:

interface Faculty  
{ 
  id: ID! 
  telephone: String 
  emailAddress: String 
  undergraduteDegreeFrom: University 
  masterDegreeFrom: University 
  doctoralDegreeFrom: University 
  worksFor: Department 
  teacherOfGraduateCourses: [GraduateCourse] 
  teacherOfUndergraduateCourses: [UndergraduateCourse] 
  publications: [Publication] 
} 

Relevant parts of the relational schema:

faculty (nr, telephone, emailAddress, undergraduateDegreeFrom, masterDegreeFrom, doctoralDegreeFrom, worksFor)
university (nr)
department (nr, subOrganizationOf)
undergraduateCourse (nr, teacher, teachingAssistant)
graduateCourse (nr, teacher)
publication (nr, title, abstract, mainAuthor)

Mapping:

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

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

  • The value of the field telephone is the value of the attribute telephone that the corresponding row has in the table faculty;

  • The value of the field emailAddress is the value of the attribute emailAddress that the corresponding row has in the table faculty;

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

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

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

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

  • The value of the teacherOfGraduateCourses field is an array containing each GraduateCourse object (created as described for the GraduateCourse type) whose corresponding row in the graduateCourse table has the nr attribute of this University as its 'teacher' attribute value.

  • The value of the teacherOfUndergraduateCourses field is an array containing each UndergraduateCourse object (created as described for the UndergraduateCourse type) whose corresponding row in the undergraduateCourse table has the nr attribute of this University as its 'teacher' attribute value.

  • The value of the publications field is an array containing each Publication object (created as described for the Publication type) whose corresponding row in the publication table has the nr attribute of this University as its 'mainAuthor' attribute value.

Mapping of Department Objects

Relevant part of the GraphQL schema:

type Department  
{ 
  id: ID! 
  subOrganizationOf: University 
  head: Professor 
  researchGroups: [ResearchGroup] 
  faculties: [Faculty] 
  professors: [Professor]
  lecturers: [Lecturer]
  graduateStudents: [GraduateStudent] 
  undergraduateStudents: [UndergraduateStudent] 
}

Relevant parts of the relational schema:

department (nr, subOrganizationOf)
university (nr)
researchGroup (nr, subOrganizationOf)
faculty (nr, telephone, emailAddress, undergraduateDegreeFrom, masterDegreeFrom, doctoralDegreeFrom, worksFor)
professor (nr, professorType, researchInterest, headOf)
lecturer (nr)
graduateStudent (nr, telephone, emailAddress, age, undergraduateDegreeFrom, advisor, memberOf)
undergraduateStudent (nr, telephone, emailAddress, age, advisor, memberOf)

Mapping:

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

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

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

  • The value of the field head is the value of the Professor object (created as described for the University type) whose corresponding row in the professor table has the headOf attribute, whose values is the same as the 'nr' attribute value of this Department.

  • The value of the researchGroups field is an array containing each ResearchGroup object (created as described for the ResearchGroup type) whose corresponding row in the researchGroup table has the nr attribute of this Department as its 'subOrganizationOf' attribute values.

  • The value of the faculties field is an array containing each Faculty object (created as described for the Faculty type) whose corresponding row in the faculty table has the nr attribute of this Department as its 'worksFor' attribute values.

  • The value of the professors field is an array containing each Professor object (created as described for the Professor type) whose corresponding row in the professor table has the same nr attribute value as corresponding faculty table, where the corresponding faculty has the nr attribute of this Department as its 'worksFor' attribute values.

  • The value of the lecturers field is an array containing each Lecturer object (created as described for the Lecturer type) whose corresponding row in the lecturer table has the same nr attribute value as corresponding faculty table, where the corresponding faculty has the nr attribute of this Department as its 'worksFor' attribute values.

  • The value of the graduateStudents field is an array containing each GraduateStudent object (created as described for the GraduateStudent type) whose corresponding row in the graduateStudent table has the nr attribute of this Department as its 'memberOf' attribute values.

  • The value of the undergraduateStudents field is an array containing each UndergraduateStudent object (created as described for the UndergraduateStudent type) whose corresponding row in the undergraduateStudent table has the nr attribute of this Department as its 'memberOf' attribute values.

Mapping of ResearchGroup Objects

Relevant part of the GraphQL schema:

type ResearchGroup  
{ 
  id: ID! 
  subOrgnizationOf: Department 
} 

Relevant parts of the relational schema:

researchGroup (nr, subOrganizationOf)
department (nr, subOrganizationOf)

Mapping:

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

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

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

Mapping of Author Objects

Relevant part of the GraphQL schema:

interface Author  
{ 
  id: ID! 
  telephone: String 
  emailAddress: String
} 

Relevant parts of the relational schema:

faculty (nr, telephone, emailAddress, undergraduateDegreeFrom, masterDegreeFrom, doctoralDegreeFrom, worksFor)
graduateStudent (nr, telephone, emailAddress, age, undergraduateDegreeFrom, advisor, memberOf)
publication (nr, title, abstract, mainAuthor)

Mapping:


Mapping of Professor Objects

Relevant part of the GraphQL schema:

type Professor implements Faculty & Author
{ 
  id: ID! 
  telephone: String 
  emailAddress: String 
  researchInterest: String 
  profType: String
  undergraduateDegreeFrom: University 
  masterDegreeFrom: University 
  doctoralDegreeFrom: University 
  worksFor: Department 
  teacherOfGraduateCourses: [GraduateCourse] 
  teacherOfUndergraduateCourses: [UndergraduateCourse]
  publications(order: PublicationSortCriterion): [Publication]
  supervisedUndergraduateStudents: [UndergraduateStudent] 
  supervisedGraduateStudents: [GraduateStudent]
} 

Relevant parts of the relational schema:

professor (nr, professorType, researchInterest, headOf)
faculty (nr, telephone, emailAddress, undergraduateDegreeFrom, masterDegreeFrom, doctoralDegreeFrom, worksFor)
university (nr)
department (nr, subOrganizationOf)
undergraduateCourse (nr, teacher, teachingAssistant)
graduateCourse (nr, teacher)
graduateStudent (nr, telephone, emailAddress, age, undergraduateDegreeFrom, advisor, memberOf)
undergraduateStudent (nr, telephone, emailAddress, age, advisor, memberOf)
publication (nr, title, abstract, mainAuthor)

Mapping:


Mapping of Lecturer Objects

Relevant part of the GraphQL schema:

type Lecturer implements Faculty & Author 
{ 
  id: ID! 
  telephone: String 
  emailAddress: String 
  position: String
  undergraduateDegreeFrom: University 
  masterDegreeFrom: University 
  doctoralDegreeFrom: University 
  worksFor: Department 
  teacherOfGraduateCourses: [GraduateCourse] 
  teacherOfUndergraduateCourses: [UndergraduateCourse] 
  publications: [Publication] 
}

Relevant parts of the relational schema:

lecturer (nr)
faculty (nr, telephone, emailAddress, undergraduateDegreeFrom, masterDegreeFrom, doctoralDegreeFrom, worksFor)
university (nr)
department (nr, subOrganizationOf)
undergraduateCourse (nr, teacher, teachingAssistant)
graduateCourse (nr, teacher)
publication (nr, title, abstract, mainAuthor)

Mapping:


Mapping of Publication Objects

Relevant part of the GraphQL schema:

type Publication  
{ 
  id: ID! 
  title: String 
  abstract: String 
  authors: [Author] 
} 

Relevant parts of the relational schema:

publication (nr, title, abstract, mainAuthor)
faculty (nr, telephone, emailAddress, undergraduateDegreeFrom, masterDegreeFrom, doctoralDegreeFrom, worksFor)
graduateStudent (nr, telephone, emailAddress, age, undergraduateDegreeFrom, advisor, memberOf)

Mapping:


Mapping of GraduateStudent Objects

Relevant part of the GraphQL schema:

type GraduateStudent implements Author 
{ 
  id: ID! 
  telephone: String 
  emailAddress: String 
  age: Int
  memberOf: Department 
  undergraduateDegreeFrom: University 
  advisor: Professor 
  takeGraduateCourses: [GraduateCourse] 
  assistCourses: [UndergraduateCourse] 
}  

Relevant parts of the relational schema:

graduateStudent (nr, telephone, emailAddress, age, undergraduateDegreeFrom, advisor, memberOf)
department (nr, subOrganizationOf)
university (nr)
professor (nr, professorType, researchInterest, headOf)
undergraduateCourse (nr, teacher, teachingAssistant)
graduateCourse (nr, teacher)

Mapping:


Mapping of UndergraduateStudent Objects

Relevant part of the GraphQL schema:

type UndergraduateStudent  
{ 
  id: ID! 
  telephone: String 
  emailAddress: String 
  age: Int
  memberOf: Department 
  advisor: Professor 
  takeCourses: [UndergraduateCourse] 
}  

Relevant parts of the relational schema:

undergraduateStudent (nr, telephone, emailAddress, age, advisor, memberOf)
department (nr, subOrganizationOf)
professor (nr, professorType, researchInterest, headOf)
undergraduateCourse (nr, teacher, teachingAssistant)

Mapping:


Mapping of GraduateCourse Objects

Relevant part of the GraphQL schema:

type GraduateCourse  
{ 
  id: ID! 
  teachedby: Faculty 
  graduateStudents: [GraduateStudent] 
} 

Relevant parts of the relational schema:

graduateCourse (nr, teacher)
faculty (nr, telephone, emailAddress, undergraduateDegreeFrom, masterDegreeFrom, doctoralDegreeFrom, worksFor)
graduateStudent (nr, telephone, emailAddress, age, undergraduateDegreeFrom, advisor, memberOf)

Mapping:


Mapping of UndergraduateCourse Objects

Relevant part of the GraphQL schema:

type UndergraduateCourse  
{ 
  id: ID! 
  teachedby: Faculty 
  undergraduateStudents: [UndergraduateStudent] 
  teachingAssistants: GraduateStudent 
} 

Relevant parts of the relational schema:

undergraduateCourse (nr, teacher, teachingAssistant)
faculty (nr, telephone, emailAddress, undergraduateDegreeFrom, masterDegreeFrom, doctoralDegreeFrom, worksFor)
undergraduateStudent (nr, telephone, emailAddress, age, advisor, memberOf)
graduateStudent (nr, telephone, emailAddress, age, undergraduateDegreeFrom, advisor, memberOf)

Mapping:

⚠️ **GitHub.com Fallback** ⚠️