I'm trying to implement an input type for filters with graphql-ruby and rails.
Base input type looks like:
module Types
class BaseInputObject < GraphQL::Schema::InputObject
end
end
My own input type looks like:
module Types
class PhotoFilterType < Types::BaseInputObject
argument :attribution, String, "Filters by submitter", required: false
argument :country, String, "Filters by country", required: false
argument :year, Int, "Filters by year", required: false
end
end
query_type's method header looks like:
field :filtered_photos, [Types::PhotoType], null: true do
argument :filters, Types::PhotoFilterType, 'filters for photo', required: true
end
And the query as follows:
const FILTER_QUERY = gql`
query getFilteredPhotos($filters: PhotoFilterType!) {
filteredPhotos(filters: $filters) {
id
title
width
height
}
}
`
Interacting with the backend using react-apollo as follows:
this.props.client.query({
query: FILTER_QUERY,
variables: {
filters: {
attribution: author.length > 0 ? author : '',
country: country.length > 0 ? country : '',
year: year ? year : 9999
}
}
})
I get the following error
{message: "PhotoFilterType isn't a defined input type (on $filters)",…}
But when I interact with rails console, I see:
irb(main):004:0> Types::PhotoFilterType
=> Types::PhotoFilterType
So I don't think the type being undefined is an issue.
Any idea what is going wrong and how to fix it? Thanks in advance.
Problem was solved by changing:
const FILTER_QUERY = gql`
query getFilteredPhotos($filters: PhotoFilter!) { // not PhotoFilterType
filteredPhotos(filters: $filters) {
id
title
width
height
}
}
`