/metaphysics

Artsy's GraphQL API

Primary LanguageTypeScriptMIT LicenseMIT

Metaphysics CircleCI

Metaphysics is a GraphQL-compliant API that wraps various Artsy APIs. You can try it here against our staging API.

It is built on express, express-graphql, and graphql. With graphiql providing a sandbox to work with.

It is currently used in production all over the place in Artsy.net, and the Artsy iOS App

Meta

Getting Setup

To get yourself set up with all the project's dependencies:

git clone https://github.com/artsy/metaphysics
cd metaphysics

# Install node modules
yarn install
# Installed system tools (like cache servers)
brew bundle
# Get set up with a default env
cp .env.example .env

For Artsy staff wanting to expand on your .env, you can use hokusai staging env get to see staging's env vars.

Development

With your dependencies set up, you can run Metaphysics by running:

yarn dev

Which will start the server on http://localhost:5001

Recommended: You can run the commands inside the terminal in VS Code, then the debugger will be hooked up by default.

Setting up your local GraphiQL

We recommend the graphiql.app client for testing queries locally.

You will need to set up headers with both:

  • x-access-token - Evaluate sd.CURRENT_USER.accessToken in a dev console on staging.artsy.net (sign in first, obvs).
  • x-user-id - As above, but sd.CURRENT_USER.id.

Sample Queries

Once you have the GraphiQL client running against your local service, you can verify things are working by executing these queries:

Get popular artists

{
  popular_artists {
    artists {
      name
    }
  }
}

Get your account information

{
  me {
    name
    email
  }
}

If any of these queries fail, it's probable that you misconfigured your x-access-token or x-user-id HTTP headers.

Docs

Docker and Kubernetes setup

This is deployed using Hokusai to manage Docker and Kubernetes. To replicate this:

  • Install Docker for Mac and Hokusai

    $ brew tap caskroom/cask && brew cask install docker
    $ pip install hokusai
    

    If you are using your system Python distribution, you may need to run this as:

    $ sudo pip install hokusai --ignore-installed
    
  • Configure Hokusai

    $ export AWS_ACCESS_KEY_ID={{ MY_AWS_ACCESS_KEY_ID }}
    $ export AWS_SECRET_ACCESS_KEY={{ MY_AWS_SECRET_ACCESS_KEY }}
    $ hokusai configure --kubectl-version {{ kubectl_version }} --s3-bucket {{ kubectl_config_s3_bucket }} --s3-key {{ kubectl_config_s3_key }}
    $ hokusai check
    

    Artsy staff should find follow the instructions in https://github.com/artsy/potential/blob/master/platform/Kubernetes.md#hokusai

Testing

  • Run tests in the Docker Compose test stack via Hokusai:

    $ hokusai test
    
  • Or, to run tests locally: npm test to run the entire suite npm run watch to spin up the test watcher

Deployment

PRs merged to the master branch are automatically deployed to staging. The release on staging can be promoted to production via the command hokusai pipeline promote --git-remote [upstream|origin]. The --git-remote option pushes a meaningful tag name to the git remote, so use whichever git remote points to Artsy's repository and not a fork (run git remote -v to see your git remotes and URLs). (If you accidentally push the git tags to the incorrect remote, you can run git push upstream production-tag-name to push a single tag to Artsy's repo.)

See Hokusai's docs on the Staging -> Production pipeline for more details.

Interacting with the staging and production deployments

Use hokusai staging commands to interact with the staging environment.

Use hokusai production commands to interact with the production environment.

(To deploy, see Deployment section above.)