Filters

The customizable nature of GraphQL makes it possible to fetch vast amounts of data in a single query. It also allows for filtering down the data you want to fetch with your query. Many of our queries have an optional filter query parameter that allows you to determine what data you would like to see based on fields allowed in that filter.

If a query has a filter available, you will find a filter object in the documentation for that query. That filter object will guide you in knowing what fields can be used to filter the records and what values can be passed into the filter parameters to retrieve the desired records.

The following examples walks you through the use of filters using two of our queries that allow filtering.

The first example uses the courseCatalog query which allows you to filter data based on fields such as title, description, or status. For reference, the courseCatalog filter can be viewed here.

In this example the searchTerm parameter returns any records where the specified searchTerm coud be found in the title and/or description fields Let's say you want to retrieve all free, published courses having to do with JavaScript. You could accomplish that with the following query:

Copy
query {
	courseCatalog(filter: {
	  searchTerm: "javascript",
	  free: true,
	  status: "published"
	}) {
	  nodes {
	    title
	    status
	    description
	  }
	}
}
	      

This next example uses the skillAssessmentResults query which allows you to select records based on the completedOn date field using the startDate and endDate filters. For reference, the skillAssessmentResults filter can be viewed here.

Let's say you want to retrieve all skillIq assessment results for your plan completed during May of 2021. You could accomplish that with the following query:

Copy
query {
	skillAssessmentResults(filter:{
		  startDate: "2021-05-01"
		  endDate: "2021-05-31"
	}) {
	  nodes{
		  skillName 
		  quintileLevel
		  completedOn
	  }
	}
}

Additional Resources

Free Pluralsight's Guide to GraphQL