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
Your data file should be an object where the keys are the entity types. The values should be lists of entities, i.e. arrays of value objects with at lead an `id` key. For instance:
39
17
@@ -78,6 +56,48 @@ Your data file should be an object where the keys are the entity types. The valu
78
56
}
79
57
```
80
58
59
+
Start the GraphQL server on localhost, port 3000.
60
+
61
+
```sh
62
+
json-graphql-server db.json
63
+
```
64
+
65
+
Now you can query your data in graphql. For instance, to issue the following query:
66
+
67
+
```graphql
68
+
query {
69
+
Customer(id: 1) {
70
+
id
71
+
first_name
72
+
last_name
73
+
}
74
+
}
75
+
```
76
+
77
+
Go to http://localhost:3000/?query=query%20%7B%20Post(id%3A%201)%20%7Bid%20title%20views%20%7D%7D. You'll get the following result:
78
+
79
+
```json
80
+
{
81
+
"data": {
82
+
"Post": {
83
+
"id": "1",
84
+
"title": "Lorem Ipsum",
85
+
"views": 254,
86
+
}
87
+
}
88
+
}
89
+
```
90
+
91
+
The json-graphql-server accepts queries in GET and POST. Under the hood, it uses [Apollo's `graphql-server` module](http://dev.apollodata.com/tools/graphql-server/requests.html). Please refer to their documentations for details about passing variables, etc.
92
+
93
+
Note that the server is [GraphiQL](https://github.com/skevy/graphiql-app/releases) enabled.
94
+
95
+
## Install
96
+
97
+
```sh
98
+
npm install -g json-graphql-server
99
+
```
100
+
81
101
## Generated Types and Queries
82
102
83
103
Based on your data, json-graphql-server will generate a schema with one type per entity, as well as 3 query types and 3 mutation types. For instance for the `Post` entity:
@@ -172,6 +192,30 @@ Here is how you can use the queries and mutations generated for your data, using
172
192
</tr>
173
193
</table>
174
194
195
+
196
+
## Usage with Node
197
+
198
+
Installthemodulelocally
199
+
200
+
```sh
201
+
npminstall --save-devjson-graphql-server
202
+
```
203
+
204
+
Then use the `jsonGraphqlExpress` express middleware:
0 commit comments