Views
Using Postgres Views with GraphQL.
Views, materialized views, and foreign tables can be exposed with pg_graphql.
Primary Keys (Required)
A primary key is required for an entity to be reflected in the GraphQL schema. Tables can define primary keys with SQL DDL, but primary keys are not available for views, materialized views, or foreign tables. For those entities, you can set a "fake" primary key with a comment directive.
For example:
tells pg_graphql to treat "Person".id
as the primary key for the Person
entity resulting in the following GraphQL type:
ID!
types, sorting, and pagination.Updatable views are reflected in the Query
and Mutation
types identically to tables. Non-updatable views are read-only and accessible via the Query
type only.
Relationships
pg_graphql identifies relationships among entities by inspecting foreign keys. Views, materialized views, and foreign tables do not support foreign keys. For this reason, relationships can also be defined in comment directive using the structure:
For example:
defines a relationship equivalent to the following foreign key
yielding the GraphQL types: