Skip to content

Commit 24addda

Browse files
Fixed #4, #5, #2, #1
1 parent 4054131 commit 24addda

File tree

3 files changed

+26
-16
lines changed

3 files changed

+26
-16
lines changed

LinkDirective.js

+12-9
Original file line numberDiff line numberDiff line change
@@ -69,20 +69,23 @@ export default class LinkDirective extends SchemaDirectiveVisitor {
6969

7070
let config = {};
7171
if (args.to) {
72-
config = {
73-
inversedBy: args.to,
74-
};
72+
config = Object.assign({}, args);
73+
config.inversedBy = args.to;
74+
delete config.to;
7575
} else {
7676
if (args.field) {
77-
config = {
78-
type: isArrayField ? 'many' : 'one',
79-
field: args.field,
80-
index: true,
81-
};
77+
config = Object.assign(
78+
{
79+
type: isArrayField ? 'many' : 'one',
80+
field: args.field,
81+
index: true,
82+
},
83+
args
84+
);
8285
} else {
8386
throw new Meteor.Error(
8487
`invalid-args`,
85-
`You have provided invalid arguments for this specification`
88+
`You have provided invalid arguments for this link in ${thisCollectionName}. The "field" property is missing.`
8689
);
8790
}
8891
}

README.md

+11-6
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,21 @@ type Post @mongo(name: "posts") {
3030
}
3131
```
3232

33-
In the background, the schema directives analyze our types and create propper links, when we have a `field` present,
34-
that's going to be a main link, that's the collection we are going to store it in, when we have `to` present,
35-
that's going to be an inversed link.
33+
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.
3634

37-
Direct fields are automatically indexed by default.
35+
Direct fields are automatically indexed by default. You don't have to specify `index: true`
36+
37+
Options to direct links:
38+
39+
```js
40+
@map(field: "linkStorageField", autoremove: true, unique: true, metadata: true)
41+
```
42+
43+
For more information about options, refer to [Grapher API](https://github.com/cult-of-coders/grapher/blob/master/docs/api.md#adding-links)
3844

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

41-
The `@map` directive makes a database field be aliased. The reason for this is that when we query with Grapher's
42-
GraphQL abilities to properly adapt that field to the correspondant db field. In the backscene, we basically have a `reducer`.
47+
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`.
4348

4449
## Usage
4550

directiveDefinitions.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ export default `
66
directive @link(
77
field: String
88
to: String
9-
meta: Boolean
9+
metadata: Boolean
10+
unique: Boolean
11+
autoremove: Boolean
1012
) on FIELD_DEFINITION
1113
1214
directive @map(

0 commit comments

Comments
 (0)