Skip to content

Commit 0572a6a

Browse files
authored
Apply suggestions from code review
1 parent 572c522 commit 0572a6a

File tree

2 files changed

+5
-21
lines changed

2 files changed

+5
-21
lines changed

postgraphile/website/versioned_docs/version-4/custom-queries.md

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ By default all attributes on postgres types are nullable, and so a function that
5252
returns a type instead of a table will have all its fields treated as such by the
5353
generated GraphQL schema. This can be over-ridden on an attribute-by-attribute basis
5454
with the `@notNull` [smart tag](./smart-tags).
55+
5556
:::
5657

5758
### Example
@@ -91,40 +92,22 @@ create function search_posts(search text)
9192
$$ language sql stable;
9293
```
9394

94-
Or using a type to return a subset of the columns on the table:
95-
```
96-
-- Columns unnecessary to this demo were omitted. You can find the full table in
97-
-- our forum example.
98-
create table post (
99-
100-
headline text not null,
101-
body text,
102-
103-
);
95+
Or using a type to return the exact shape of data you need:
10496

97+
```sql {5}
10598
create type post_search_result as (
10699
headline text,
107100
body text
108101
);
109102
comment on column post_search_result.headline is E'@notNull';
110103

111-
-- Create the function named `search_posts` with a text argument named `search`.
112-
-- This will expose `Query.searchPosts(search: String!, ...)` to GraphQL.
113104
create function search_posts(search text)
114-
-- This function will return a set of posts from the `post` table. The
115-
-- `setof` part is important to PostGraphile, check out our Functions article
116-
-- to learn why.
117105
returns setof post_search_result as $$
118-
-- Write our advanced query as a SQL query!
119106
select headline, body
120107
from post
121108
where
122-
-- Use the `ILIKE` operator on both the `headline` and `body` columns. If
123-
-- either return true, return the post.
124109
headline ilike ('%' || search || '%') or
125110
body ilike ('%' || search || '%')
126-
-- End the function declaring the language we used as SQL and add the
127-
-- `STABLE` marker so PostGraphile knows its a query and not a mutation.
128111
$$ language sql stable;
129112
```
130113

postgraphile/website/versioned_docs/version-4/smart-tags.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ The column can also be renamed:
7171
comment on column original_table.col1 is E'@name colA';
7272
```
7373

74-
The same can be done for types, type attributes, and custom queries:
74+
The same can be done for types, type attributes (i.e. "columns"), and custom
75+
queries:
7576

7677
```sql
7778
create type flibble as (f text);

0 commit comments

Comments
 (0)