Configuration & Customization
Extra configuration options can be set on SQL entities using comment directives.
Extra configuration options can be set on SQL entities using comment directives.
Comment Directives
Comment directives are snippets of configuration associated with SQL entities that alter how those entities behave.
The format of a comment directive is
Inflection
Inflection describes how SQL entities' names are transformed into GraphQL type and field names. By default, inflection is disabled and SQL names are literally interpolated such that
results in GraphQL type names like
Since snake case is a common casing structure for SQL types, pg_graphql
support basic inflection from snake_case
to PascalCase
for type names, and snake_case
to camelCase
for field names to match Javascript conventions.
The inflection directive can be applied at the schema level with:
for example
similarly would generated the GraphQL type names
For more fine grained adjustments to reflected names, see renaming.
Max Rows
The default page size for collections is 30 entries. To adjust the number of entries on each page, set a max_rows
directive on the relevant schema entity.
For example, to increase the max rows per page for each table in the public
schema:
totalCount
totalCount
is an opt-in field that extends a table's Connection type. It provides a count of the rows that match the query's filters, and ignores pagination arguments.
to enable totalCount
for a table, use the directive
for example
Renaming
Table's Type
Use the "name"
JSON key to override a table's type name.
results in:
Column's Field Name
Use the "name"
JSON key to override a column's field name.
results in:
Computed Field
Use the "name"
JSON key to override a computed field's name.
results in:
Relationship's Field
Use the "local_name"
and "foreign_name"
JSON keys to override a relationship's inbound and outbound field names.
results in:
Description
Tables, Columns, and Functions accept a description
directive to populate user defined descriptions in the GraphQL schema.
Enum Variant
If a variant of a Postgres enum does not conform to GraphQL naming conventions, introspection returns an error:
For example:
causes the error:
To resolve this problem, rename the invalid SQL enum variant to a GraphQL compatible name:
or, add a comment directive to remap the enum variant in the GraphQL API
Which both result in the GraphQL enum: