Last active
October 23, 2019 19:41
-
-
Save kristianmandrup/1f7e4a550e6c32b99881aa1b78a4a440 to your computer and use it in GitHub Desktop.
Revisions
-
kristianmandrup revised this gist
Nov 16, 2018 . 1 changed file with 16 additions and 23 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,7 +2,6 @@ import { makeExecutableSchema, addMockFunctionsToSchema } from "graphql-tools"; import { graphql } from "graphql"; import { ApolloClient } from "apollo-client"; import { from } from "apollo-link"; import { withClientState } from "apollo-link-state"; import { InMemoryCache } from "apollo-cache-memory"; import GoalsSchema from "../api/goals/Goal.graphql"; @@ -39,19 +38,13 @@ const revisedRandId = () => .substr(2, 10); // mock order const order = {}; // mock user const user = {}; const product = {}; const allProducts = [product]; const mocks = { ID: () => revisedRandId(), @@ -64,24 +57,24 @@ const mocks = { User: () => ({ ...user }) }; addMockFunctionsToSchema({ schema, mocks }); const mockMang = async (query, args = {}) => { try { const res = await graphql(schema, query.loc.source.body, null, null, args); res.data.loading = false; return res.data; } catch (err) { return console.log(err.message); } }; export { client }; export const mockFunc = () => null; export const mockAsyncFunc = async () => true; export default mockMang; -
kristianmandrup created this gist
Nov 13, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,87 @@ import { makeExecutableSchema, addMockFunctionsToSchema } from "graphql-tools"; import { graphql } from "graphql"; import { ApolloClient } from "apollo-client"; import { from } from "apollo-link"; import gql from "graphql-tag"; import { withClientState } from "apollo-link-state"; import { InMemoryCache } from "apollo-cache-memory"; import GoalsSchema from "../api/goals/Goal.graphql"; // import { defaultState } from '../ui/config/apollo/defaultState' const defaultState = {}; // import { defaultState } from '../ui/config/apollo/stateMutations' const stateMutations = {}; const stateLink = withClientState({ cache: new InMemoryCache(), resolvers: stateMutations, defaults: defaultState }); // client.onResetStore(stateLink.writeDefaults) const link = from({ stateLink }); const client = new ApolloClient({ link, cache: new InMemoryCache() }); const typeDefs = [GoalsSchema]; const schema = makeExecutableSchema({ typeDefs }); const revisedRandId = () => Math.random() .toString(36) .replace(/[^a-z]+/g, "") .substr(2, 10); // mock order const order = { } // mock user const user = { } const product = { } const allProducts = [product] const mocks = { ID: () => revisedRandId(), Product: () => ({ ...product }), Order: () => ({ ...order }), User: () => ({ ...user }) } addMockFunctionsToSchema({schema, mocks}) const mockMang = await (query, args = {}) => { try { const res = await graphql(schema, query.loc.source.body, null, null, args) res.data.loading = false return res.data } catch (err) { return console.log(err.message) } } export { client } export const mockFunc = () => null export const mockAsyncFunc = async () => true export default mockMang