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

Commit c8bc54d

Browse files
committed
docs(graphql-cookbook): Add Mocked network interface
1 parent 099e551 commit c8bc54d

File tree

9 files changed

+135
-40
lines changed

9 files changed

+135
-40
lines changed

public/docs/_examples/heroes-graphql/ts/rollup-config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export default {
4242
namedExports: {
4343
'node_modules/graphql-tools/dist/index.js': ['makeExecutableSchema' ],
4444
'node_modules/graphql/index.js': ['execute' ],
45-
'node_modules/graphql-tag/printer.js': ['print'],
45+
'node_modules/graphql-tag/bundledPrinter.js': ['print'],
4646
'node_modules/lodash/lodash.js': ['find', 'omit', 'assign', 'isFunction'],
4747
}
4848
}),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// #docplaster
2+
// #docregion
3+
4+
// #docregion v1, v2
5+
import { NgModule } from '@angular/core';
6+
import { BrowserModule } from '@angular/platform-browser';
7+
import { FormsModule } from '@angular/forms';
8+
import { HttpModule } from '@angular/http';
9+
10+
import { AppRoutingModule } from './app-routing.module';
11+
12+
// #enddocregion v1
13+
14+
// #docregion import-apollo
15+
import { ApolloModule } from 'apollo-angular';
16+
import { getClient } from './client';
17+
// #enddocregion import-apollo
18+
19+
// #docregion v1
20+
import { AppComponent } from './app.component';
21+
import { DashboardComponent } from './dashboard.component';
22+
import { HeroesComponent } from './heroes.component';
23+
import { HeroDetailComponent } from './hero-detail.component';
24+
// #enddocregion v1, v2
25+
import { HeroSearchComponent } from './hero-search.component';
26+
// #docregion v1, v2
27+
28+
// #docregion apollo-ngmodule
29+
@NgModule({
30+
imports: [
31+
BrowserModule,
32+
FormsModule,
33+
HttpModule,
34+
InMemoryWebApiModule.forRoot(InMemoryDataService),
35+
// #enddocregion v1
36+
// #docregion v1
37+
AppRoutingModule,
38+
ApolloModule.forRoot(getClient)
39+
],
40+
// #docregion search
41+
declarations: [
42+
// #enddocregion apollo-ngmodule
43+
AppComponent,
44+
DashboardComponent,
45+
HeroDetailComponent,
46+
HeroesComponent,
47+
// #enddocregion v1, v2
48+
HeroSearchComponent
49+
// #docregion v1, v2
50+
],
51+
// #enddocregion search
52+
bootstrap: [ AppComponent ]
53+
})
54+
export class AppModule { }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// #docregion
2+
import { ApolloClient } from 'apollo-client';
3+
// #docregion import-and-use
4+
import { mockNetworkInterface } from './mockedNetworkInterface';
5+
6+
const client = new ApolloClient({
7+
networkInterface: mockNetworkInterface
8+
});
9+
// #enddocregion import-and-use
10+
export function getClient(): ApolloClient {
11+
return client;
12+
}
13+
// #enddocregion

