【发布时间】:2019-04-03 14:38:33
【问题描述】:
我的 GraphQL 架构如下所示:
type Outer {
id: ID
name: String,
inner: [Inner]
}
type Inner {
id: ID
name: String
}
input OuterInput {
name: String,
inner: InnerInput
}
Input InnerInput {
name: String
}
type Query {
getOuter(id: ID): Outer
}
type Mutation {
createOuter(outer: OuterInput): Outer
}
在数据库中,外部对象是这样存储的:
{
id: 1,
name: ‘test’,
inner: [5, 6] //IDs of inner objects. Not the entire inner object
}
外部和内部存储在单独的数据库集合/表中(我使用的是 DynamoDB)
我的解析器如下所示:
Query: {
getOuter: (id) => {
//return ‘Outer’ object with the ‘inner’ IDs from the database since its stored that way
}
}
Outer: {
inner: (outer) => {
//return ‘Inner’ objects with ids from ‘outer.inner’ is returned
}
}
Mutation: {
createOuter: (outer) => {
//extract out the IDs out of the ‘inner’ field in ‘outer’ and store in DB.
}
}
OuterInput: {
inner: (outer) => {
//Take the full ‘Inner’ objects from ‘outer’ and store in DB.
// This is the cause of the error
}
}
但我无法为“OuterInput”中的“inner”字段编写解析器,类似于我为“Outer”所做的。 GraphQL 抛出错误说
Error: OuterInput was defined in resolvers, but it's not an object
如果不允许为输入类型编写解析器,我该如何处理?
【问题讨论】:
标签: graphql apollo-server