Skip to content

Commit 2a5919f

Browse files
committed
fixed tabbing
1 parent 2b1ce71 commit 2a5919f

File tree

1 file changed

+35
-35
lines changed

1 file changed

+35
-35
lines changed

docs/source/guides/schema-organization.md

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ import {
302302
303303
const Query = gql`
304304
type Query {
305-
_empty
305+
_empty
306306
}
307307
`;
308308
@@ -339,12 +339,12 @@ Let's say that we're to implement the resolver for the `authors(id: Int!): Autho
339339
// inside author.js
340340
341341
const resolvers = {
342-
Query: {
343-
author: (obj, args, context) => {
344-
// something goes on here that we have to fill in
345-
return author;
346-
},
347-
},
342+
Query: {
343+
author: (obj, args, context) => {
344+
// something goes on here that we have to fill in
345+
return author;
346+
},
347+
},
348348
};
349349
```
350350

@@ -368,8 +368,8 @@ import { schema } from './schema.js';
368368
const db = getDB();
369369
370370
app.use('/graphql', bodyParser.json(), graphqlExpress({
371-
schema,
372-
context: { db },
371+
schema,
372+
context: { db },
373373
}));
374374
```
375375

@@ -383,20 +383,20 @@ import { schema } from './schema.js';
383383
const db = getDB();
384384
385385
app.use('/graphql', bodyParser.json(), graphqlExpress({
386-
schema,
387-
context: { db },
386+
schema,
387+
context: { db },
388388
}));
389389
```
390390

391391
Now, this `db` object will be available to us within the `context` object in the resolver implementation. So, we might write something like this:
392392

393393
```
394394
const resolvers = {
395-
Query: {
396-
author: (obj, args, context) => {
397-
return context.db.execute('SELECT * FROM authors WHERE id=?', args.id);
398-
},
399-
},
395+
Query: {
396+
author: (obj, args, context) => {
397+
return context.db.execute('SELECT * FROM authors WHERE id=?', args.id);
398+
},
399+
},
400400
};
401401
```
402402

@@ -417,39 +417,39 @@ Ideally, our code for the resolver should look something like this:
417417
import { AuthorModel } from './models/author';
418418
419419
const resolvers = {
420-
Query: {
421-
author: (obj, args, context) => {
422-
return AuthorModel.find(args.id, context);
423-
},
424-
},
420+
Query: {
421+
author: (obj, args, context) => {
422+
return AuthorModel.find(args.id, context);
423+
},
424+
},
425425
};
426426
```
427427

428428
Our `AuthorModel` object can be written as:
429429

430430
```
431431
export const AuthorModel = {
432-
find: (id, context) {
433-
const dbResult = context.db.execute('SELECT * FROM authors WHERE id=?', id);
434-
return new Author(dbResult);
435-
}
432+
find: (id, context) {
433+
const dbResult = context.db.execute('SELECT * FROM authors WHERE id=?', id);
434+
return new Author(dbResult);
435+
}
436436
};
437437
```
438438

439439
where `Author` is a simple data class that contains properties of authors we care about. You might ask: what's the benefit of doing this? Now, we're no longer stuffing our GraphQL resolvers full of logic that's dependent on the database that we're using or the schema within the database. Instead, all the resolvers have to care about is the `Author` object. For example, let's say our `Author` GraphQL type has a `name` type. We may now implement this resolver as:
440440

441441
```
442442
const resolvers = {
443-
Query: {
444-
author: (obj, args, context) => {
445-
return AuthorModel.find(args.id, context);
446-
},
447-
},
448-
Author: {
449-
name: (obj, args, context) => {
450-
return obj.name;
451-
},
452-
},
443+
Query: {
444+
author: (obj, args, context) => {
445+
return AuthorModel.find(args.id, context);
446+
},
447+
},
448+
Author: {
449+
name: (obj, args, context) => {
450+
return obj.name;
451+
},
452+
},
453453
};
454454
```
455455

0 commit comments

Comments
 (0)