Back to Graphql Engine

BigQuery: Relationships between Tables/Views

docs/docs/schema/bigquery/table-relationships/index.mdx

2.48.163.2 KB
Original Source

BigQuery: Relationships between Tables/Views

Introduction

<!-- TODO: nested object query docs https://github.com/hasura/graphql-engine-mono/issues/4458 --> <!-- To make [nested object queries](/), the tables/views in your database need to be connected via relationships. -->

Let's say we have the following tables in our database: authors, passport_infos, articles and tags.

Table relationships

The tables/views in any relational database are typically related to each other via one of the following types of table relationships:

TypeExampleMeaning
one-to-oneowner and passport_infos<ul><li> an owner can have one passport_info </li><li> a passport_info can have one owner </li></ul>
one-to-manyauthors and articles<ul><li> an author can have many articles </li><li> an article can have one author </li></ul>
many-to-manyarticles and tags<ul><li> an article can have many tags </li><li> a tag can have many articles </li></ul>

GraphQL schema relationships {#pg-graphql-relationships}

Each table relationship, as you can see from the above section, will have two component relationships (one in either direction) in the GraphQL schema. These relationships can be one of the following types:

TypeExampleMeaning
object relationship (one-to-one)an article can have one authoran article object will have a single nested author object called author
array relationship (one-to-many)an author can have many articlesan author object will have an array of nested article objects called articles

:::info Note

The relationship name is used to refer to the nested objects in queries. For example, "articles" of an author and "author" of an article.

:::

Managing GraphQL relationships

See the following to manage the object/array relationships between tables/views for the GraphQL schema:

<!-- TODO: BigQuery data modeling guide https://github.com/hasura/graphql-engine-mono/issues/4937 --> <!-- ## Table relationships modeling guides The following guides will help you model the different types of table relationships in the database: - [Modeling one-to-one table relationships](/schema/common-patterns/data-modeling/one-to-one.mdx) - [Modeling one-to-many table relationships](/schema/common-patterns/data-modeling/one-to-many.mdx) - [Modeling many-to-many table relationships](/schema/common-patterns/data-modeling/many-to-many.mdx) -->