This is a minimal example of using the (Warthog GraphQL API library. Warthog is a Node.js GraphQL Framework for building APIs with strong conventions through auto-generated code. With Warthog, set up your data models and resolvers, and it does the rest.
This project is currently running on Heroku at warthog-starter.herokuapp.com/graphql. Feel free to play around with it.
To get things set up in development, where everything will run in ts-node,
- Ensure postgres is running and update env.yml with the postgres config. If you have a password for the postgres admin user, add
DBPASSto env.yml underDBUSER. For example, you could rundocker run --detach --publish 5432:5432 -e POSTGRES_PASSWORD=password --name 'warthog-starter' postgres:10.12 - run
yarn bootstrap.
Run yarn build && yarn start to run the server.
When you run yarn start, it will run graphql-playground at the printed URL. When in the playground, you can issue queries and mutations against the API.
Run yarn test to run tests
In Production mode, you'll need to build and run the compiled code. To do this locally, run:
yarn startWhen you're ready to check in your feature, you'll need to generate a DB migration. This can automatically be done by running:
yarn db:migrate:generate user-and-postThis will drop a migration in the db folder. To run it and create the schema in your DB, run:
yarn db:migrateTo generate a new model, service and resolver, run warthog generate <model-name>. So for example:
warthog generate like...or if you want to bootstrap with some fields:
warthog generate author name! nickname numLogins:int! verified:bool! registeredAt:date balance:float!Some notes about this format:
- First param (
authorabove) is always the resource name (required) - Each subsequent item is a separate field/column that will be added to the model
- The format is fieldName:datatype, with an optional
!at the end to mark the field required and non-nullable (otherwise it's optional) datatypemust be one of the following:bool,date,int,float,string- If
datatypeis missing, it's assumed to bestring
