Functions marked immutable or stable are available on the query type. Functions marked with the default volatile category are available on the mutation type:
Built-in GraphQL scalar types Int, Float, String, Boolean and custom scalar types are supported as function arguments and return types. Function types returning a table or view are supported as well. Such functions implement the Node interface:
Since Postgres considers a row/composite type containing only null values to be null, the result can be a little surprising in this case. Instead of an object with all columns null, the top-level field is null:
typeQuery{accountsByEmail(
emailToSearch: String!"""Query the first `n` records in the collection"""
first: Int"""Query the last `n` records in the collection"""
last: Int"""Query values in the collection before the provided cursor"""
before: Cursor"""Query values in the collection after the provided cursor"""
after: Cursor"""Filters to apply to the results set when querying from the collection"""
filter: AccountFilter"""Sort order to apply to the collection"""
orderBy: [AccountOrderBy!]):AccountConnection}
A set returning function with any of its argument names clashing with argument names of a collection (first, last, before, after, filter, or orderBy) will not be exposed.
Functions accepting or returning arrays of non-composite types are also supported. In the following example, the ids array is used to filter rows from the Account table:
typeQuery{accountsByIds(
ids: Int[]!"""Query the first `n` records in the collection"""
first: Int"""Query the last `n` records in the collection"""
last: Int"""Query values in the collection before the provided cursor"""
before: Cursor"""Query values in the collection after the provided cursor"""
after: Cursor"""Filters to apply to the results set when querying from the collection"""
filter: AccountFilter"""Sort order to apply to the collection"""
orderBy: [AccountOrderBy!]):AccountConnection}
If there is no sensible default, and you still want to make the argument optional, consider using the default value null.
1 2 3 4 5 6 7 8 910111213141516171819202122
createfunction"addNums"(aintdefaultnull,bintdefaultnull)returnsintimmutablelanguageplpgsqlas$$beginifaisnullandbisnullthenraiseexception'a and b both can''t be null';endif;ifaisnullthenreturnb;endif;ifbisnullthenreturna;endif;returna+b;end;$$;
123
typeQuery{addNums(a:Int, b:Int):Int}
123
query{addNums(a:42)}
12345
{"data":{"addNums":42}}
Currently, null defaults are only supported as simple expressions, as shown in the previous example.
Limitations
The following features are not yet supported. Any function using these features is not exposed in the API:
Functions that accept a table's tuple type
Overloaded functions
Functions with a nameless argument
Functions returning void
Variadic functions
Functions that accept or return an array of composite type
Functions that accept or return an enum type or an array of enum type