Skip to content

Instantly share code, notes, and snippets.

@taion
Created August 21, 2016 20:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save taion/2d6d5c9c07029a08117a2e7ee188797e to your computer and use it in GitHub Desktop.
Save taion/2d6d5c9c07029a08117a2e7ee188797e to your computer and use it in GitHub Desktop.
GraphQL CRUD partial updates
/* @flow */
import { GraphQLNonNull } from 'graphql';
export default function makeRequired(partial?: boolean) {
if (partial) {
return (type: mixed) => type;
}
return (type: mixed) => new GraphQLNonNull(type);
}
/* @flow */
import { GraphQLString } from 'graphql';
import makeRequired from './makeRequired';
export default function widgetFields(partial?: boolean) {
const required = makeRequired(partial);
return {
name: { type: required(GraphQLString) },
description: { type: GraphQLString },
color: { type: required(GraphQLString) },
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment