1
0
mirror of https://github.com/hasura/graphql-engine.git synced 2024-12-15 17:31:56 +03:00
Commit Graph

160 Commits

Author SHA1 Message Date
Samir Talwar
60f81023db server/tests-py: Run the auth hook inside the test harness.
This teaches `hge_server` how to run more tests, thanks to `hge_env`.

It also simplifies the logic a bit more.

I have also modified _run.sh_ and _docker-compose.yml_ so we can run multiple test suites, one after another.

PR-URL: https://github.com/hasura/graphql-engine-mono/pull/6105
GitOrigin-RevId: eff009362eb6bb90c07cedaf96dfe6ec9336ff32
2022-09-29 10:44:03 +00:00
Samir Talwar
a0176c215f server/tests-py: Set up postgis extensions using a fixture.
Let's put it in one place.

This is a precursor to moving database provisioning into the Python
integration tests.

PR-URL: https://github.com/hasura/graphql-engine-mono/pull/5453
GitOrigin-RevId: 5920b0b1177d94496485fcb4e178b946534ee4eb
2022-08-15 14:30:42 +00:00
Abby Sassel
26bbe2be34 server/tests: bigquery scalar type tests
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/5405
Co-authored-by: Gil Mizrahi <8547573+soupi@users.noreply.github.com>
GitOrigin-RevId: fc0a509500068331f9d80d58b411f144e011f094
2022-08-11 15:37:07 +00:00
Samir Talwar
5df8419a4f server/tests-py: Use markers for backends instead of parameterized tests.
I'm trying to shore up the Python integration tests to make them more reliable. In doing so, I noticed this.

---

It feels a lot more sensible as we never run on more than one backend at a time.

This also removes the `check_file_exists` parameter from the setup functions; it never worked. It was always set to the result of a comparison between a backend name and a function, which was always `False`. Enabling it breaks things.

PR-URL: https://github.com/hasura/graphql-engine-mono/pull/5254
GitOrigin-RevId: 8718ab21527c2ba0a7205d1c01ebaac1a10be844
2022-08-02 19:33:59 +00:00
Gil Mizrahi
ee15c804bc server/postgres: prefix identifiers longer than 63 characters with their md5 hash
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/5080
GitOrigin-RevId: 58e5e6aab136617d1bbfc6621c89942da358b04d
2022-07-22 15:29:02 +00:00
Abby Sassel
3318963d99 server/tests: sunset (FKA) TestGraphQLQueryBasicCommon pytests
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/4990
GitOrigin-RevId: 85c0ac27a7437c6ff96ce282b2fcf6950d5f4d07
2022-07-08 04:19:38 +00:00
Abby Sassel
4b4a11dd07 server/tests: sunset TestGraphQLQueryBasicMySQL pytests
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/4961
GitOrigin-RevId: 8745c075701378ebfad8cc66bb714b8a79666199
2022-07-05 18:35:00 +00:00
Samir Talwar
987b55f981 server/tests-py: Reduce the number of locations we check the status code.
We have a lot of `assert st_code == 200` scattered about. This is a
problem because (a) it makes the code harder to parse and (b) the error
message is lacking; I have seen a few flaky tests which were impossible
to diagnose because I didn't know what the response _should_ be.

This reduces the number of places in which we perform this assertion
(moving most of them to `HGECtx.execute_query`), so that we can have a
better chance of seeing a useful error message on test failure.

PR-URL: https://github.com/hasura/graphql-engine-mono/pull/4957
GitOrigin-RevId: 3ff388bccf49f96569aa6b7db85266a0c5ee27ea
2022-07-05 18:01:07 +00:00
Tom Harding
ffad733bd3 Port the "test_user_perms" pytest to hspec
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/4828
GitOrigin-RevId: 6227b8601e6b4d6f6bf2bd199cdb4d94a200c96c
2022-06-30 10:28:08 +00:00
Brandon Martin
5e29a1304d Revert "Add _cast support for other postgres datatypes fix and …
…fix "

This reverts commit f85742318167d1e51f463c45fcd00f26269c2555.

## Description ✍️
With this commit there is the possiblity that you could get conflicting
type definitions with remote schemas. Reverting for now as we determine
a solution. At which point we will add this back in.

