From 9899171cc06191ef8f5efca119421fe856022e45 Mon Sep 17 00:00:00 2001 From: Tlvenn Date: Wed, 23 Sep 2015 00:15:09 +0800 Subject: [PATCH 1/3] Add appendField, fix #5 --- README.md | 5 ++++- src/baseObject.js | 11 +++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 384ed4a..58da8c0 100644 --- a/README.md +++ b/README.md @@ -142,6 +142,7 @@ Define a new `GraphQLEnumType` Define a new `GraphQLInterfaceType`. +##### .appendField(name, field) ##### .field(name, type, description) ##### .deprecated(deprecationReason) ##### .arg(name, type, defaultValue, description) @@ -151,9 +152,11 @@ Define a new `GraphQLInterfaceType`. Define a new `GraphQLObjectType`. +##### .appendField(name, field) ##### .field(name, type, description) ##### .deprecated(deprecationReason) ##### .arg(name, type, defaultValue, description) +##### .isTypeOf(fn) ##### .resolve(fn) ## schemaFrom(queryRootType, mutationRootType) @@ -170,4 +173,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 7c388b5..76784bf 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 */ From d063e0575f732926ca1577e1ed3e2b4bdf7204ca Mon Sep 17 00:00:00 2001 From: Tlvenn Date: Wed, 23 Sep 2015 00:23:27 +0800 Subject: [PATCH 2/3] Allow field args to be defined in one step, fix #6 --- src/baseObject.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/baseObject.js b/src/baseObject.js index 6b3fdee..ee52a96 100644 --- a/src/baseObject.js +++ b/src/baseObject.js @@ -84,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) { From 9cafa65806bfa84d1cc977428e25b744ca241985 Mon Sep 17 00:00:00 2001 From: Tlvenn Date: Wed, 23 Sep 2015 00:26:04 +0800 Subject: [PATCH 3/3] Document new args method --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 58da8c0..11a636f 100644 --- a/README.md +++ b/README.md @@ -145,6 +145,7 @@ Define a new `GraphQLInterfaceType`. ##### .appendField(name, field) ##### .field(name, type, description) ##### .deprecated(deprecationReason) +##### .args(args) ##### .arg(name, type, defaultValue, description) ##### .resolve(fn) @@ -155,6 +156,7 @@ Define a new `GraphQLObjectType`. ##### .appendField(name, field) ##### .field(name, type, description) ##### .deprecated(deprecationReason) +##### .args(args) ##### .arg(name, type, defaultValue, description) ##### .isTypeOf(fn) ##### .resolve(fn)