这里我有3种类型
JobType
EmployerType
SeekerType
job
只有一个Employer
创建了
const JobsType = new GraphQLObjectType({
name: 'JobsType',
fields: {
jobsId: {
type: GraphQLID,
resolve: obj => obj._id,
},
title: { type: GraphQLString },
description: { type: GraphQLString },
experience: { type: GraphQLString },
position: { type: GraphQLString },
openings: { type: GraphQLInt },
employer: {
type: EmployerType
resolve: () => // somedata here
}
},
});
Employer
可以创建多个jobs
所以
const EmployerType = new GraphQLObjectType({
name: 'EmployerType',
fields: {
userId: {
type: GraphQLID,
resolve: obj => obj._id,
},
company: { type: GraphQLString },
email: { type: GraphQLString },
password: { type: GraphQLString },
industry: { type: ENUM.IndustryType },
ownerShip: { type: ENUM.OwnerShipType },
website: { type: GraphQLString },
jobs: {
type: JobsType,
resolve: (obj) => // some data to resolve
}
},
});
seeker
可以适用于许多jobs
,
const SeekerType = new GraphQLObjectType({
name: 'SeekerType',
fields: {
userId: {
type: GraphQLID,
resolve: obj => obj._id,
},
email: { type: GraphQLString },
password: { type: GraphQLString },
firstName: { type: GraphQLString },
lastName: { type: GraphQLString },
education: { type: GraphQLString },
address: { type: GraphQLString },
jobs: {
type: JobsType,
resolve: (obj) => // some data to resolve
}
},
});
所以这里似乎在GraphQLObjectType
Jobs
包含EmployerType
,再次EmployerType
包含jobs
,而job
又包含EmployerType
所以喜欢这个
{
job {
jobId,
jobTitle,
employer {
userId,
company,
email,
job {
jobId,
jobTitle,
employer {
userId,
company,
email
}
}
}
}
}
这不是正确的方式,因为依赖关系越来越深入
同样适用于SeekerType
{
seeker {
userId,
email,
firstName,
lastName,
job {
jobId,
title,
description,
employer {
userId,
company,
email,
job {
jobId,
title,
employer {
userId,
company
}
}
}
}
}
}
这可能是什么解决方案