How to filter for a Craft CMS site in a GraphQL Query

A step by step guide on filtering a GraphQL query for a specific Craft CMS site.

Oscar de la Hera Gomez
Written by Oscar de la Hera Gomez
First published on 02/14/2023 at 12:52
Last Updated on 02/14/2023 at 13:34
Two flowers that represents Craft CMS and GraphQL side by side with the text "GraphQL Site Filter" beneath it.

A step by step guide on filtering a GraphQL query for a specific Craft CMS site.

SubscribeDownload Open Source Craft CMS project

The following tutorial walks you through how to filter a GraphQL query for a specific site in a multisite Craft CMS. It assumes that you have setup Craft CMS to work with the GraphQL, and have multiple sites setup.

If you wish to learn how to do the above, please consult the tutorials below.

How to setup Craft CMS to work with the GraphQLHow to create a GraphQL schema in Craft CMSHow to split Craft CMS into multiple websites

Step One: Access the GraphiQL

A screenshot of the Craft CMS GraphiQL.

On your browser, access the Craft CMS GraphiQL by replacing YOUR_CRAFT_URL with the URL of your Craft CMS in the url below.

YOUR_CRAFT_URL/admin/graphiql

Step Two: Write the Query

A Craft CMS GraphQL Query including the "site" parameter along with a "*" that filters for all sites.

Please note that we used * in the screenshot above, which filters for all websites.

In the GraphiQL, write the query and add site parameter with the handle of the website that you wish to filter for in that query. For example if your site handle is sample as is in our tutorial on splitting your Craft CMS, then the parameter would be site: ["sample"].

How to split Craft CMS into multiple websites

If you press play, you will see that the GraphQL query will be filtered for that site.

Any Questions?

We are actively looking for feedback on how to improve this resource. Please send us a note to inquiries@delasign.com with any thoughts or feedback you may have.
SubscribeContact UsVisit our BlogView our ServicesView our Work

Partner with us

We would love to get to know you and see how we can help your organization with its goals and needs.
Let's Talk

Stay Informed

Get occasional updates about our company, research, and product launches.
Subscribe