Skip to content

Commit

Permalink
Fixed #4, #5, #2, #1
Browse files Browse the repository at this point in the history
  • Loading branch information
theodorDiaconu committed Jul 31, 2018
1 parent 4054131 commit 24addda
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 16 deletions.
21 changes: 12 additions & 9 deletions LinkDirective.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,20 +69,23 @@ export default class LinkDirective extends SchemaDirectiveVisitor {

let config = {};
if (args.to) {
config = {
inversedBy: args.to,
};
config = Object.assign({}, args);
config.inversedBy = args.to;
delete config.to;
} else {
if (args.field) {
config = {
type: isArrayField ? 'many' : 'one',
field: args.field,
index: true,
};
config = Object.assign(
{
type: isArrayField ? 'many' : 'one',
field: args.field,
index: true,
},
args
);
} else {
throw new Meteor.Error(
`invalid-args`,
`You have provided invalid arguments for this specification`
`You have provided invalid arguments for this link in ${thisCollectionName}. The "field" property is missing.`
);
}
}
Expand Down
17 changes: 11 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,21 @@ type Post @mongo(name: "posts") {
}
```

In the background, the schema directives analyze our types and create propper links, when we have a `field` present,
that's going to be a main link, that's the collection we are going to store it in, when we have `to` present,
that's going to be an inversed link.
In the background, the schema directives analyze our types and create propper links, when we have a `field` present, that's going to be a main link, that's the collection we are going to store it in, when we have `to` present, that's going to be an inversed link.

Direct fields are automatically indexed by default.
Direct fields are automatically indexed by default. You don't have to specify `index: true`

Options to direct links:

```js
@map(field: "linkStorageField", autoremove: true, unique: true, metadata: true)
```

For more information about options, refer to [Grapher API](https://github.com/cult-of-coders/grapher/blob/master/docs/api.md#adding-links)

Each `ObjectType` needs to have the propper `@mongo` directive to work.

The `@map` directive makes a database field be aliased. The reason for this is that when we query with Grapher's
GraphQL abilities to properly adapt that field to the correspondant db field. In the backscene, we basically have a `reducer`.
The `@map` directive makes a database field be aliased. The reason for this is that when we query with Grapher's GraphQL abilities to properly adapt that field to the correspondant db field. In the backscene, we basically have a `reducer`.

## Usage

Expand Down
4 changes: 3 additions & 1 deletion directiveDefinitions.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ export default `
directive @link(
field: String
to: String
meta: Boolean
metadata: Boolean
unique: Boolean
autoremove: Boolean
) on FIELD_DEFINITION
directive @map(
Expand Down

0 comments on commit 24addda

Please sign in to comment.