Skip to content

Commit

Permalink
Updated README
Browse files Browse the repository at this point in the history
  • Loading branch information
tomitrescak committed Sep 9, 2016
1 parent ca7655a commit b496f52
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
38 changes: 37 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,25 @@ This set of helpers facilitates the use of GraphQL and Apollo, it allows you to

# Server

This package allows for modular definition of GraphQL schema.
Modular definition can reflect the strucutre of your **Domain Elements**.
The advantage of this approach is that you can keep your queries and mutations
close to your domain element.
A graphQL module contains following properties:

```typescript
declare interface IApolloQueryDefinition {
declare interface ApolloModule {
// definition of types
schema: string;
// definition of queries
queryText?: string;
// implementation of queries
queries?: Object;
// implementation of type resolvers
resolvers?: Object;
// definition of mutations
mutationText?: string;
// implmentation of mutations
mutations?: Object;
// allows you to modify apollo Options (e.g. context) based on current request
modifyOptions?: (req: any, apolloOptions: ApolloOptions) => void
Expand All @@ -25,6 +37,28 @@ declare interface IApolloQueryDefinition {

Please see the section **Examples** examples on how to use the [domain element schema](#schema) and also how to use server helpers:

To use modules in your code you need to do following:

```javascript
import { addModules } from 'apollo-modules';
import { makeExecutableSchema } from 'graphql-tools';
import myModule from './my_module';

// import all your modules
const modules = addModules([
myModule,
...
];

// build your schema
const schema = makeExecutableSchema({ typeDefs: modules.schema, resolvers: modules.resolvers, allowUndefinedInResolve: true });

// init your apollo server as usual
...
```
Following are the availabel methods from this package.
1. `addModules(definition: IApolloQueryDefinition[]): void`: compiles schema of several domain elements (Example: [Generating schemas](#generation))
2. `createServer(apolloOptions?: ApolloOptions, executableSchema?: any): (req: any) => IApolloOptions` provides easy initialisation of the Apollo server.
3. `ioSchema`: generates your defined schema type as both input and ouput type. This is used, when you want to be sending whole documents to GraphQL server and probably is not the best practice. When defining the IO type all you need to do is to append the $Input after the type name. (Example: [Advanced Schema](#ioschema))
Expand Down Expand Up @@ -60,6 +94,8 @@ app.use('/graphql', apollo.apolloExpress(createServer(graphqlOptions)));
## Simple schema<a name="schema" id="schema"></a>
In this example we initialise a simple schema that modifies the context upon each request.
```typescript
import { Mongo } from 'meteor/mongo';
import { Exercises } from './exercise_schema';
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "apollo-modules",
"version": "0.0.3",
"version": "0.0.4",
"description": "Modular system for building apollo schemas",
"repository": {
"url": "https://github.com/tomitrescak/apollo-modules"
Expand Down

0 comments on commit b496f52

Please sign in to comment.