UNPKG

graphile-utils

Version:
28 lines 1.23 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); function makeChangeNullabilityPlugin(rules) { return (builder, _options) => { function changeNullability(field, build, context) { const { Self, scope: { fieldName }, } = context; const typeRules = rules[Self.name]; if (!typeRules) { return field; } const shouldBeNullable = typeRules[fieldName]; if (shouldBeNullable == null) { return field; } const { graphql: { getNullableType, GraphQLNonNull }, } = build; const nullableType = getNullableType(field.type); return Object.assign(Object.assign({}, field), { type: shouldBeNullable ? nullableType : nullableType === field.type ? new GraphQLNonNull(field.type) : field.type }); } builder.hook("GraphQLInputObjectType:fields:field", changeNullability); builder.hook("GraphQLObjectType:fields:field", changeNullability); }; } exports.default = makeChangeNullabilityPlugin; //# sourceMappingURL=makeChangeNullabilityPlugin.js.map