diff --git a/README.md b/README.md index de60632..8e230c8 100644 --- a/README.md +++ b/README.md @@ -8,20 +8,15 @@ Get a full fake GraphQL API with zero coding in less than 30 seconds. > I'd love to learn GraphQL, but it seems that I first have to read a book about GraphQL Types and Queries, then install a gazillion npm packages. > - About every developer -Start playing with GraphQL right away with `json-graphql-server`, a testing and mocking tool for GraphQL. All it takes is a JSON of your data. +Start playing with GraphQL right away with `json-graphql-server`, a testing and mocking tool for GraphQL written in Node.js. All it takes is a JSON of your data. Inspired by the excellent [json-server](https://github.com/typicode/json-server). -## Example - -Follow the guide below starting from scratch, or see the example live on StackBlitz: +## Usage [![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/fork/json-graphql-server) - -Create a `db.js` file. - -Your data file should export an object where the keys are the entity types. The values should be lists of entities, i.e. arrays of value objects with at least an `id` key. For instance: +Create a `db.js` file that exports an object where the keys are the entity types. The values should be lists of entities, i.e. arrays of value objects with at least an `id` key. For instance: ```js module.exports = { @@ -40,14 +35,23 @@ module.exports = { } ``` -Start the GraphQL server on localhost, port 3000. +Use the `npx json-graphql-server ` command to start the GraphQL server on localhost, port 3000. ```sh -json-graphql-server db.js +npx json-graphql-server db.js ``` -To use a port other than 3000, you can run `json-graphql-server db.js --p ` -To use a host other than localhost, you can run `json-graphql-server db.js -h ` or `--host ` +To use a different port, use the `--port` or `-p` option: + +``` +npx json-graphql-server db.js --p 8080 +``` + +To use a different host, use the `--host` or `-h` option: + +``` +npx json-graphql-server db.js -h 127.0.0.1 +``` Now you can query your data in graphql. For instance, to issue the following query: @@ -98,7 +102,7 @@ Note that the server is [GraphiQL](https://github.com/graphql/graphiql) enabled, ## Install ```sh -npm install -g json-graphql-server +npm install json-graphql-server ``` ## Generated Types and Queries