diff --git a/docs/changelog.md b/docs/changelog.md index 2ab1c66c..0fd6359a 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -56,4 +56,5 @@ ## master - bugfix: make non-default args non-null in UDFs +- bugfix: default value of a string type argument in a UDF was wrapped in single quotes - feature: add support for array types in UDFs diff --git a/docs/functions.md b/docs/functions.md index 9500aae8..d3031627 100644 --- a/docs/functions.md +++ b/docs/functions.md @@ -18,7 +18,7 @@ For example, a function to add two numbers will be available on the query type a ```graphql type Query { - addNums(a: Int, b: Int): Int + addNums(a: Int!, b: Int!): Int } ``` @@ -62,7 +62,7 @@ Functions marked `immutable` or `stable` are available on the query type. Functi ```graphql type Mutation { - addAccount(email: String): Int + addAccount(email: String!): Int } ``` @@ -110,11 +110,11 @@ Built-in GraphQL scalar types `Int`, `Float`, `String`, `Boolean` and [custom sc as $$ select id, email from account where id = "accountId"; $$; ``` -=== "MutationType" +=== "QueryType" ```graphql - type Mutation { - addAccount(email: String): Int + type Query { + accountById(email: String!): Account } ``` @@ -161,7 +161,7 @@ Since Postgres considers a row/composite type containing only null values to be (2, 'bat@x.com', null), (null, null, null); - create function returns_account_with_all_null_columns() + create function "returnsAccountWithAllNullColumns"() returns account language sql stable as $$ select id, email, name from account where id is null; $$; ``` @@ -217,7 +217,7 @@ Functions returning multiple rows of a table or view are exposed as [collections ```graphql type Query { accountsByEmail( - emailToSearch: String + emailToSearch: String! """Query the first `n` records in the collection""" first: Int @@ -414,7 +414,6 @@ Functions with default arguments can have their default arguments omitted. The following features are not yet supported. Any function using these features is not exposed in the API: -* Functions that return a record type * Functions that accept a table's tuple type * Overloaded functions * Functions with a nameless argument diff --git a/src/sql_types.rs b/src/sql_types.rs index 83b6c004..f1c553d7 100644 --- a/src/sql_types.rs +++ b/src/sql_types.rs @@ -259,7 +259,7 @@ impl<'a> ArgsIterator<'a> { 25 => trimmed .strip_suffix("::text") .to_owned() - .map(|i| i.trim_matches(',').to_string()), + .map(|i| i.trim_matches(',').trim_matches('\'').to_string()), _ => None, } } diff --git a/test/expected/function_calls.out b/test/expected/function_calls.out index a7e1b0bd..284ebe70 100644 --- a/test/expected/function_calls.out +++ b/test/expected/function_calls.out @@ -2436,7 +2436,7 @@ begin; "name": "String", + "ofType": null + }, + - "defaultValue": "'hello'"+ + "defaultValue": "hello" + } + ], + "name": "funcWithDefaults" +