GraphQL Error field type must be Input Type but got:
Solution 1:
In GraphQL, an input
cannot be used as a type
and a type
cannot be used as an input
. Unfortunately, even if the fields appear identical to an existing type, you always have to define a separate input to use as an argument. Try something like this:
const NotebookDetailsInput = new GraphQLInputObjectType({
name: 'NotebookDetailsInput',
fields: () => ({
id: { type: GraphQLID },
description: { type: GraphQLString },
language: { type: GraphQLString },
})
});
If using SDL, the same type would look like this:
input {
id: ID
description: String
language: String
}
Please see this answer for an extensive explanation of why it's necessary to do this.
Solution 2:
For those who are using graphql-tools
and stumble accross this post, documentation is here at GraphQL's Website.
My Example using graphQL tools is here below: (this has an input inside of an input AKA an ImageInput
inside the SocialPostInput
)
//mutation file
extend type Mutation {
SchedulePost (
socialPost: SocialPostInput,
schedule: ScheduleInput
): ScheduledPost
}`
//Schedule and SocialPost file
type Image {
id: String
url: String
}
type SocialPost {
id: String
GCID: String
message: String
image: Image
}
input ImageInput {
url: String
}
input SocialPostInput {
GCID: String
message: String
image: ImageInput
}
type Schedule {
id: String
month: Int
date: Int
hour: Int
minute: Int
}
input ScheduleInput {
id: String
month: Int
date: Int
hour: Int
minute: Int
}`
Solution 3:
If you describe schema within schema.graphql file, just replace type to input:
Wrong:
type SomeData {
someField: String!
}
Right:
input SomeData {
someField: String!
}