From 24cb29554f6e33a2709cea125aa86e0d81997aef Mon Sep 17 00:00:00 2001 From: Caleb Meredith Date: Sun, 26 Mar 2017 15:16:14 -0400 Subject: [PATCH] fix(postgraphql): add missing type coercion in computed procedure field (#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 --- examples/kitchen-sink/schema.sql | 1 + .../postgraphqlIntegrationQueries-test.js.snap | 17 +++++++++++++++++ .../postgraphqlIntegrationSchema-test.js.snap | 3 +++ ...tgraphqlIntegrationSchemaExport-test.js.snap | 13 +++++++++++++ .../queries/procedure-computed-fields.graphql | 4 ++++ .../createPgProcedureObjectTypeGqlFieldEntry.ts | 2 +- .../introspectDatabase-test.js.snap | 17 +++++++++++++++++ 7 files changed, 56 insertions(+), 1 deletion(-) diff --git a/examples/kitchen-sink/schema.sql b/examples/kitchen-sink/schema.sql index d1fdab9c13..981a52f14b 100644 --- a/examples/kitchen-sink/schema.sql +++ b/examples/kitchen-sink/schema.sql @@ -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; diff --git a/src/postgraphql/__tests__/__snapshots__/postgraphqlIntegrationQueries-test.js.snap b/src/postgraphql/__tests__/__snapshots__/postgraphqlIntegrationQueries-test.js.snap index 968f69f995..76836730b2 100644 --- a/src/postgraphql/__tests__/__snapshots__/postgraphqlIntegrationQueries-test.js.snap +++ b/src/postgraphql/__tests__/__snapshots__/postgraphqlIntegrationQueries-test.js.snap @@ -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 { @@ -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 { @@ -872,6 +880,10 @@ Object { }, Object { "firstName": "Budd", + "firstPost": Object { + "headline": "Stop talking, brain thinking. Hush.", + "id": 6, + }, "friends": Object { "nodes": Array [ Object { @@ -899,6 +911,7 @@ Object { }, Object { "firstName": "Kathryn", + "firstPost": null, "friends": Object { "nodes": Array [ Object { @@ -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 [], }, diff --git a/src/postgraphql/__tests__/__snapshots__/postgraphqlIntegrationSchema-test.js.snap b/src/postgraphql/__tests__/__snapshots__/postgraphqlIntegrationSchema-test.js.snap index 45d1320aaf..a395425882 100644 --- a/src/postgraphql/__tests__/__snapshots__/postgraphqlIntegrationSchema-test.js.snap +++ b/src/postgraphql/__tests__/__snapshots__/postgraphqlIntegrationSchema-test.js.snap @@ -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( @@ -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( @@ -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( diff --git a/src/postgraphql/__tests__/__snapshots__/postgraphqlIntegrationSchemaExport-test.js.snap b/src/postgraphql/__tests__/__snapshots__/postgraphqlIntegrationSchemaExport-test.js.snap index 7c343a341c..880b106136 100644 --- a/src/postgraphql/__tests__/__snapshots__/postgraphqlIntegrationSchemaExport-test.js.snap +++ b/src/postgraphql/__tests__/__snapshots__/postgraphqlIntegrationSchemaExport-test.js.snap @@ -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( @@ -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\`.\", diff --git a/src/postgraphql/__tests__/fixtures/queries/procedure-computed-fields.graphql b/src/postgraphql/__tests__/fixtures/queries/procedure-computed-fields.graphql index 2a6707a5c4..43b8ad3350 100644 --- a/src/postgraphql/__tests__/fixtures/queries/procedure-computed-fields.graphql +++ b/src/postgraphql/__tests__/fixtures/queries/procedure-computed-fields.graphql @@ -32,6 +32,10 @@ query { } } } + firstPost { + id + headline + } } } allEdgeCases { diff --git a/src/postgraphql/schema/procedures/createPgProcedureObjectTypeGqlFieldEntry.ts b/src/postgraphql/schema/procedures/createPgProcedureObjectTypeGqlFieldEntry.ts index 664f989ee0..33f8ac17ca 100644 --- a/src/postgraphql/schema/procedures/createPgProcedureObjectTypeGqlFieldEntry.ts +++ b/src/postgraphql/schema/procedures/createPgProcedureObjectTypeGqlFieldEntry.ts @@ -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 }, }] } diff --git a/src/postgres/introspection/__tests__/__snapshots__/introspectDatabase-test.js.snap b/src/postgres/introspection/__tests__/__snapshots__/introspectDatabase-test.js.snap index d5e45433e8..4f3d8552b9 100644 --- a/src/postgres/introspection/__tests__/__snapshots__/introspectDatabase-test.js.snap +++ b/src/postgres/introspection/__tests__/__snapshots__/introspectDatabase-test.js.snap @@ -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 [