8 KiB
Development
Prerequisites
Developing Hive locally requires you to have the following software installed locally:
- Node.js 18 LTS (or
nvmorfnm) - pnpm v8
- Docker
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 - Create
.envfile in the root, and use the following:
ENVIRONMENT=local
- Run
pnpm iat the root to install all the dependencies and run the hooks - Run
pnpm local:setupto run Docker compose dependencies, create databases and migrate database - Run
pnpm generateto generate the typings from the graphql files (usepnpm graphql:generateif you only need to run GraphQL Codegen) - Run
pnpm 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 log in 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 (withpnpm dev) - Open Hive app, create a project and a target, then create a token
- Run the seed script:
TOKEN="MY_TOKEN_HERE" pnpm 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. Same for development env, you can useDEV=1
Note: You can set
FEDERATION=1in order to publish multiple subgraphs.
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.
Troubleshooting
We recommend the following flow if you are having issues with running Hive locally:
- Stop all Docker containers:
docker kill $(docker ps -q) - Clear all local Docker environment:
docker system prune --all --force --volumes - Delete all generated local
.envfiles:find . -name '.env' | xargs rm - Delete local
docker/.hiveanddocker/.hive-devdir used by Docker volumes. - Reinstall dependencies using
pnpm install - Force-generate new
.envfiles:pnpm env:sync --force
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 runpnpm build - Inside
packages/libraries/cli, run:pnpm 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/.envto the proxy URL (e.g.https://hive-<your-name>.loophole.site) - 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
Local OIDC Testing
The docker-compose.dev.yml files includes a mock OIDC server that can be used for testing the OIDC
login/logout flow locally. The server tuns on port 7043.
Please make sure to set the AUTH_ORGANIZATION_OIDC environment variables for the server and
app to "1".
You can use the following values for connecting an integration to an OIDC provider.
# Token Endpoint
http://localhost:7043/connect/token
# User Info Endpoint
http://localhost:7043/connect/userinfo
# Authorization Endpoint
http://localhost:7043/connect/authorize
# Client ID
implicit-mock-client
# Client Secret
client-credentials-mock-client-secret
For login use the following credentials.
# Username
test-user
# Password
password
Run Hive
- Click on Start Hive in the bottom bar of VSCode
- Open the UI (
http://localhost:3000by default) and register any email and password - Sending e-mails is mocked out during local development, so in order to verify the account find
the verification link by visiting the email server's
/_historyendpoint -http://localhost:6260/_historyby default.- Searching for
tokenshould help you find the link.
- Searching for
Legacy Auth0 Integration
Note: If you are not working at The Guild, you can safely ignore this section.
Since we migrated from Auth0 to SuperTokens there is a compatibility layer for importing/migrating accounts from Auth0 to SuperTokens.
By default, you don't need to set this up and can just use SuperTokens locally. However, if you need to test some stuff or fix the Auth0 -> SuperTokens migration flow you have to set up some stuff.
- 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) { const 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 that are found when viewing your new application on Auth0:AUTH_LEGACY_AUTH0(set this to1for enabling the migration.)AUTH_LEGACY_AUTH0_CLIENT_ID(e.g.rGSrExtM9sfilpF8kbMULkMNYI2SgXro)AUTH_LEGACY_AUTH0_CLIENT_SECRET(e.g.gJjNQJsCaOC0nCKTgqWv2wvrh1XXXb-iqzVdn8pi2nSPq2TxxxJ9FIUYbNjheXxx)AUTH_LEGACY_AUTH0_ISSUER_BASE_URL(e.g.https://foo-bars.us.auth0.com)AUTH_LEGACY_AUTH0_AUDIENCE(e.g.https://foo-bars.us.auth0.com/api/v2/)