graphql-schema icon indicating copy to clipboard operation
graphql-schema copied to clipboard

Add support to append entire field

Open tlvenn opened this issue 8 years ago • 2 comments

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 ?

tlvenn avatar Sep 21 '15 15:09 tlvenn

Example of schema using graphql-relay-js: https://github.com/facebook/relay/blob/master/examples/todo/data/schema.js

tlvenn avatar Sep 21 '15 15:09 tlvenn

@devknoll any comment ?

tlvenn avatar Oct 05 '15 19:10 tlvenn