My GraphQL schema looks like this:
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
}
In database, Outer object is store this way:
{
id: 1,
name: ‘test’,
inner: [5, 6] //IDs of inner objects. Not the entire inner object
}
Outer and Inner are stored in separate database collections/tables (I’m using DynamoDB)
My resolvers look like this:
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
}
}
But I’m not able to write a resolver for the ‘inner’ field in ‘OuterInput’ similar to what I did for ‘Outer’. GraphQL throws an error saying
Error: OuterInput was defined in resolvers, but it's not an object
How can I handle such a scenario if writing resolvers for Input types are not allowed?