Skip to content

Commit

Permalink
Improve usage instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
fzaninotto authored Dec 19, 2024
1 parent 2094c6b commit d2b0444
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -40,14 +35,23 @@ module.exports = {
}
```

Start the GraphQL server on localhost, port 3000.
Use the `npx json-graphql-server <db_file_name>` 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 <your port here>`
To use a host other than localhost, you can run `json-graphql-server db.js -h <your host here>` or `--host <your host here>`
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:

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d2b0444

Please sign in to comment.