@@ -89,30 +89,30 @@ a `where age <= 100` clause. In addition to the property filters, there are some
89
89
90
90
``` js
91
91
const { graphQlSchema } = require (' ./graphql' ) // your graphql schema
92
- const graphQlSchemaResult = await graphQlSchema ()
93
- const { createHandler } = require (' graphql-http/lib/use/express' )
94
-
95
- app .use (' /graphql' , (req , res , next ) => {
96
- res .set (' Content-Security-Policy' , ' default-src *; style-src \' self\' http://* \' unsafe-inline\' ; script-src \' self\' http://* \' unsafe-inline\' \' unsafe-eval\' ' )
97
-
98
- next ()
99
- }, createHandler ({
100
- schema: graphQlSchemaResult, context : (req , res , params ) => ({ req, res, params })
101
- }))
92
+ const graphQlSchemaResult = await graphQlSchema ()
93
+ const { createHandler } = require (' graphql-http/lib/use/express' )
94
+
95
+ app .use (' /graphql' , (req , res , next ) => {
96
+ res .set (' Content-Security-Policy' , ' default-src *; style-src \' self\' http://* \' unsafe-inline\' ; script-src \' self\' http://* \' unsafe-inline\' \' unsafe-eval\' ' )
97
+
98
+ next ()
99
+ }, createHandler ({
100
+ schema: graphQlSchemaResult, context : (req , res , params ) => ({ req, res, params })
101
+ }))
102
102
```
103
103
104
104
#### [ express-graphql] ( https://www.npmjs.com/package/express-graphql ) (deprecated)
105
105
106
106
``` js
107
107
const { graphQlSchema } = require (' ./graphql' ) // your graphql schema
108
- const graphQlSchemaResult = await graphQlSchema ()
109
- const { graphqlHTTP } = require (' express-graphql' )
110
-
111
- app .use (' /graphql' , (req , res , next ) => {
112
- res .set (' Content-Security-Policy' , ' default-src *; style-src \' self\' http://* \' unsafe-inline\' ; script-src \' self\' http://* \' unsafe-inline\' \' unsafe-eval\' ' )
113
-
114
- next ()
115
- }, graphqlHTTP ({ schema: graphQlSchemaResult }))
108
+ const graphQlSchemaResult = await graphQlSchema ()
109
+ const { graphqlHTTP } = require (' express-graphql' )
110
+
111
+ app .use (' /graphql' , (req , res , next ) => {
112
+ res .set (' Content-Security-Policy' , ' default-src *; style-src \' self\' http://* \' unsafe-inline\' ; script-src \' self\' http://* \' unsafe-inline\' \' unsafe-eval\' ' )
113
+
114
+ next ()
115
+ }, graphqlHTTP ({ schema: graphQlSchemaResult }))
116
116
```
117
117
118
118
# Getting started
@@ -194,11 +194,11 @@ It will use the model's table schema to generate the structure of the jsonSchema
194
194
195
195
# Extending your schema with mutations
196
196
197
- Often you need to provide mutations in your GraphQL schema. At the same time mutations can be quite opinionated with
197
+ Often you need to provide mutations in your GraphQL schema. At the same time, mutations can be quite opinionated with
198
198
side effects and complex business logic, so plain CUD implementation is not always a good idea.
199
199
Therefore, we provide a method ` extendWithMutations ` which allows you to extend the generated query schema with
200
200
mutations. You can provide a root ` GraphQLObjectType ` or a function as the first argument for this method.
201
- Function in this case plays as a strategy which receives current builder as a first argument and
201
+ Function in this case plays as a strategy that receives the current builder as a first argument and
202
202
returns ` GraphQLObjectType ` .
203
203
204
204
``` js
@@ -270,8 +270,8 @@ schema = mainModule
270
270
# Extending your schema with subscriptions
271
271
272
272
When you want to implement a real-time behavior in your app like push notifications, you basically have two options in
273
- graphql : subscriptions and live queries. The first approach is focused on events and granular control over updates,
274
- while the other is based on smart live queries, where most of real-time magic is hidden from the client. We'd like to
273
+ GraphQl : subscriptions and live queries. The first approach focuses on events and granular control over updates,
274
+ while the other is based on smart live queries, where most real-time magic is hidden from the client. We'd like to
275
275
stick with the first approach since there are some decent implementations out there
276
276
like [ graphql-subscriptions] ( https://github.com/apollographql/graphql-subscriptions ) by Apollo.
277
277
@@ -358,8 +358,8 @@ const graphQlSchema = graphQlBuilder()
358
358
359
359
Now you would have ` myProp_lt: value ` instead of the default ` myPropLt: value ` .
360
360
361
- By default, the model names are pluralized by adding an ` s ` to the end of the camelized table name. You can set a custom
362
- plural and singular names for the root fields like so:
361
+ By default, the model names are pluralized by adding an ` s ` to the end of the caramelized table name.
362
+ You can set a custom plural and singular names for the root fields like so:
363
363
364
364
``` js
365
365
const graphQlSchema = graphQlBuilder ()
@@ -411,21 +411,22 @@ Allows you to customize **Objection** query builder behavior. For instance, you
411
411
options argument. So, each time the builder is called, it will be called with ** skipUndefined** enabled.
412
412
This can be useful when you use [ graphql-tools] ( https://github.com/apollographql/graphql-tools ) schema stitching.
413
413
414
- ## Cacheing
414
+ ## Caching
415
415
416
- We add a cache layer to the graphql builder.
416
+ We add a cache layer to the GraphQl builder.
417
417
This is useful when you have a lot of queries that are similar.
418
418
You can enable the cache by passing a cache object to the builder.
419
419
420
- Specifying Cache options when building the GraphQL schema is not necessary but it can drastically improve performance
421
- GraphQL Caching options are : ` host, port, redisKeyPrefix, timeout `
420
+ Specifying Cache options when building the GraphQL schema is not necessary, but it can drastically improve performance
421
+ GraphQL Caching options are: ` host, port, redisKeyPrefix, timeout `
422
422
423
423
` host ` and ` port ` specify the host and port of your Redis connection
424
424
425
- ` redisKeyPrefix ` is a prefix for all the cached Redis keys, default value is 'gqlCache'
425
+ ` redisKeyPrefix ` is a prefix for all the cached Redis keys, the default value is 'gqlCache'
426
426
427
- ` timeout ` specifies the age of each cached Redis key in seconds, defaults to 1 hour, you might need to change this value
428
- in case your system often faces data updates
427
+ ` timeout ` specifies the age of each cached Redis key in seconds, and defaults to 1 hour, you might need to change this
428
+ value
429
+ in case your system often faces data updates.
429
430
430
431
``` js
431
432
const graphql = require (' graphql' ).graphql ;
@@ -438,11 +439,15 @@ const Review = require('./models/Review');
438
439
439
440
const graphQlSchema = async () => {
440
441
const builder = await graphQlBuilder ({
441
- host: ' localhost' ,
442
- port: 6379 ,
443
- redisKeyPrefix: ' gqlCache' ,
444
- timeout: 10
445
- }).allModels ([Movie, Person, Review]);
442
+ // Builder options, currently only 'redis' is available
443
+ redis: {
444
+ host: ' localhost' ,
445
+ port: 6379 ,
446
+ redisKeyPrefix: ' gqlCache' ,
447
+ cacheTimeout: 10
448
+ }
449
+ }
450
+ ).allModels ([Movie, Person, Review]);
446
451
447
452
return builder .build ();
448
453
};
0 commit comments