PR-URL: https://github.com/hasura/graphql-engine-mono/pull/4879
Co-authored-by: Gil Mizrahi <8547573+soupi@users.noreply.github.com>
GitOrigin-RevId: 932b4a9226717c826d4bde7e375695354cee8c0c
2022-06-29 12:09:40 +00:00
Brandon Simmons
6e8da71ece server: migrate to aeson-2 in preparation for ghc 9.2 upgrade
(Work here originally done by awjchen, rebased and fixed up for merge by
jberryman)

This is part of a merge train towards GHC 9.2 compatibility. The main
issue is the use of the new abstract `KeyMap` in 2.0. See:
https://hackage.haskell.org/package/aeson-2.0.3.0/changelog

Alex's original work is here:


BEHAVIOR CHANGE NOTE: This change causes a different arbitrary ordering
of serialized Json, for example during metadata export. CLI users care
about this in particular, and so we need to call it out as a _behavior
change_ as we did in v2.5.0. The good news though is that after this
change ordering should be more stable (alphabetical key order).

See: https://hasurahq.slack.com/archives/C01M20G1YRW/p1654012632634389

PR-URL: https://github.com/hasura/graphql-engine-mono/pull/4611
Co-authored-by: awjchen <13142944+awjchen@users.noreply.github.com>
GitOrigin-RevId: 700265162c782739b2bb88300ee3cda3819b2e87
2022-06-08 15:32:27 +00:00
hasura-bot
e48f3cbef1 Add _cast support for other postgres datatypes fix and fix
GITHUB_PR_NUMBER: 8524
GITHUB_PR_URL: https://github.com/hasura/graphql-engine/pull/8524

PR-URL: https://github.com/hasura/graphql-engine-mono/pull/4551
Co-authored-by: Abdullah Saleem <5978905+abdullah2993@users.noreply.github.com>
Co-authored-by: Abby Sassel <3883855+sassela@users.noreply.github.com>
GitOrigin-RevId: f85742318167d1e51f463c45fcd00f26269c2555
2022-06-01 16:41:49 +00:00
Abby Sassel
25d77afaff server/tests: Fix BigQuery test failure Job exceeded rate limits error in CI
Fixes https://github.com/hasura/graphql-engine-mono/issues/3695.

