Skip to content

Commit

Permalink
Updated readme and added mocking functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
theodorDiaconu committed Apr 19, 2018
1 parent 386d497 commit e1b6d7f
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 9 deletions.
20 changes: 12 additions & 8 deletions docs/accounts.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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';
Expand Down
8 changes: 8 additions & 0 deletions docs/settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
```

Expand Down
1 change: 1 addition & 0 deletions server/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ let Config = {
GRAPHQL_VALIDATION_RULES: [],
GRAPHQL_SCHEMA_DIRECTIVES: {},
EXPRESS_MIDDLEWARES: [],
MOCKING: null,
};

export default Config;
10 changes: 9 additions & 1 deletion server/initialize.js
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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) {
Expand Down

0 comments on commit e1b6d7f

Please sign in to comment.