mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-15 17:31:56 +03:00
a40bf10b9f
Examples 1) ` pytest --hge-urls "http://127.0.0.1:8080" --pg-urls "postgresql://admin@127.0.0.1:5432/hge_tests" -vv ` 2) `pytest --hge-urls "http://127.0.0.1:8080" "http://127.0.0.1:8081" --pg-urls "postgresql://admin@127.0.0.1:5432/hge_tests" "postgresql://admin@127.0.0.1:5432/hge_tests2" -vv ` ### Solution and Design <!-- How is this issue solved/fixed? What is the design? --> <!-- It's better if we elaborate --> #### Reducing execution time of tests - The Schema setup and teardown, which were earlier done per test method, usually takes around 1 sec. - For mutations, the model has now been changed to only do schema setup and teardown once per test class. - A data setup and teardown will be done once per test instead (usually takes ~10ms). - For the test class to get this behaviour, one can can extend the class `DefaultTestMutations`. - The function `dir()` should be define which returns the location of the configuration folder. - Inside the configuration folder, there should be - Files `<conf_dir>/schema_setup.yaml` and `<conf_dir>/schema_teardown.yaml`, which has the metadata query executed during schema setup and teardown respectively - Files named `<conf_dir>/values_setup.yaml` and `<conf_dir>/values_teardown.yaml`. These files are executed to setup and remove data from the tables respectively. #### Running Graphql queries on both http and websockets - Each GraphQL query/mutation is run on the both HTTP and websocket protocols - Pytests test parameterisation is used to achieve this - The errors over websockets are slightly different from that on HTTP - The code takes care of converting the errors in HTTP to errors in websockets #### Parallel executation of tests. - The plugin pytest-xdist helps in running tests on parallel workers. - We are using this plugin to group tests by file and run on different workers. - Parallel test worker processes operate on separate postgres databases(and separate graphql-engines connected to these databases). Thus tests on one worker will not affect the tests on the other worker. - With two workers, this decreases execution times by half, as the tests on event triggers usually takes a long time, but does not consume much CPU.
2.6 KiB
2.6 KiB
Contributing
This guide explains how to set up the graphql-engine server for development on your own machine and how to contribute.
Pre-requisites
- stack
- A Postgres server (Recommended: Use docker to run a local postgres instance)
- GNU Make (optional)
- Node.js (v8.9+)
- libpq-dev
- psql
- python >= 3.7 with pip3
Upgrading npm
If your npm is too old (< 5.7),
npm install -g npm@latest
or
sudo npm install -g npm@latest
or update your nodejs
Getting pip3
sudo apt install python3-pip
Development workflow
Fork and clone
- Fork the repo on GitHub
- Clone your forked repo:
git clone https://github.com/<your-username>/graphql-engine
cd graphql-engine
Compile
- compile console assets
cd console npm ci cd ..
- compile the server
cd server stack build --fast --flag graphql-engine:local-console
Run
- Make sure postgres is running (Postgres >= 9.5)
- Create a database on postgres
- Run the binary:
stack exec graphql-engine -- --database-url=<database-url> serve
database url looks like: postgres://<username>:<password>@<host>:<port>/<dbname>
Running Postgres
The easiest way is to run docker in a container
docker run -p 5432:5432 -d postgres:11.1
Test if it's running by
telnet localhost 5432
psql
You will need psql or another client
sudo apt install postgresql-client
Work
- Work on the feature/fix
- Add test cases if relevant
Test
- Install the py-test dependencies:
pip3 install -r tests-py/requirements.txt
- Make sure postgres is running
- Run the graphql-engine:
stack exec graphql-engine -- --database-url=<database-url> serve --enable-console
- Set the environmental variables for event-trigger tests
export EVENT_WEBHOOK_HEADER="MyEnvValue"
export WEBHOOK_FROM_ENV="http://127.0.0.1:5592"
- Run tests:
cd tests-py
pytest --hge-urls http://127.0.0.1:8080 --pg-urls <database_url> -vv
Create Pull Request
- Make sure your commit messages meet the guidelines.
- Create a pull request from your forked repo to the main repo.
- Every pull request will automatically build and run the tests.
Code conventions
This helps enforce a uniform style for all committers.
- Compiler warnings are turned on, make sure your code has no warnings.
- Use hlint to make sure your code has no warnings.
- Use stylish-haskell to format your code.