Skip to content

Commit 2ef2379

Browse files
authored
docs: small explanations of vars naming
1 parent 799954d commit 2ef2379

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

README.md

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ Live demo: [https://graphql-compose.herokuapp.com/](https://graphql-compose.hero
4242

4343
Source code: https://github.com/graphql-compose/graphql-compose-mongoose-example
4444

45+
Small explanation for varaibles naming:
46+
- `UserSchema` - this is a mongoose schema
47+
- `User` - this is a mongoose model
48+
- `UserTC` - this is a TypeComposer instance for User. TypeComposer has GraphQLObjectType inside, avaliable via method UserTC.getType().
49+
- Here and in all other places of code suffix `...TC` means that this is TypeComposer instance, `...ITC` - InputTypeComposer, `...ETC` - EnumTypeComposer.
50+
4551
```js
4652
import mongoose from 'mongoose';
4753
import { composeWithMongoose } from 'graphql-compose-mongoose';
@@ -79,13 +85,13 @@ const UserSchema = new mongoose.Schema({
7985
description: 'Can be any mixed type, that will be treated as JSON GraphQL Scalar Type',
8086
},
8187
});
82-
const UserModel = mongoose.model('UserModel', UserSchema);
88+
const User = mongoose.model('User', UserSchema);
8389

8490

8591

8692
// STEP 2: CONVERT MONGOOSE MODEL TO GraphQL PIECES
8793
const customizationOptions = {}; // left it empty for simplicity, described below
88-
const UserTC = composeWithMongoose(UserModel, customizationOptions);
94+
const UserTC = composeWithMongoose(User, customizationOptions);
8995

9096
// STEP 3: CREATE CRAZY GraphQL SCHEMA WITH ALL CRUD USER OPERATIONS
9197
// via graphql-compose it will be much much easier, with less typing
@@ -121,7 +127,7 @@ FAQ
121127
===
122128
### Can I get generated vanilla GraphQL types?
123129
```js
124-
const UserTC = composeWithMongoose(UserModel);
130+
const UserTC = composeWithMongoose(User);
125131
UserTC.getType(); // returns GraphQLObjectType
126132
UserTC.getInputType(); // returns GraphQLInputObjectType, eg. for args
127133
UserTC.get('languages').getType(); // get GraphQLObjectType for nested field
@@ -146,7 +152,7 @@ UserTC.addFields({
146152
```
147153

148154
### How to build nesting/relations?
149-
Suppose you Model has `friendsIds` field with array of user ids. So let build some relations:
155+
Suppose you `User` model has `friendsIds` field with array of user ids. So let build some relations:
150156
```js
151157
UserTC.addRelation(
152158
'friends',
@@ -217,11 +223,11 @@ Before continuing to convert your models to TypeComposers:
217223
import mongoose from 'mongoose';
218224
import { composeWithMongoose } from 'graphql-compose-mongoose';
219225

220-
const UserProfileModel = mongoose.model('UserProfile', UserProfile);
221-
const ArticleModel = mongoose.model('Article', Article);
226+
const UserProfile = mongoose.model('UserProfile', UserProfile);
227+
const Article = mongoose.model('Article', Article);
222228

223-
const UserProfileTC = composeWithMongoose(UserProfileModel);
224-
const ArticleTC = composeWithMongoose(ArticleModel);
229+
const UserProfileTC = composeWithMongoose(UserProfile);
230+
const ArticleTC = composeWithMongoose(Article);
225231
```
226232
Then, you can use queries like this:
227233
```graphql
@@ -249,7 +255,7 @@ fragment fullImageData on EmbeddedImage {
249255

250256
Customization options
251257
=====================
252-
When we convert model `const UserTC = composeWithMongoose(UserModel, customizationOptions);` you may tune every piece of future derived types and resolvers.
258+
When we convert model `const UserTC = composeWithMongoose(User, customizationOptions);` you may tune every piece of future derived types and resolvers.
253259

254260
### Here is flow typed definition of this options:
255261

0 commit comments

Comments
 (0)