You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: README.md
+15-11
Original file line number
Diff line number
Diff line change
@@ -8,20 +8,15 @@ Get a full fake GraphQL API with zero coding in less than 30 seconds.
8
8
> 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.
9
9
> - About every developer
10
10
11
-
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.
11
+
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.
12
12
13
13
Inspired by the excellent [json-server](https://github.com/typicode/json-server).
14
14
15
-
## Example
16
-
17
-
Follow the guide below starting from scratch, or see the example live on StackBlitz:
15
+
## Usage
18
16
19
17
[](https://stackblitz.com/fork/json-graphql-server)
20
18
21
-
22
-
Create a `db.js` file.
23
-
24
-
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:
19
+
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:
25
20
26
21
```js
27
22
module.exports= {
@@ -40,14 +35,23 @@ module.exports = {
40
35
}
41
36
```
42
37
43
-
Start the GraphQL server on localhost, port 3000.
38
+
Use the `npx json-graphql-server <db_file_name>` command to start the GraphQL server on localhost, port 3000.
44
39
45
40
```sh
46
41
npx json-graphql-server db.js
47
42
```
48
43
49
-
To use a port other than 3000, you can run `json-graphql-server db.js --p <your port here>`
50
-
To use a host other than localhost, you can run `json-graphql-server db.js -h <your host here>` or `--host <your host here>`
44
+
To use a different port, use the `--port` or `-p` option:
45
+
46
+
```
47
+
npx json-graphql-server db.js --p 8080
48
+
```
49
+
50
+
To use a different host, use the `--host` or `-h` option:
51
+
52
+
```
53
+
npx json-graphql-server db.js -h 127.0.0.1
54
+
```
51
55
52
56
Now you can query your data in graphql. For instance, to issue the following query:
0 commit comments