diff --git a/README.md b/README.md index 384ed4a..11a636f 100644 --- a/README.md +++ b/README.md @@ -142,8 +142,10 @@ 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) @@ -151,9 +153,12 @@ Define a new `GraphQLInterfaceType`. 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) @@ -170,4 +175,4 @@ Define a new `GraphQLNonNull(type)`. # Thanks -Thanks to [Florent Cailhol](https://github.com/ooflorent) for the chainable interface idea! \ No newline at end of file +Thanks to [Florent Cailhol](https://github.com/ooflorent) for the chainable interface idea! diff --git a/src/baseObject.js b/src/baseObject.js index 72ca363..ee52a96 100644 --- a/src/baseObject.js +++ b/src/baseObject.js @@ -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 */ @@ -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) {