Learning React
Learning React
During my practice of writing GraphQL using a Schema Language, I encountered an error like below:
Error: The type of ... must be Input Type but got: ...
Googling it led me to the GraphQL documentation: https://graphql.org/graphql-js/mutations-and-input-types/.
It indicates that aside from the Query and Mutation type of the schema language, there is also an Input type. Below is what I encountered of the error and the fix to it.
In my mutation schema below, I am trying to use the type TvmProperties as my type for my properties parameter in computePv(). GraphQL don't accept that and will throw an error.
type TvmProperties {
pv: String
fv: String
...
}
type Mutation {
computePv(properties: TvmProperties): Float!
}
I fixed it by making another object with input keyword to it instead of the type. With this approached GraphQL knows that the typing I am making is for inputs.
input TvmPropertiesInput {
pv: Float
fv: Float
...
}
type Mutation {
computePv(properties: TvmPropertiesInput): Float!
}