builds relationship mutation input type

This commit is contained in:
James
2020-04-12 09:25:54 -04:00
parent d7aecddb38
commit 787c38c712
2 changed files with 25 additions and 1 deletions

View File

@@ -1,4 +1,4 @@
const { GraphQLObjectType, GraphQLSchema } = require('graphql');
const { GraphQLObjectType, GraphQLSchema, GraphQLInputObjectType } = require('graphql');
const graphQLHTTP = require('express-graphql');
const buildObjectType = require('./schema/buildObjectType');

View File

@@ -56,6 +56,30 @@ function buildMutationInputType(name, fields, parentName) {
return { type };
},
relationship: (field) => {
const isRelatedToManyCollections = Array.isArray(field.relationTo);
let type = GraphQLString;
if (isRelatedToManyCollections) {
const fullName = `${combineParentName(parentName, field.label)}RelationshipInput`;
type = new GraphQLInputObjectType({
name: fullName,
fields: {
relationTo: new GraphQLEnumType({
name: `${fullName}RelationTo`,
values: field.relationTo.reduce((values, option) => ({
...values,
[option]: {
value: option,
},
}), {}),
}),
},
});
}
return field.hasMany ? new GraphQLList(type) : type;
},
repeater: (field) => {
const fullName = combineParentName(parentName, field.label);
let type = buildMutationInputType(fullName, field.fields, fullName);