

- #Graphql conditional fragment how to#
- #Graphql conditional fragment code#
- #Graphql conditional fragment series#
In this query the fields categories and title are filtered to find the book that belongs to the magical creatures category AND has Fantastic in its title. It is also possible to filter on multiple fields by separating the individual filters by a comma (which works as an AND): If you want to understand more how these filters work, looking at the corresponding tests in the codebase could be very useful. elemMatch: short for element match, this indicates that the field you are filtering will return an array of elements, on which you can apply a filter using the previous operators.lte: short for less than or equal, must be less than or equal to given value.

lt: short for less than, must be less than given value.gte: short for greater than or equal, must be greater than or equal to given value.gt: short for greater than, must be greater than given value.nin: short for not in array, must NOT be an element of the array.in: short for in array, must be an element of the array.glob: short for global, allows to use wildcard * which acts as a placeholder for any non-empty string.regex: short for regular expression, must match the given pattern.ne: short for not equal, must be different from the given data.eq: short for equal, must match the given data exactly.
#Graphql conditional fragment code#
In the code block below the list, there is an example query with a description of what the query does for each operator. This allows Gatsby to support operators like eq, ne, in, regex and querying nested fields through the _ connector. Gatsby relies on Sift to enable MongoDB-like query syntax for object filtering. You can find a good video tutorial on this in LevelUpTuts Gatsby Tutorial #9: Filters & Sorting with GraphQL. In this query, the filter argument and the ne (not equals) operator are used to show only results that have a title. In this query skip is used to omit the first 3 results. Here totalCount tells you there’s 8 results, but limit is used to show only the first three. There are several ways to reduce the number of results from a query. This section covers the different arguments you can pass in to GraphQL fields. The query will still work and the returned object will reflect the nodes structure. If you’re using Gatsby version 2.2.0 or later, you can remove edges and node from your query and replace it with nodes.

In the GraphiQL editor, try using the editor’s autocomplete ( Ctrl + Space) to get extended details from the packageJson nodes. In this query you ask for the total count of plugins in this Gatsby site, along with specific information about each one. Gatsby structures its content as collections of nodes, which are connected to each other with edges. When typing in the query editor you can use Ctrl + Space to see autocomplete options and Ctrl + Enter to run the current query. In the GraphiQL editor, try editing the query to include the description from siteMetadata. Start with the basics, pulling up the site title from your gatsby-config.js’s siteMetadata.
#Graphql conditional fragment how to#
You can also open the CodeSandbox version of the example site.įor more background information, read about why Gatsby uses GraphQL and how to use GraphiQL in any Gatsby site. You can run this example locally to experiment and poke around the innards of the site! To get to the GraphiQL editor, go to localhost:8000/_graphql (that’s three underscores). These examples will work on the real schema used on graphql-reference example.
#Graphql conditional fragment series#
