Skip to content

Commit 3c63a00

Browse files
committed
first commit
1 parent 7c45c51 commit 3c63a00

File tree

4 files changed

+15
-7
lines changed

4 files changed

+15
-7
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,4 @@ This section has moved here: https://facebook.github.io/create-react-app/docs/de
6666
### `npm run build` fails to minify
6767

6868
This section has moved here: https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify
69+
# ApolloMockingExample

src/Repository.test.jsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,18 @@ import { render } from "./mocking/ApolloMockingProvider";
44

55
const zenhubRepo = {
66
Repository: () => ({
7-
name: 'ZenHubHQ'
7+
name: "ZenHubHQ"
88
})
99
};
1010

1111
const threeIssues = {
1212
Repository: () => ({
13-
issues: [{ number: 1, title: "Issue 1" }, { number:2, title: "Issue 2" }, { number:3, title: "Issue 3" }]
14-
}),
13+
issues: [
14+
{ number: 1, title: "Issue 1" },
15+
{ number: 2, title: "Issue 2" },
16+
{ number: 3, title: "Issue 3" }
17+
]
18+
})
1519
};
1620

1721
describe("<Repository />", () => {

src/mocking/ApolloMockingProvider.jsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,27 @@ import { InMemoryCache } from "apollo-cache-inmemory";
1010
import { ApolloProvider } from "react-apollo";
1111
import { SchemaLink } from "apollo-link-schema";
1212

13-
import generalMocks from "./generalMocks";
13+
import defaultMocks from "./defaultMocks";
1414
import mergeResolvers from "./mergeResolvers";
1515

1616
const ApplicationSchema = loader("./schema.graphql");
1717

1818
// For queries with no variables
1919
const schema = makeExecutableSchema({ typeDefs: ApplicationSchema });
2020

21-
const ApolloMockingProvider = ({ children, customResolvers }) => {
22-
const mocks = mergeResolvers([generalMocks, customResolvers]);
21+
export const getClient = customResolvers => {
22+
const mocks = mergeResolvers([defaultMocks, customResolvers]);
2323

2424
addMockFunctionsToSchema({ schema, mocks });
2525

26-
const client = new ApolloClient({
26+
return new ApolloClient({
2727
link: new SchemaLink({ schema }),
2828
cache: new InMemoryCache()
2929
});
30+
};
3031

32+
const ApolloMockingProvider = ({ children, customResolvers }) => {
33+
const client = getClient(customResolvers);
3134
return <ApolloProvider client={client}>{children}</ApolloProvider>;
3235
};
3336

0 commit comments

Comments
 (0)