Skip to content
This repository was archived by the owner on Dec 4, 2017. It is now read-only.

Commit 823d03c

Browse files
committed
docs(cookbook/graphql): Docregion
1 parent 883cb64 commit 823d03c

File tree

2 files changed

+27
-18
lines changed

2 files changed

+27
-18
lines changed
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
// #docregion
12
import ApolloClient, { createNetworkInterface } from 'apollo-client';
23
import { networkInterface } from './in-memory-graphql';
34

45
export const client = new ApolloClient({
5-
networkInterface,
6-
dataIdFromObject: (r:any) => r.id,
7-
});
6+
networkInterface
7+
});
8+
// #enddocregion

public/docs/_examples/heroes-graphql/ts/app/in-memory-graphql.ts

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
// #docregion
2+
// #docregion import-lodash
23
import { find, filter } from 'lodash';
4+
// #enddocregion import-lodash
5+
// #docregion import-graphql-tools
36
import { makeExecutableSchema } from 'graphql-tools';
4-
7+
// #enddocregion import-graphql-tools
8+
// #docregion import-graphql
9+
import { execute } from 'graphql';
10+
// #enddocregion import-graphql
511
// #docregion graphql-schema
612
const typeDefinitions = `
713
type Hero {
@@ -35,7 +41,7 @@ schema {
3541
}
3642
`;
3743
// #enddocregion graphql-schema
38-
44+
// #docregion heroes-array
3945
const heroes = [
4046
{id: 11, name: 'Mr. Nice'},
4147
{id: 12, name: 'Narco'},
@@ -48,45 +54,46 @@ const heroes = [
4854
{id: 19, name: 'Magma'},
4955
{id: 20, name: 'Tornado'}
5056
];
57+
// #enddocregion heroes-array
5158

59+
// #docregion resolvers
5260
const resolveFunctions = {
5361
Query: {
5462
heroes() {
5563
return heroes;
5664
},
57-
hero(obj: any, params: any, context: any) {
58-
return find(heroes, { id: params.heroId });
65+
hero(obj: any, args: any, context: any) {
66+
return find(heroes, { id: args.heroId });
5967
}
6068
},
6169
Mutation: {
62-
updateHero(root: any, params: any) {
63-
let hero = find(heroes, { id: params.heroId });
70+
updateHero(root: any, args: any) {
71+
let hero = find(heroes, { id: args.heroId });
6472
if (!hero) {
65-
throw new Error(`Couldn't find post with id ${params.heroId}`);
73+
throw new Error(`Couldn't find post with id ${args.heroId}`);
6674
}
67-
hero = params.heroId;
75+
hero = args.heroId;
6876
return hero;
6977
},
70-
addHero(root: any, params: any) {
78+
addHero(root: any, args: any) {
7179
const maxId = Math.max(...heroes.map((hero)=>{return hero.id}));
7280
const newHero = {
73-
name: params.heroName,
81+
name: args.heroName,
7482
id: maxId + 1
7583
};
7684
heroes.push(newHero);
7785
return(newHero);
7886
}
7987
}
8088
}
81-
89+
// #enddocregion resolvers
90+
// #docregion make-executable-schema
8291
const schema = makeExecutableSchema({
8392
typeDefs: typeDefinitions,
8493
resolvers: resolveFunctions,
8594
});
86-
87-
// in-browser-network-interface.js
88-
import { execute } from 'graphql';
89-
95+
// #enddocregion make-executable-schema
96+
// #docregion execute-and-export
9097
class InBrowserNetworkInterface {
9198
schema: any = {};
9299
constructor(params: any) {
@@ -105,4 +112,5 @@ class InBrowserNetworkInterface {
105112
}
106113

107114
export const networkInterface = new InBrowserNetworkInterface({ schema });
115+
// #enddocregion execute-and-export
108116
// #enddocregion

0 commit comments

Comments
 (0)