graphql-schema
graphql-schema copied to clipboard
Add support to append entire field
In order to be friendly with Relay and graphql-relay-js lib, the API needs to allow the user to append some fields directly to an Object or an Interface.
Example would be to use the globalIdField
or the mutationWithClientMutationId
helpers from graphql-relay-js.
I was tempted to hack the field method but then it breaks the promise that it's a field you can build on (add some args and define the resolve method) because the passed object literal define all of those already.
I suspect to avoid any confusion, we should have an explicit method to handle this. May be appendField(name:String,field:Object) and it would do :
appendField(name,field) {
this.__saveField();
invariant(
!this.fields[name],
`appendField(...): '${name}' is already defined`
);
this.fields[name] = field;
}
What do you think ?
Example of schema using graphql-relay-js: https://github.com/facebook/relay/blob/master/examples/todo/data/schema.js
@devknoll any comment ?