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
1
@graphql(<JSON>)
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
1234
createtable"BlogPost"(idintprimarykey,...);
results in GraphQL type names like
1234
BlogPost
BlogPostEdge
BlogPostConnection
...
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 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 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.
1234567
typeBlogPostConnection{
edges: [BlogPostEdge!]!
pageInfo: PageInfo!"""The total number of records matching the `filter` criteria"""
totalCount: Int!# this field}
to enable totalCount for a table, use the directive
Tables, Columns, and Functions accept a description directive to populate user defined descriptions in the GraphQL schema.
123456789
createtable"Account"(idserialprimarykey);commentontablepublic.accountise'@graphql({"description": "A User Account"})';commentoncolumnpublic.account.idise'@graphql({"description": "The primary key identifier"})';
123456
"""A User Account"""typeAccountimplementsNode{"""The primary key identifier"""
id: Int!}
Enum Variant
If a variant of a Postgres enum does not conform to GraphQL naming conventions, introspection returns an error:
For example:
1
createtype"Algorithm"asenum('aead-ietf');
causes the error:
1234567
{"errors":[{"message":"Names must only contain [_a-zA-Z0-9] but \"aead-ietf\" does not.",}]}
To resolve this problem, rename the invalid SQL enum variant to a GraphQL compatible name: