6.3 KiB
Development
Prerequisites
Developing Hive locally requires you to have the following software installed locally:
- Node.js 16 LTS (or
nvmorfnm) - yarn v1
- docker
- docker-compose
Setup Instructions
- Clone the repository locally
- Make sure to install the recommended VSCode extensions (defined in
.vscode/extensions.json) - In the root of the repo, run
nvm useto use the same version of node as mentioned - Run
yarnat the root to install all the dependencies and run the hooks - Run
yarn setupto create and apply migrations on the PostgreSQL database - Run
yarn generateto generate the typings from the graphql files (useyarn graphql:generateif you only need to run GraphQL Codegen) - Run
yarn buildto build all services - Click on
Start Hivein the bottom bar of VSCode - If you are not added to the list of guest users, request access from The Guild maintainers
- Alternatively, configure hive to use your own Auth0 Application
- Open the UI (
http://localhost:3000by default) and Sign in with any of the identity provider - Once this is done, you should be able to login and use the project
- Once you generate the token against your organization/personal account in hive, the same can be added locally to
hive.jsonwithinpackages/libraries/cliwhich can be used to interact via the hive cli with the registry
Development Seed
We have a script to feed your local instance of Hive.
- Use
Start Hiveto run your local Hive instance - Make sure
usageandusage-ingestorare running as well (withyarn dev) - Open Hive app, create a project and a target, then create a token
- Run the seed script:
TOKEN="MY_TOKEN_HERE" yarn seed - This should report a dummy schema and some dummy usage data to your local instance of Hive, allowing you to test features e2e
Note: You can set
STAGING=1in order to target staging env and seed a target there.
To send more operations and test heavy load on Hive instance, you can also set
OPERATIONS(amount of operations in each interval round, default is1) andINTERVAL(frequency of sending operations, default:1000ms). For example, usingINTERVAL=1000 OPERATIONS=1000will send 1000 requests per second.
Publish your first schema (manually)
- Start Hive locally
- Create a project and a target
- Create a token from that target
- Go to
packages/libraries/cliand runyarn build - Inside
packages/libraries/cli, run:yarn start schema:publish --token "YOUR_TOKEN_HERE" --registry "http://localhost:4000/graphql" examples/single.graphql
Setting up Slack App for developing
- Download Loophole CLI (same as ngrok but supports non-random urls)
- Log in to Loophole
$ loophole account login - Start the proxy by running
$ loophole http 3000 --hostname hive-<your-name>(@kamilkisiela I usehive-kamil). It createshttps://hive-<your-name>.loophole.siteendpoint. - Message @kamilkisiela and send him the url (He will update the list of accepted redirect urls in both Auth0 and Slack App).
- Update
APP_BASE_URLandAUTH0_BASE_URLinpackages/web/app/.env - Run
packages/web/appand openhttps://hive-<your-name>.loophole.site.
We have a special Slack channel called
#hive-teststo not spam people :)
Setting up GitHub App for developing
- Follow the steps above for Slack App
- Update
Setup URLin GraphQL Hive Development app and set it tohttps://hive-<your-name>.loophole.site/api/github/setup-callback
Setting up Auth0 App for developing
Note
Super Tokens, which should also significantly simplify the local development experience.
You may want to use your own Auth0 app when running hive locally.
- Create your own Auth0 application
- If you haven't already, create an account on manage.auth0.com
- Create a new application with the following settings:
- Type:
Regular Web Application - Allowed Callback URLs:
http://localhost:3000/api/callback - Allowed Logout URLs:
http://localhost:3000/
- Type:
- Create two Auth0 users
- This can be done from the "User Management" page
- Create a new "Rule" in your Auth0 Account
- This can be done from the "Auth Pipeline -> Rules" section on the left navigation bar.
- Enter the following code:
function (user, context, callback) { var namespace = 'https://graphql-hive.com'; context.accessToken[namespace + '/metadata'] = user.user_metadata; context.idToken[namespace + '/metadata'] = user.user_metadata; context.accessToken[namespace + '/userinfo'] = { user_id: user.user_id, email: user.email, username: user.username, nickname: user.nickname }; return callback(null, user, context); }
- Update the
.envsecrets used by your local hive instance:- The
AUTH0_DOMAIN,AUTH0_CLIENT_ID, andAUTH0_CLIENT_SECRETvalues are found when viewing your new application on Auth0.
- The
# packages/services/server/.env
# Can be any value
AUTH0_SECRET=super-secret-value
AUTH0_DOMAIN=
AUTH0_CLIENT_ID=
AUTH0_CLIENT_SECRET=
AUTH0_SCOPE="openid profile offline_access"
AUTH0_AUDIENCE=https://${AUTH0_DOMAIN}/api/v2/
AUTH0_CONNECTION=Username-Password-Authentication
# packages/web/app/.env
# Must be the same value as in 'packages/services/server/.env'
AUTH0_SECRET=super-secret-value
AUTH0_DOMAIN=
AUTH0_CLIENT_ID=
AUTH0_CLIENT_SECRET=
AUTH0_SCOPE="openid profile offline_access"
AUTH0_AUDIENCE=https://${AUTH0_DOMAIN}/api/v2/
AUTH0_BASE_URL=http://localhost:3000
AUTH0_ISSUER_BASE_URL=https://${AUTH0_DOMAIN}
- Click on Start Hive in the bottom bar of VSCode
- Open the UI (
http://localhost:3000by default) and Sign in with one of the users you created on the Auth0 management console