Skip to content

Commit cdb8868

Browse files
committed
update docs to explain function returning all null columns
1 parent 7eb6b56 commit cdb8868

File tree

1 file changed

+48
-1
lines changed

1 file changed

+48
-1
lines changed

docs/functions.md

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ Functions marked `immutable` or `stable` are available on the query type. Functi
8888
## Supported Return Types
8989

9090

91-
Built-in GraphQL scalar types `Int`, `Float`, `String`, `Boolean` and [custom scalar types](api.md#custom-scalars) are supported as function arguments and return types. Function types returning a table or view are supported as well:
91+
Built-in GraphQL scalar types `Int`, `Float`, `String`, `Boolean` and [custom scalar types](api.md#custom-scalars) 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](api.md#node):
9292

9393
=== "Function"
9494

@@ -125,6 +125,7 @@ Built-in GraphQL scalar types `Int`, `Float`, `String`, `Boolean` and [custom sc
125125
accountById(accountId: 1) {
126126
id
127127
email
128+
nodeId
128129
}
129130
}
130131
```
@@ -137,11 +138,57 @@ Built-in GraphQL scalar types `Int`, `Float`, `String`, `Boolean` and [custom sc
137138
"accountById": {
138139
"id": 1,
139140
"email": "a@example.com"
141+
"nodeId": "WyJwdWJsaWMiLCAiYWNjb3VudCIsIDFd"
140142
}
141143
}
142144
}
143145
```
144146

147+
If all the columns of a row are null, the result can be a little surprising. Instead of an object with all columns null, the top-level field is null:
148+
149+
=== "Function"
150+
151+
```sql
152+
create table account(
153+
id int,
154+
email varchar(255),
155+
name text null
156+
);
157+
158+
insert into account(id, email, name)
159+
values
160+
(1, 'aardvark@x.com', 'aardvark'),
161+
(2, 'bat@x.com', null),
162+
(null, null, null);
163+
164+
create function returns_account_with_all_null_columns()
165+
returns account language sql stable
166+
as $$ select id, email, name from account where id is null; $$;
167+
```
168+
169+
=== "Query"
170+
171+
```graphql
172+
query {
173+
returnsAccountWithAllNullColumns {
174+
id
175+
email
176+
name
177+
__typename
178+
}
179+
}
180+
```
181+
182+
=== "Response"
183+
184+
```json
185+
{
186+
"data": {
187+
"returnsAccountWithAllNullColumns": null
188+
}
189+
}
190+
```
191+
145192
Functions returning multiple rows of a table or view are exposed as [collections](api.md#collections).
146193

147194
=== "Function"

0 commit comments

Comments
 (0)