Skip to content

Commit 2d7d750

Browse files
ekoszmickhansen
authored andcommitted
Add more documentation on custom connection arguments (#245)
Closes #242
1 parent 50af08e commit 2d7d750

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

docs/relay.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,3 +174,40 @@ fragment getCreated on userTaskEdge {
174174
wasCreatedByUser
175175
}
176176
```
177+
178+
You can pass custom args in your connection definition and they will
179+
automaticly be turned into where arguments. These can be further modified
180+
using the `where` option in `sequelizeConnection`.
181+
182+
```js
183+
const userTaskConnection = sequelizeConnection({
184+
name: 'userTask',
185+
nodeType: taskType,
186+
target: User.Tasks,
187+
where: function (key, value) {
188+
if (key === 'titleStartsWith') {
189+
return { title: { $like: `${value}%` } };
190+
} else {
191+
return {[key]: value};
192+
}
193+
},
194+
});
195+
const userType = new GraphQLObjectType({
196+
name: User.name,
197+
fields: {
198+
id: globalIdField(User.name),
199+
name: {
200+
type: GraphQLString
201+
},
202+
tasks: {
203+
type: userTaskConnection.connectionType,
204+
args: {
205+
...userTaskConnection.connectionArgs, // <-- Load the defaults
206+
titleStartsWith: { // <-- Extend further yourself
207+
type: GraphQLString,
208+
}
209+
},
210+
resolve: userTaskConnection.resolve
211+
}
212+
}
213+
});

0 commit comments

Comments
 (0)