public/docs/_examples/heroes-graphql/ts/src/app/heroes.component.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export class HeroesComponent implements OnInit {
4242
}
4343
`
4444
}).subscribe((queryResult: ApolloQueryResult<{ heroes: Hero[] }>) => {
45-
this.heroes = queryResult.data.heroes;
45+
this.heroes = queryResult.data.heroes.slice();
4646
});
4747
}
4848
// #enddocregion query-heroes

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

+1-37
Original file line numberDiff line numberDiff line change
@@ -9,43 +9,7 @@ import { makeExecutableSchema } from 'graphql-tools';
99
import { execute } from 'graphql';
1010
// #enddocregion import-graphql
1111
// #docregion graphql-schema
12-
const typeDefinitions = `
13-
# the model
14-
type Hero {
15-
id: Int!
16-
name: String!
17-
}
18-
19-
# The schema allows the following queries:
20-
type Query {
21-
heroes(search: String): [Hero]
22-
23-
hero(heroId: Int!): Hero
24-
}
25-
26-
# This schema allows the following mutation:
27-
type Mutation {
28-
updateHero (
29-
id: Int!
30-
name: String!
31-
): Hero
32-
33-
addHero (
34-
heroName: String!
35-
): Hero
36-
37-
deleteHero (
38-
id: Int!
39-
): Hero
40-
}
41-
42-
# Tell the server which types represent the root query and root mutation types.
43-
# By convention, they are called RootQuery and RootMutation.
44-
schema {
45-
query: Query
46-
mutation: Mutation
47-
}
48-
`;
12+
import { typeDefinitions } from './schema';
4913
// #enddocregion graphql-schema
5014
// #docregion heroes-array
5115
let heroes = [
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// #docregion
2+
// #docregion imports
3+
import {
4+
makeExecutableSchema,
5+
addMockFunctionsToSchema
6+
} from 'graphql-tools';
7+
import { mockNetworkInterfaceWithSchema } from 'apollo-test-utils';
8+
import { typeDefinitions } from './schema';
9+
// #enddocregion imports
10+
11+
// #docregion create-interface
12+
const schema = makeExecutableSchema({
13+
typeDefs: typeDefinitions
14+
});
15+
addMockFunctionsToSchema({ schema });
16+
export const mockNetworkInterface = mockNetworkInterfaceWithSchema({ schema });
17+
// #enddocregion create-interface
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// #docregion
2+
export const typeDefinitions = `
3+
# the model
4+
type Hero {
5+
id: Int!
6+
name: String!
7+
}
8+
9+
# The schema allows the following queries:
10+
type Query {
11+
heroes(search: String): [Hero]
12+
13+
hero(heroId: Int!): Hero
14+
}
15+
16+
# This schema allows the following mutation:
17+
type Mutation {
18+
updateHero (
19+
id: Int!
20+
name: String!
21+
): Hero
22+
23+
addHero (
24+
heroName: String!
25+
): Hero
26+
27+
deleteHero (
28+
id: Int!
29+
): Hero
30+
}
31+
32+
# Tell the server which types represent the root query and root mutation types.
33+
# By convention, they are called RootQuery and RootMutation.
34+
schema {
35+
query: Query
36+
mutation: Mutation
37+
}
38+
`;

public/docs/_examples/heroes-graphql/ts/src/systemjs.config.extras.js

+8
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ System.config({
1818
'redux': 'npm:redux/dist/redux.min.js',
1919
// #enddocregion systemjs-apollo-client-map
2020

21+
// #docregion systemjs-apollo-test-utils-map
22+
'apollo-test-utils': 'npm:apollo-test-utils',
23+
2124
// #docregion systemjs-graphql-server-map
2225
'graphql': 'npm:graphql',
2326
'graphql-tools': 'npm:graphql-tools',
@@ -27,6 +30,7 @@ System.config({
2730
'iterall': 'npm:iterall',
2831
'lodash': 'npm:lodash'
2932
// #enddocregion systemjs-graphql-server-map
33+
// #enddocregion systemjs-apollo-test-utils-map
3034
},
3135
packages: {
3236

@@ -41,6 +45,9 @@ System.config({
4145
},
4246
// #enddocregion systemjs-apollo-client-packages
4347

48+
// #docregion systemjs-apollo-test-utils-packages
49+
'apollo-test-utils': { main: '/dist/src/index.js', defaultExtension: 'js' },
50+
4451
// #docregion systemjs-graphql-server-packages
4552
'graphql': {
4653
main: './index.js',
@@ -64,5 +71,6 @@ System.config({
6471
'iterall': { main: './index.js', defaultExtension: 'js' },
6572
'lodash': { main: './index.js', defaultExtension: 'js' }
6673
// #enddocregion systemjs-graphql-server-packages
74+
// #enddocregion systemjs-apollo-test-utils-packages
6775
}
6876
});

public/docs/_examples/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@
4848
"@angular/upgrade": "2.4.5",
4949
"angular-in-memory-web-api": "~0.2.4",
5050
"apollo-angular": "^0.12.0",
51-
"apollo-client": "1.0.0-rc.5",
51+
"apollo-client": "^1.0.0-rc.5",
52+
"apollo-test-utils": "^0.2.1",
5253
"core-js": "^2.4.1",
5354
"graphql": "^0.9.1",
5455
"graphql-subscriptions": "^0.3.1",

0 commit comments

Comments
 (0)