0

I am new to graphql, working on an existing schema. I've to add new filters into my existing API, but either my syntax is wrong or my query in postman is wrong.

Essentially, I want to be able to query on both population and country

Here's how my schema looks:

scalar JSON

schema {
   query: Query
}
....

input PercentageInput {
  gte: Int
}

input Population {
  percentage: PercentageInput
}

input Country {
  percentage: PercentageInput
}

input And {
  population: [Population]
  country: [Country]
}

input AudienceFilterInput {
  market: String
  and: [Population]
}

input TalentMetadataFilterInput {
  citizen_of: ListFilterInput
  gender: [String]
  original_country: [String]
  audience: AudienceFilterInput
}

I would ideally want to query with both population and country with percentage greater than some value.

Whenever I query in Postman using this:

query MyQuery {
    talentMetadata(
    filter: { audience: { and: [ population {male_percentage : { gte: 80 }}, country { us_percentage : { gte: 30 }}]} },,
    size: 100)..
}

I get the following error:

"message": "Field \"male_percentage\" is not defined by type \"Population\". Did you mean \"percentage\"?",

Also, if you share the postman query along with the schema, would be awesome.

Pavanraotk
  • 1,097
  • 4
  • 15
  • 33

1 Answers1

0

I got the solution working.

Here's how my schema looks:

scalar JSON

schema {
   query: Query
}
....

input PercentageInput {
  gte: Int
}

input Population {
  genx_percentage: PercentageInput
  geny_percentage: PercentageInput
}

input Country {
  male_percentage: PercentageInput
  female_percentage: PercentageInput
}

input AudienceFilterInput {
  country: Country
  population: Population
}

input TalentMetadataFilterInput {
  citizen_of: ListFilterInput
  gender: [String]
  original_country: [String]
  audience: AudienceFilterInput
}

This with the below query:

query MyQuery {
    
  talentMetadata(
    filter: {
      audience: {
        country: { female_percentage: { gte: 80 } }
        population: { genx_plus_percentage: { gte: 30 } }
      }
    }
    size: 100
  ) {
    items {
      states
      drinks
      ...
    }
  }
}

Pavanraotk
  • 1,097
  • 4
  • 15
  • 33