Skip to content
This repository has been archived by the owner on Feb 10, 2022. It is now read-only.

Add appendField feature, closes #5 #7

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,18 +142,23 @@ Define a new `GraphQLEnumType`

Define a new `GraphQLInterfaceType`.

##### .appendField(name, field)
##### .field(name, type, description)
##### .deprecated(deprecationReason)
##### .args(args)
##### .arg(name, type, defaultValue, description)
##### .resolve(fn)

### objectType(name, [interfaces], description)

Define a new `GraphQLObjectType`.

##### .appendField(name, field)
##### .field(name, type, description)
##### .deprecated(deprecationReason)
##### .args(args)
##### .arg(name, type, defaultValue, description)
##### .isTypeOf(fn)
##### .resolve(fn)

## schemaFrom(queryRootType, mutationRootType)
Expand All @@ -170,4 +175,4 @@ Define a new `GraphQLNonNull(type)`.

# Thanks

Thanks to [Florent Cailhol](https://github.com/ooflorent) for the chainable interface idea!
Thanks to [Florent Cailhol](https://github.com/ooflorent) for the chainable interface idea!
20 changes: 20 additions & 0 deletions src/baseObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,17 @@ export default class BaseObject {
}
}

appendField(name, field) {
this.__saveField();

invariant(
!this.fields[name],
`appendField(...): '${name}' is already defined`
);

this.fields[name] = field;
}

field(name, type, description, resolve) {
if (typeof description === 'function') {
/* eslint-disable no-param-reassign */
Expand Down Expand Up @@ -73,6 +84,15 @@ export default class BaseObject {

return this;
}

args(args) {
invariant(
this.__field,
`args(...) must appear under a field`
);

this.__field.args = args;
}

arg(name, type, defaultValue, description) {
if (!description) {
Expand Down