1
1
# json-graphql-server
2
2
3
- Get a full fake GraphQL API with zero coding in less than 30 seconds. Works on the browser and on the server.
3
+ Get a full fake GraphQL API with zero coding in less than 30 seconds.
4
4
5
5
## Motivation
6
6
@@ -11,20 +11,6 @@ Start playing with GraphQL right away with `json-graphql-server`, a testing and
11
11
12
12
## Usage
13
13
14
- * In the browser
15
-
16
- ``` js
17
- < script src= " https://cdnjs.cloudflare.com/ajax/libs/json-graphql-server/1.0.0/json-graphql-server.min.js" >< / script>
18
- < script>
19
- var data = {
20
- // ... your data
21
- };
22
- GraphQLClientServer (data); // starts a GraphQL Server in your browser
23
- // now every call to http://localhost:3000/graphql will be intercepted
24
- // and served with your data in GraphQL
25
- < / script>
26
- ```
27
-
28
14
* CLI
29
15
30
16
``` sh
@@ -36,14 +22,14 @@ json-graphql-server path/to/data.js
36
22
37
23
``` js
38
24
import express from ' express' ;
39
- import { GraphQlServer } from ' json-graphql-server' ;
25
+ import { jsonGraphqlExpress } from ' json-graphql-server' ;
40
26
41
27
const PORT = 3000 ;
42
28
const app = express ();
43
29
const data = {
44
30
// ... your data
45
31
};
46
- app .use (' /graphql' , GraphQLServer (data));
32
+ app .use (' /graphql' , jsonGraphqlExpress (data));
47
33
app .listen (PORT );
48
34
```
49
35
@@ -186,58 +172,13 @@ Here is how you can use the queries and mutations generated for your data, using
186
172
</tr >
187
173
</table >
188
174
189
- ## Options
190
-
191
- You can access the json -graphql -server from anywhere - CORS are configures to accept all inbound requests . Also , content is compressed using GZip .
192
-
193
- ### Browser Options
194
-
195
- You can override the GraphQL endpoint and port using the second parameter :
196
-
197
- ```js
198
- <script >
199
- var data = {
200
- // ... your data
201
- };
202
- GraphQLClientServer (data, 'http ://localhost :8080/graphql ');
203
- // now every call to http ://localhost :8080/graphql will be intercepted
204
- // and served with your data in GraphQL
205
- </script >
206
- ```
207
-
208
- ### CLI Options
209
-
210
- You can override the GraphQL server port using the ` --port ` (or ` -p ` ) option:
211
-
212
- ``` sh
213
- json-graphql-server --port 8080 path/to/data.js
214
- ```
215
-
216
- You can force a server restart every time the source JSON file changes using the ` --watch ` option:
217
-
218
- ``` sh
219
- json-graphql-server --watch path/to/data.js
220
- ```
221
-
222
- You can start a https server instead of an http one using the ` --https ` (or ` -s ` ) option:
223
-
224
- ``` sh
225
- json-graphql-server --https path/to/data.js
226
- ```
227
-
228
- You can add a random delay to responses by specifying a maximum delay (in ms) using the ` --delay ` (or ` -d ` ) option:
229
-
230
- ``` sh
231
- json-graphql-server --delay 1000 path/to/data.js
232
- ```
233
-
234
175
## Adding Authentication, Custom Routes, etc.
235
176
236
177
`json -graphql -server ` doesn 't deal with authentication or custom routes . But you can use your favorite middleware with Express :
237
178
238
179
```js
239
180
import express from 'express ';
240
- import { GraphQlServer } from ' json-graphql-server' ;
181
+ import { jsonGraphqlExpress } from 'json -graphql -server ';
241
182
242
183
import OAuthSecurityMiddleWare from './path /to /OAuthSecurityMiddleWare ';
243
184
@@ -247,7 +188,7 @@ const data = {
247
188
// ... your data
248
189
};
249
190
app .use (OAuthSecurityMiddleWare ());
250
- app .use (' /graphql' , GraphQLServer (data));
191
+ app .use ('/graphql', jsonGraphqlExpress (data ));
251
192
app .listen (PORT);
252
193
```
253
194
0 commit comments