Skip to content

Commit

Permalink
fix(postgraphql): add missing type coercion in computed procedure fie…
Browse files Browse the repository at this point in the history
…ld (#409)

* run all of the integration tests in parallel

* move test utilities

* only introspect catalog once

* speed up some tests

* set a max workers count

* add a thing

* remove a thing to trigger build

* fix lint errors

* fix integration queries with different configurations

* only test Koa in versions of Node.js greater than 4

* fix values not getting properly coerced

* Update snapshots after merge
  • Loading branch information
calebmer committed Mar 26, 2017
1 parent 0631012 commit 24cb295
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 1 deletion.
1 change: 1 addition & 0 deletions examples/kitchen-sink/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ create function c.no_args_mutation() returns int as $$ select 2 $$ language sql;

create function c.person_first_name(person c.person) returns text as $$ select split_part(person.name, ' ', 1) $$ language sql stable;
create function c.person_friends(person c.person) returns setof c.person as $$ select friend.* from c.person as friend where friend.id in (person.id + 1, person.id + 2) $$ language sql stable;
create function c.person_first_post(person c.person) returns a.post as $$ select * from a.post where a.post.author_id = person.id limit 1 $$ language sql stable;
create function c.compound_type_computed_field(compound_type c.compound_type) returns integer as $$ select compound_type.a + compound_type.foo_bar $$ language sql stable;
create function a.post_headline_trimmed(post a.post, length int default 10, omission text default '') returns text as $$ select substr(post.headline, 0, length) || omission $$ language sql stable;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -808,6 +808,10 @@ Object {
"nodes": Array [
Object {
"firstName": "John",
"firstPost": Object {
"headline": "I hate yogurt. It’s just stuff with bits in.",
"id": 2,
},
"friends": Object {
"nodes": Array [
Object {
Expand Down Expand Up @@ -840,6 +844,10 @@ Object {
},
Object {
"firstName": "Sara",
"firstPost": Object {
"headline": "No… It’s a thing; it’s like a plan, but with more greatness.",
"id": 1,
},
"friends": Object {
"nodes": Array [
Object {
Expand Down Expand Up @@ -872,6 +880,10 @@ Object {
},
Object {
"firstName": "Budd",
"firstPost": Object {
"headline": "Stop talking, brain thinking. Hush.",
"id": 6,
},
"friends": Object {
"nodes": Array [
Object {
Expand Down Expand Up @@ -899,6 +911,7 @@ Object {
},
Object {
"firstName": "Kathryn",
"firstPost": null,
"friends": Object {
"nodes": Array [
Object {
Expand All @@ -914,6 +927,10 @@ Object {
},
Object {
"firstName": "Joe",
"firstPost": Object {
"headline": "Please, Don-Bot… look into your hard drive, and open your mercy file!",
"id": 5,
},
"friends": Object {
"nodes": Array [],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,7 @@ type Person implements Node {
email: Email!
createdAt: Datetime
firstName: String
firstPost: Post

# Reads and enables paginatation through a set of \`Person\`.
friends(
Expand Down Expand Up @@ -3709,6 +3710,7 @@ type Person implements Node {
email: Email!
createdAt: Datetime
firstName: String
firstPost: Post

# Reads and enables paginatation through a set of \`Person\`.
friends(
Expand Down Expand Up @@ -5524,6 +5526,7 @@ type Person implements Node {
email: Email!
createdAt: Datetime
firstName: String
firstPost: Post

# Reads and enables paginatation through a set of \`Person\`.
friends(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1636,6 +1636,7 @@ type Person implements Node {
email: Email!
createdAt: Datetime
firstName: String
firstPost: Post

# Reads and enables paginatation through a set of \`Person\`.
friends(
Expand Down Expand Up @@ -5631,6 +5632,18 @@ exports[`test exports a schema as JSON 1`] = `
\"isDeprecated\": false,
\"deprecationReason\": null
},
{
\"name\": \"firstPost\",
\"description\": null,
\"args\": [],
\"type\": {
\"kind\": \"OBJECT\",
\"name\": \"Post\",
\"ofType\": null
},
\"isDeprecated\": false,
\"deprecationReason\": null
},
{
\"name\": \"friends\",
\"description\": \"Reads and enables paginatation through a set of \`Person\`.\",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ query {
}
}
}
firstPost {
id
headline
}
}
}
allEdgeCases {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function createPgSingleProcedureQueryGqlFieldEntry (
const input = [source, ...argEntries.map(([argName], i) => fixtures.args[i + 1].fromGqlInput(args[argName]))]
const query = sql.compile(sql.query`select to_json(${createPgProcedureSqlCall(fixtures, input)}) as value`)
const { rows: [row] } = await client.query(query)
return row ? fixtures.return.intoGqlOutput(row['value']) : null
return row ? fixtures.return.intoGqlOutput(fixtures.return.type.transformPgValueIntoValue(row['value'])) : null
},
}]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1467,6 +1467,23 @@ Object {
"returnTypeId": "text",
"returnsSet": false,
},
Object {
"argDefaultsNum": 0,
"argNames": Array [
"person",
],
"argTypeIds": Array [
"person",
],
"description": null,
"isStable": true,
"isStrict": false,
"kind": "procedure",
"name": "person_first_post",
"namespaceId": "c",
"returnTypeId": "post",
"returnsSet": false,
},
Object {
"argDefaultsNum": 0,
"argNames": Array [
Expand Down

0 comments on commit 24cb295

Please sign in to comment.