When I write a function in Postgresql I can add strict resulting in all parameters being required in Graphql (!), without strict all parameters are optional.
On required fields in the non strict function I can throw exceptions or simply return null without executing the function like the strict function would do when the parameter is null. But how can I tell Postgraphile which parameters are required? Via a comment or something, or marking parameters which have a default as optional.
On my search I found this question asked here, and especially this answer. The answer I found in quote:
This functionality is implemented in graphile-build-pg via the pgStrictFunctions setting, but this isn't currently exposed via postgraphile-core to PostGraphQL itself. What it does is treats all functions as strict, requiring all arguments to be marked as required unless they have defaults.
It is possible to mark an argument as default null, but of course a strict function with a null default will automatically return null without being called.
create function a(b int, c int default null)
returns int as $$
select b;
$$ language sql stable;
By default neither b nor c will be required, but with pgStrictFunctions set b will be marked as required (but c will not).
While it mentions a solution it does not state how to implement it. Searching the entire project (including node_modules) for 'pgStrictFunctions' did not give any clues either. How to implement I finally found on discord, this is how I finally got it working:
@Module({
controllers: [],
imports: [
PostGraphileModule.forRoot({
......
graphileBuildOptions: {
pgStrictFunctions: true,
},
......
}),
],
providers: [GraphQLService],
})