Skip to content

Commit f281d03

Browse files
committed
docs: add info about schemaComposer option to README.md
1 parent 2ef7155 commit f281d03

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

README.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,20 @@ schemaComposer.Mutation.addFields({userPushToArray: UserTC.getResolver('pushToAr
492492

493493
NB if you set `unique: true` on the array then using the `update` `$push` approach will not check for duplicates, this is due to a MongoDB bug: https://jira.mongodb.org/browse/SERVER-1068. For more usage examples with `$push` and arrays see the MongoDB docs here https://docs.mongodb.com/manual/reference/operator/update/push/. Also note that `$push` will preserve order in the array (append to end of array) whereas `$addToSet` will not.
494494

495+
### Is it possible to use several schemas?
496+
497+
By default `composeWithMongoose` uses global `schemaComposer` for generated types. If you need to create different GraphQL schemas you need create own `schemaComposer`s and provide them to `customizationOptions`:
498+
499+
```js
500+
import { SchemaComposer } from 'graphql-compose';
501+
502+
const schema1 = new SchemaComposer();
503+
const schema2 = new SchemaComposer();
504+
505+
const UserTCForSchema1 = composeWithMongoose(User, { schemaComposer: schema1 });
506+
const UserTCForSchema2 = composeWithMongoose(User, { schemaComposer: schema2 });
507+
```
508+
495509
## Customization options
496510

497511
When we convert model `const UserTC = composeWithMongoose(User, customizationOptions);` you may tune every piece of future derived types and resolvers.
@@ -501,7 +515,8 @@ When we convert model `const UserTC = composeWithMongoose(User, customizationOpt
501515
The top level of customization options. Here you setup name and description for the main type, remove fields or leave only desired fields.
502516

503517
```js
504-
export type typeConverterOpts = {
518+
export type customizationOptions = {
519+
schemaComposer?: SchemaComposer<TContext>, // will be used global schema if not provided specific instance
505520
name?: string,
506521
description?: string,
507522
fields?: {

0 commit comments

Comments
 (0)