Skip to content
This repository was archived by the owner on Oct 8, 2024. It is now read-only.

Commit a89748f

Browse files
authored
make json str response not nullable (#181)
1 parent 3fdc50c commit a89748f

File tree

3 files changed

+7
-9
lines changed

3 files changed

+7
-9
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
- Update to v2 Hypermode metadata format [#176](https://github.com/hypermodeAI/functions-as/pull/176)
66
- Fix display output of certain types during build [#180](https://github.com/hypermodeAI/functions-as/pull/180)
7+
- Make json in dgraph response not nullable [#181](https://github.com/hypermodeAI/functions-as/pull/181)
78

89
## 2024-08-27 - Version 0.11.2
910

examples/dgraph/assembly/index.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export function alterSchema(): string {
2828
}
2929

3030
// This function returns the results of querying for all people in the database.
31-
export function queryPeople(): Person[] | null {
31+
export function queryPeople(): Person[] {
3232
const query = `
3333
{
3434
people(func: type(Person)) {
@@ -44,8 +44,7 @@ export function queryPeople(): Person[] | null {
4444
new dgraph.Request(new dgraph.Query(query)),
4545
);
4646

47-
if (resp.Json === null) return null;
48-
return JSON.parse<PeopleData>(resp.Json!).people;
47+
return JSON.parse<PeopleData>(resp.Json).people;
4948
}
5049

5150
// This function returns the results of querying for a specific person in the database.
@@ -72,8 +71,7 @@ export function querySpecificPerson(
7271
new dgraph.Request(new dgraph.Query(statement, vars)),
7372
);
7473

75-
if (resp.Json === null) return null;
76-
const people = JSON.parse<PeopleData>(resp.Json!).people;
74+
const people = JSON.parse<PeopleData>(resp.Json).people;
7775

7876
if (people.length === 0) return null;
7977
return people[0];
@@ -141,14 +139,13 @@ export function deletePerson(uid: string): Map<string, string> | null {
141139
}
142140

143141
// This function demonstrates what happens when a bad query is executed.
144-
export function testBadQuery(): Person[] | null {
142+
export function testBadQuery(): Person[] {
145143
const query = "this is a bad query";
146144

147145
const resp = dgraph.execute(
148146
hostName,
149147
new dgraph.Request(new dgraph.Query(query)),
150148
);
151149

152-
if (resp.Json === null) return null;
153-
return JSON.parse<PeopleData>(resp.Json!).people;
150+
return JSON.parse<PeopleData>(resp.Json).people;
154151
}

src/assembly/dgraph.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ export class Mutation {
141141
*
142142
*/
143143
export class Response {
144-
Json: string | null = null;
144+
Json: string = "";
145145
Uids: Map<string, string> | null = null;
146146
}
147147

0 commit comments

Comments
 (0)