From e1b6d7f601dc33286c2c9a6b8150b29c16f61e95 Mon Sep 17 00:00:00 2001 From: Theodor Diaconu Date: Thu, 19 Apr 2018 06:55:00 +0300 Subject: [PATCH] Updated readme and added mocking functionality --- docs/accounts.md | 20 ++++++++++++-------- docs/settings.md | 8 ++++++++ server/config.js | 1 + server/initialize.js | 10 +++++++++- 4 files changed, 30 insertions(+), 9 deletions(-) diff --git a/docs/accounts.md b/docs/accounts.md index 20cdbb6..b39cdb7 100644 --- a/docs/accounts.md +++ b/docs/accounts.md @@ -18,14 +18,16 @@ export default { ``` ```js -import { Config } from 'meteor/cultofcoders:apollo'; - -Config.USER_DEFAULT_FIELDS: { - _id: 1, - username: 1, - emails: 1, - roles: 1, -}, +import { initialize } from 'meteor/cultofcoders:apollo'; + +initialize({ + USER_DEFAULT_FIELDS: { + _id: 1, + username: 1, + emails: 1, + roles: 1, + } +}), ``` `userId` works with your client and with `/graphiql` because the `Meteor.loginToken` is stored in `localStorage` and it's on the same domain, making very easy for you to test your queries and mutations. @@ -38,6 +40,8 @@ meteor npm i -S bcrypt meteor add cultofcoders:apollo-accounts ``` +Make sure you have a type called `User` already defined and loaded, otherwise it will fail. + ```js // file: /server/accounts.js import { initAccounts } from 'meteor/cultofcoders:apollo-accounts'; diff --git a/docs/settings.md b/docs/settings.md index dbcb164..2195a94 100644 --- a/docs/settings.md +++ b/docs/settings.md @@ -44,6 +44,14 @@ When initializing, we accept as an argument a configuration object: emails: 1, roles: 1, }, + + // OPTIONS TO ADD ADDITIONAL MOCKING + // By default this is null + // Read more: https://www.apollographql.com/docs/graphql-tools/mocking.html + MOCKING: { + mocks: {}, + preserveResolvers: false, + } } ``` diff --git a/server/config.js b/server/config.js index f303c39..ca4f304 100644 --- a/server/config.js +++ b/server/config.js @@ -13,6 +13,7 @@ let Config = { GRAPHQL_VALIDATION_RULES: [], GRAPHQL_SCHEMA_DIRECTIVES: {}, EXPRESS_MIDDLEWARES: [], + MOCKING: null, }; export default Config; diff --git a/server/initialize.js b/server/initialize.js index a93b5e5..2aa63a0 100644 --- a/server/initialize.js +++ b/server/initialize.js @@ -1,5 +1,5 @@ import { Meteor } from 'meteor/meteor'; - +import { addMockFunctionsToSchema } from 'graphql-tools'; import { createServer } from './apolloServer'; import { createSubscriptionServer } from './subcriptionServer'; import { createEngine } from './engineServer'; @@ -16,6 +16,14 @@ export default function initialize(config = {}) { Object.freeze(Config); const schema = getExecutableSchema(); + + if (Config.MOCKING) { + addMockFunctionsToSchema({ + schema, + ...Config.MOCKING, + }); + } + const app = createServer({ schema }); if (Config.ENGINE_API_KEY) {