Error: [BigQuery test failure Job exceeded rate limits](https://github.com/hasura/graphql-engine-mono/issues/3695)

Cause:
1. [this command](2325755954/.circleci/test-server.sh (L1263)) runs tests matching the `Bigquery or Common` string, for the `test-oss-server-bigquery` CI job.
2. in this case, the pytest filter matched on `TestGraphQLQueryBoolExpSearchCommon`. Although unrelated pytests are skipped, BQ setup and teardown runs uneccesarily for the [MSSQL and Postgres backends](e444cf1f5d/server/tests-py/test_graphql_queries.py (L868)).
4. the setup and teardown runs three times in quick succession, _for each of_ SQL Server, Postgres and BigQuery. Occasionally, this surpassed [BigQuery's maximum rate of 5 table update operations in 10 seconds](https://cloud.google.com/bigquery/quotas#load_job_per_table.long).

Fix: restrict setup/teardown to only the relevant backends...
- Hotfix (this PR): ...by renaming pytest classes and changing the pytest filters in `test-server`
	- ok, this is faintly horrifying and an inelegant convention change. On the bright side, it shaves a minute or so off our integration test suite run by skipping fewer tests. Anecdata for `test-oss-server-bigquery`
		- before: 87 passed, 299 skipped, 1 warning, 1 error in 192.99s
		- after: 87 passed, 20 skipped, 1 warning in 170.82s
	- [`Common` was a terrible name, anyway](https://github.com/hasura/graphql-engine-mono/issues/2079), for `AnyCombinationOfBackends`.
- Better fix: ...by refactoring the `conftest.py` helpers. I ran out of a timebox so will write up a separate issue. Given we're actively [porting pytests over to hspec](https://github.com/hasura/graphql-engine/issues/8432), I don't know how much it's worth investing time in a refactor.

To verify the fix: I ran a full CI build a few times [[1]](https://buildkite.com/hasura/graphql-engine-mono/builds/8069#078c781a-c8ef-44f2-a400-15f91fb88e42)[[2]](https://buildkite.com/hasura/graphql-engine-mono/builds/8072#f9e7f59d-264f-46a4-973d-21aa762cca35)[[3]](https://buildkite.com/hasura/graphql-engine-mono/builds/8075#bb104e80-ff76-408c-a46b-6f40e92e6317) whilst troubleshooting to convince myself this fixed the problem.

PR-URL: https://github.com/hasura/graphql-engine-mono/pull/4362
GitOrigin-RevId: 4c3283f0654b70e9dcda642d9012f6376aa95290
2022-04-27 18:40:41 +00:00
Philip Lykke Carlsen
e444cf1f5d Enhance pytest expectation overwriting via --accept flag
The pytest function `with_admin_secret` supports overwriting expectations. With this PR that support integrates with the pytest flag `--accept`.

PR-URL: https://github.com/hasura/graphql-engine-mono/pull/4330
GitOrigin-RevId: 8246588306487db03f1c09483f4447106805321c
2022-04-21 18:05:20 +00:00
hasura-bot
4ec9229f15 add jsonb to string cast support for postgres (fix , )
GITHUB_PR_NUMBER: 7818
GITHUB_PR_URL: https://github.com/hasura/graphql-engine/pull/7818

PR-URL: https://github.com/hasura/graphql-engine-mono/pull/2898
Co-authored-by: Teo Stocco <9053709+zifeo@users.noreply.github.com>
Co-authored-by: Rikin Kachhia <54616969+rikinsk@users.noreply.github.com>
Co-authored-by: Rakesh Emmadi <12475069+rakeshkky@users.noreply.github.com>
GitOrigin-RevId: 1100f3ce44ea07867a2d7de5b6bb059510f100e1
2022-03-10 07:32:59 +00:00
Philip Lykke Carlsen
369d1ab2f1 Only overwrite expectations if the flag is actually set
## Description

In https://hasurahq.slack.com/archives/C01RZPEPF0W/p1646672587226349 @rakeshkky discovered a flaw in the SQL explain tests golden tests that would overwrite expectation files even when not instructed to do so.

PR-URL: https://github.com/hasura/graphql-engine-mono/pull/3912
GitOrigin-RevId: 0c5acc6b96c7b619915d26ec8f78547959d5f78d
2022-03-07 22:17:52 +00:00
Rakesh Emmadi
878f6108e6 server/bigquery: apply 'order by' to 'array_agg' projection inside an array relationship join sub-query
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/3824
GitOrigin-RevId: b1739c35fb2c387152729d3ff72c6ff7ef9b9118
2022-03-07 10:13:02 +00:00
Rakesh Emmadi
e77c110927 server/bigquery: fix parsing timestamp input values
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/3667
GitOrigin-RevId: b696c219f96929fa8321c1a6d04589ee8d5b0827
2022-02-21 14:48:00 +00:00
Philip Lykke Carlsen
109a0beca8 (Fix ) Guard calls to JSON_QUERY on null arguments
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/3655
GitOrigin-RevId: 6e0aed6e96b2995af11366676fa9c453bb44a7aa
2022-02-21 08:53:06 +00:00
Gil Mizrahi
efec0bf9ca server/postgres: LIMIT 1 on object relationships
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/3489
Co-authored-by: Abby Sassel <3883855+sassela@users.noreply.github.com>
GitOrigin-RevId: f09a75508545cdbc34cf8728fad95bbb00bde018
2022-02-08 17:40:24 +00:00
Antoine Leblanc
d66d2d81fd server: use placeholder to prevent empty query roots
### Description

The GraphQL spec has to conflicting requirements:
1. an object must contain at least one field: the schema may not contain empty objects
2. the _query_root_ must always be present

Given _1_, the schema generation code removes from the schema all fields that would result in empty objects, such as a table for which a user does not have select permissions. But, as a result, our code also potentially removes _query_root_ if it is empty, breaking _2_.

This PR introduces a dummy "placeholder" field in the query root if it's empty, to ensure we never remove it from the schema.

### Remaining work

- [x] changelog entry
- [x] tests

PR-URL: https://github.com/hasura/graphql-engine-mono/pull/148
GitOrigin-RevId: bfd6bfcc2f3de92900b6ba566012f093399ca037
2022-01-27 18:08:11 +00:00
Kirill Zaborsky
47b9321ba4 BigQuery operators: like/nlike, geography
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/2924
GitOrigin-RevId: 3748411cb4419a21a58283836adb5cb39d351d19
2022-01-18 13:37:12 +00:00
Kirill Zaborsky
7beb15b4a3 distinct_on for BigQuery
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/3191
GitOrigin-RevId: e9f1c814b2caf09946389c4bcb30a0c42277abaf
2022-01-17 10:02:17 +00:00
Kirill Zaborsky
560daa63a8 BigQuery: fix support for joins in nodes of aggregate queries
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/3233
GitOrigin-RevId: a3a4624d5cd0c4c562e27d1e3605882e7f5a3d0d
2022-01-13 15:09:52 +00:00
Kirill Zaborsky
279f22ed08 Fix support for multiple array relationships in BigQuery
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/3003
GitOrigin-RevId: 7a9bf10be6436da2d87d5555f589e23c40c76dd6
2021-12-15 15:19:49 +00:00
Evie Ciobanu
aff1ebb060 server: add more MSSQL tests to CI
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/3129
Co-authored-by: Gil Mizrahi <8547573+soupi@users.noreply.github.com>
GitOrigin-RevId: 1e8fc7ed2426fc07f64ca042c9a0be005cc9d052
2021-12-15 10:44:09 +00:00
pranshi06
dee86453ea server: fallback to unauthorised role when JWT is not found in cookie
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/2882
GitOrigin-RevId: ad03fbd0572e00ffe7abea106388a4df4d12af2c
2021-12-08 18:29:29 +00:00
Rakesh Emmadi
7194dc691c server/mssql: fix SQL generation for aggregation queries in sql server (fixes & )
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/3024
GitOrigin-RevId: 30c0e7d713375d0c54ff7145d00985e3ade4f1a9
2021-12-02 14:22:42 +00:00
Abby Sassel
3fc34aa028 server: deduplicate some pytests
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/2988
GitOrigin-RevId: 018903d81c6025da2d9eb78aad4762a78f1f6c69
2021-11-26 19:38:17 +00:00
Kirill Zaborsky
a2afe4116b BigQuery remote joins
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/2874
Co-authored-by: Abby Sassel <3883855+sassela@users.noreply.github.com>
GitOrigin-RevId: 24b0304716795a28038629775238996c28b312a3
2021-11-24 16:22:55 +00:00
Gil Mizrahi
39002bc572 Parse session variables to their correct type in mssql
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/2908
GitOrigin-RevId: d9d8811e0d0658f6396a7c94bce9b7d2deb5245e
2021-11-20 09:03:44 +00:00
Gil Mizrahi
0e65932355 server/mssql support delete mutations (close )
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/2691
Co-authored-by: Abby Sassel <3883855+sassela@users.noreply.github.com>
Co-authored-by: Rakesh Emmadi <12475069+rakeshkky@users.noreply.github.com>
GitOrigin-RevId: 8b66cc30e8e036ee56a5267c1d2f308155951ae9
2021-11-19 17:06:01 +00:00
Rakesh Emmadi
95be515a60 server/mssql: fix table_by_pk query returning empty array
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/2810
GitOrigin-RevId: ed8e694d491d7bd28da0b39da2b1f1150d2e3735
2021-11-10 05:32:41 +00:00
Sibi Prabakaran
9f35e660c0 server/mysql: Implement MySQL explain API
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/2367
Co-authored-by: Chris Done <11019+chrisdone@users.noreply.github.com>
Co-authored-by: Aniket Deshpande <922486+aniketd@users.noreply.github.com>
Co-authored-by: Abby Sassel <3883855+sassela@users.noreply.github.com>
GitOrigin-RevId: 701c84a1ca5e4ab73a229a804381a7f5281090f1
2021-10-23 11:43:25 +00:00
Chris Done
459a7adbfb Add Types/FromIr changes for MySQL to work with the DataLoader
While it looks like a lot of work in FromIr.hs, you can rather review the type changes in `Hasura.Backends.MySQL.Types.Internal` and the changes to FromIr are only to reflect that. Essentially we're simplifying the FromIr code to not think about SQL-based joins: instead, FromIr produces fields necessary for the dataloader Plan/Execute to do their job properly.

I've done my best to ensure that all the hunks in the diff in this PR are minimal for slightly easier perusing.

I think future PRs will be more intentionally well structured, rather than created retroactively.

**Preceding PR:** 

**Next PR**: 

The tests have been run like this on my machine. I don't know more beyond that.

```
docker run -i -e "PYTEST_ADDOPTS=--color=yes" -e "TERM=xterm-256color" --net=host -v`pwd`:`pwd` -w`pwd`/server/tests-py chrisdone/hasura-pytest:b0f26f615 pytest  --hge-urls="http://localhost:8080"  --pg-urls="postgres://chinook:chinook@localhost:5432/chinook"  --backend mysql -k MySQL
```

PR-URL: https://github.com/hasura/graphql-engine-mono/pull/2608
Co-authored-by: Abby Sassel <3883855+sassela@users.noreply.github.com>
GitOrigin-RevId: a6483335c3036963360dde7d7d7eaf10859351cb
2021-10-21 23:51:17 +00:00
Philip Lykke Carlsen
c4536e801c Correctly translate permissions on functions to SQL, and simplify Bool Exp IR
Prior to this change, the SQL expression that resulted from translating permissions on functions would refer to the table of the function's return type, rather than the set of rows selected from the function being called.

Now the SQL that results from translating permissions correctly refer to the selected rows.

This PR also contains the suggested additions of https://github.com/hasura/graphql-engine-mono/pull/2563#discussion_r726116863, which simplifies the Boolean Expression IR, but in turn makes the Schema Dependency Discovery algorithm work a bit harder.

We are changing the definition of `data OpExpG`, but the format accepted by its JSON parser remains unchanged. While there does exist a generically derived `instance ToJSON OpExpG` this is only used in the (unpublished) `/v1/metadata/dump_internal_state` API.

PR-URL: https://github.com/hasura/graphql-engine-mono/pull/2609
Co-authored-by: Gil Mizrahi <8547573+soupi@users.noreply.github.com>
GitOrigin-RevId: bb9a0b4addbc239499dd2268909220196984df72
2021-10-18 09:17:42 +00:00
Abby Sassel
ef2e1ae935 server: skip flaky test to unblock PRs
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/2592
GitOrigin-RevId: d56bb4d83b75010d39ffab997766fa5778d547ee
2021-10-13 18:18:57 +00:00
Abby Sassel
a9e3a1b4bd server/bigquery: improve test setup and documentation (close )
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/2495
GitOrigin-RevId: ef250a0796200be6b75363b4275eb8a7ae780154
2021-10-12 17:59:44 +00:00
Gil Mizrahi
42cd2e69c0 Add support for customising function root field names
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/2468
Co-authored-by: Philip Lykke Carlsen <358550+plcplc@users.noreply.github.com>
GitOrigin-RevId: 5ff85bb02e4e651376a40914b7ae0aabc8524a05
2021-10-07 13:03:22 +00:00
Rakesh Emmadi
6724b62719 server/postgres: add test case to test computed field with session argument in where expression
>

### Description
>
Add a simple test case to test behavior of computed fields with session argument in filter expression (`where`) of a graphql query.

### Changelog

- [ ] `CHANGELOG.md` is updated with user-facing content relevant to this PR. If no changelog is required, then add the `no-changelog-required` label.

### Affected components

- [x] Tests

PR-URL: https://github.com/hasura/graphql-engine-mono/pull/2465
GitOrigin-RevId: 25e287c7e7826350e93f2bebacd5d877568c9934
2021-09-30 11:27:37 +00:00
awjchen
f1daabab04 docs, tests: update Explain API docs
https://github.com/hasura/graphql-engine-mono/pull/2352

Co-authored-by: Rikin Kachhia <54616969+rikinsk@users.noreply.github.com>
GitOrigin-RevId: f9f5d1157524afbe418ba0ca3e3e1d6258eaf9e3
2021-09-23 20:00:07 +00:00
Evie Ciobanu
1843ee7b0b [server] fix LIMIT optimization not respecting ORDER BY
https://github.com/hasura/graphql-engine-mono/pull/2239

Co-authored-by: Gil Mizrahi <8547573+soupi@users.noreply.github.com>
Co-authored-by: Rakesh Emmadi <12475069+rakeshkky@users.noreply.github.com>
GitOrigin-RevId: fabc825239950b11d673cfd33e8075a01409bcf6
2021-09-21 10:40:24 +00:00
Antoine Leblanc
21254256a1 Improve error messages of Metadata API.
### Description

This PR improves error messages in our metadata API by displaying a message with the name of the failing command and a link to our documentation. Furthermore, it harmonizes our internal uses of `withObject`, to respect the convention of using the Haskell type name, now that the Aeson error message is displayed as an "internal error message".

https://github.com/hasura/graphql-engine-mono/pull/1905

GitOrigin-RevId: e4064ba3290306437aa7e45faa316c60e51bc6b6
2021-09-20 19:50:22 +00:00
Antoine Leblanc
e2ce1972f6 Prevent empty subscription roots (fix )
### Description

We always build a subscription root, even when there was no possible fields. This breaks some third party clients, as the spec does not allow empty types in the schema. This PR fixes this by changing the `buildSubscriptionParser` helper to return a `Maybe` value, and harmonizes / cleans places where we build the subscription root.

https://github.com/hasura/graphql-engine-mono/pull/2357

GitOrigin-RevId: 1aeae25e321eee957e7645c436d17e69207309fd
2021-09-16 07:42:46 +00:00
Antoine Leblanc
9bae641ac4 Always enable inherited roles tests
### Description

The inherited roles integration tests were behind a flag, and its corresponding fixture, presumably to avoid enabling the option globally. However,  introduced a new test using inherited roles that was not gated behind the flag, which fails when run with `dev.sh`. However, that test works on CI... because inherited roles are globally enabled there.

Consequently, this PR:
- globally enables inherited roles in dev.sh
- removes the flag and the associated fixture

https://github.com/hasura/graphql-engine-mono/pull/2358

Co-authored-by: Vishnu Bharathi <4211715+scriptnull@users.noreply.github.com>
GitOrigin-RevId: ebfa6754873324bed15b2cc5e37ec2d8008e8f8d
2021-09-16 06:24:54 +00:00
Swann Moreau
4887f70caa [server] revert "server/postgres: optimize SQL query generation with LIMITs"
Fixes https://github.com/hasura/graphql-engine/issues/7453, by reverting  (commit 47eaccdbfb3499efd2c9f733f3312ad31c77916f).

https://hasurahq.slack.com/archives/CKFUG6RCH/p1629900718181700

https://github.com/hasura/graphql-engine-mono/pull/2204

GitOrigin-RevId: 53d5fee9c6008b26bc14213e5a16f6aba6d9c6b1
2021-08-30 11:54:53 +00:00
Abby Sassel
1e7ab8665d server/bigquery: fix data source references & pytest filter in CI
https://github.com/hasura/graphql-engine-mono/pull/2169

GitOrigin-RevId: a0a7190a404ee558a965e06fe1a022953f6f5a10
2021-08-26 18:12:05 +00:00
Aniket Deshpande
2700554412 bq: test table customization features
https://github.com/hasura/graphql-engine-mono/pull/2062

Co-authored-by: Rikin Kachhia <54616969+rikinsk@users.noreply.github.com>
GitOrigin-RevId: 5573efd1b28e088d5730c7d22e16889dc852b5fe
2021-08-18 13:00:58 +00:00
Rakesh Emmadi
fa152d842d server/postgres: optimize SQL query generation with LIMITs
>

### Description
>
This PR supersedes https://github.com/hasura/graphql-engine-mono/pull/1484. Apply `limit` to the table selection before joining relationship rows to improve query performance.

### Changelog

- [x] `CHANGELOG.md` is updated with user-facing content relevant to this PR. If no changelog is required, then add the `no-changelog-required` label.

### Affected components

- [x] Server

### Related Issues
->
Fix https://github.com/hasura/graphql-engine/issues/5745

### Solution and Design
>
Prior to this change, we apply `LIMIT` and `OFFSET` to the outer selection from sub-query which includes joins for relationships. Now, we move `LIMIT` and `OFFSET` (if present) to inner selection of base table. But, this isn't done always! If there are order by relationships' columns we apply at the outer selection. To know more, please refer to [source code note](https://github.com/hasura/graphql-engine-mono/pull/2078/files#diff-46d868ee45d3eaac667cebb34731f573c77d5c9c8097bb9ccf1115fc07f65bfdR652).

```graphql
query {
  article(limit: 2){
    id
    title
    content
    author{
      name
    }
  }
}
```
Before:
```sql
SELECT
  coalesce(json_agg("root"), '[]') AS "root"
FROM
  (
    SELECT
      row_to_json(
        (
          SELECT
            "_4_e"
          FROM
            (
              SELECT
                "_0_root.base"."id" AS "id",
                "_0_root.base"."title" AS "title",
                "_0_root.base"."content" AS "content",
                "_3_root.or.author"."author" AS "author"
            ) AS "_4_e"
        )
      ) AS "root"
    FROM
      (
        SELECT
          *
        FROM
          "public"."article"
        WHERE
          ('true')
      ) AS "_0_root.base"
      LEFT OUTER JOIN LATERAL (
        SELECT
          row_to_json(
            (
              SELECT
                "_2_e"
              FROM
                (
                  SELECT
                    "_1_root.or.author.base"."name" AS "name"
                ) AS "_2_e"
            )
          ) AS "author"
        FROM
          (
            SELECT
              *
            FROM
              "public"."author"
            WHERE
              (("_0_root.base"."author_id") = ("id"))
          ) AS "_1_root.or.author.base"
      ) AS "_3_root.or.author" ON ('true')
    LIMIT
      2
  ) AS "_5_root"
```
cost
```
Aggregate  (cost=0.73..0.74 rows=1 width=32)
  ->  Limit  (cost=0.15..0.71 rows=2 width=32)
        ->  Nested Loop Left Join  (cost=0.15..223.96 rows=810 width=32)
              ->  Seq Scan on article  (cost=0.00..18.10 rows=810 width=72)
              ->  Index Scan using author_pkey on author  (cost=0.15..0.24 rows=1 width=36)
                    Index Cond: (article.author_id = id)
                    SubPlan 1
                      ->  Result  (cost=0.00..0.01 rows=1 width=32)
              SubPlan 2
                ->  Result  (cost=0.00..0.01 rows=1 width=32)
```

After:
```sql
SELECT
  coalesce(json_agg("root"), '[]') AS "root"
FROM
  (
    SELECT
      row_to_json(
        (
          SELECT
            "_4_e"
          FROM
            (
              SELECT
                "_0_root.base"."id" AS "id",
                "_0_root.base"."title" AS "title",
                "_0_root.base"."content" AS "content",
                "_3_root.or.author"."author" AS "author"
            ) AS "_4_e"
        )
      ) AS "root"
    FROM
      (
        SELECT
          *
        FROM
          "public"."article"
        WHERE
          ('true')
        LIMIT
          2
      ) AS "_0_root.base"
      LEFT OUTER JOIN LATERAL (
        SELECT
          row_to_json(
            (
              SELECT
                "_2_e"
              FROM
                (
                  SELECT
                    "_1_root.or.author.base"."name" AS "name"
                ) AS "_2_e"
            )
          ) AS "author"
        FROM
          (
            SELECT
              *
            FROM
              "public"."author"
            WHERE
              (("_0_root.base"."author_id") = ("id"))
          ) AS "_1_root.or.author.base"
      ) AS "_3_root.or.author" ON ('true')
  ) AS "_5_root"
```
cost:
```
Aggregate  (cost=16.47..16.48 rows=1 width=32)
  ->  Nested Loop Left Join  (cost=0.15..16.44 rows=2 width=100)
        ->  Limit  (cost=0.00..0.04 rows=2 width=72)
              ->  Seq Scan on article  (cost=0.00..18.10 rows=810 width=72)
        ->  Index Scan using author_pkey on author  (cost=0.15..8.18 rows=1 width=36)
              Index Cond: (article.author_id = id)
              SubPlan 1
                ->  Result  (cost=0.00..0.01 rows=1 width=32)
  SubPlan 2
    ->  Result  (cost=0.00..0.01 rows=1 width=32)
```

https://github.com/hasura/graphql-engine-mono/pull/2078

Co-authored-by: Evie Ciobanu <1017953+eviefp@users.noreply.github.com>
GitOrigin-RevId: 47eaccdbfb3499efd2c9f733f3312ad31c77916f
2021-08-17 17:03:08 +00:00
Abby Sassel
6b3db83737 server/bigquery: run tests in CI
server/bigquery: run tests in CI 

[Example of successful BigQuery test job](https://app.circleci.com/pipelines/github/hasura/graphql-engine-mono/15951/workflows/86deb614-ddbc-4df5-9af3-288eeff6504a/jobs/283568)

TODO:
- [ ] I'll make corresponding changes in the OSS repo once this is merged
- [ ] @scriptnull or anyone with permissions: to require in CI

https://github.com/hasura/graphql-engine-mono/pull/1741

GitOrigin-RevId: d4ba446e9b13d213de135c73bb72973478575a29
2021-08-12 16:48:29 +00:00