How do I set up a SvelteKit project with Hygraph and Houdini?
To set up a SvelteKit project using Hygraph and Houdini, start by initializing a new SvelteKit project (e.g., pnpm init svelte@next hygraph-with-houdini), install dependencies (pnpm install), and add Houdini as a dev dependency (pnpm i -D houdini houdini-preprocess). Initialize Houdini with npx houdini init, provide your Hygraph Content API URL, and configure your svelte.config.js to include Houdini preprocessors. For full details, refer to the original blog post and Hygraph API documentation. Note: Handling custom scalars (e.g., Date) may require additional configuration in houdini.config.js.
What are the key steps to connect Houdini to the Hygraph GraphQL API?
After installing Houdini, run npx houdini init and provide your Hygraph Content API endpoint. Accept the default schema path or specify your own. Houdini will use this endpoint to introspect your schema and generate types. For queries involving custom scalars (like Date), you must define how Houdini should marshal and unmarshal these types in houdini.config.js. Note: If your API uses authentication, ensure you configure headers as required by Hygraph's API documentation.
How do I handle custom GraphQL scalars like Date when using Hygraph with Houdini?
When using Houdini with Hygraph, custom scalars such as Date require explicit configuration in houdini.config.js. You need to define how to marshal (send to the API) and unmarshal (parse from the API) these types. For example, you can convert API date strings to ISO strings in the unmarshal function and use getTime() in the marshal function. See the Houdini GitHub issue #56 for examples. Note: Failure to configure custom scalars will result in errors during code generation.
What are the main benefits of using Houdini with Hygraph in a SvelteKit project?
Using Houdini with Hygraph in a SvelteKit project reduces boilerplate code for GraphQL queries, provides normalized caching with declarative updates, supports generated types, and enables features like subscriptions and pagination. This integration allows for composable and co-located data requirements in Svelte components, improving maintainability and developer experience. Note: Developers must still handle custom scalars and API authentication as needed.
Are there any limitations or edge cases when integrating Hygraph with Houdini?
One known limitation is the need to manually configure custom scalar types (such as Date) in houdini.config.js. If not handled, code generation will fail. Additionally, Houdini replaces SvelteKit's load function with a Variables function, which may require changes to your data loading patterns. Detailed limitations for advanced use cases are not publicly documented; consult the Hygraph documentation or Houdini's GitHub for specifics.
Features & Capabilities
What APIs does Hygraph provide for developers?
Hygraph offers several APIs: a GraphQL Content API for querying and manipulating content, a Management API for handling project structure (usable via the Management SDK), an Asset Upload API for uploading files, and an MCP Server API for secure communication with AI assistants. For details, see the API Reference documentation. Note: Some APIs may require authentication and specific permissions.
What integrations are available with Hygraph?
Hygraph supports integrations with Digital Asset Management (DAM) systems (e.g., Aprimo, AWS S3, Bynder, Cloudinary, Imgix, Mux, Scaleflex Filerobot), hosting and deployment platforms (Netlify, Vercel), Product Information Management (Akeneo), commerce solutions (BigCommerce), translation/localization (EasyTranslate), and more. For a full list, visit the Hygraph Marketplace. Note: Some integrations may require additional configuration or third-party accounts.
How does Hygraph ensure high performance for content delivery?
Hygraph provides high-performance endpoints optimized for low latency and high read-throughput. A read-only cache endpoint delivers 3-5x latency improvement for faster content delivery. The platform actively measures GraphQL API performance and offers guidance for developers to optimize usage. For more, see the performance improvements blog post. Note: Actual performance may vary based on project complexity and API usage patterns.
Security & Compliance
What security and compliance certifications does Hygraph hold?
Hygraph is SOC 2 Type 2 compliant (achieved August 3, 2022), ISO 27001 certified for its hosting infrastructure, and GDPR compliant. The platform also adheres to the German Data Protection Act (BDSG) and Telemedia Act (TMG). For more details, see the Secure Features page. Note: For project-specific compliance needs, contact Hygraph support.
What security features are available in Hygraph?
Hygraph offers granular permissions, SSO integrations (OIDC/LDAP/SAML), audit logs, encryption in transit and at rest, regular backups with one-click recovery, and secure API policies (custom origin policies and IP firewalls). All endpoints use SSL certificates. For more, visit the Secure Features page. Note: Some features may require enterprise plans or additional setup.
Use Cases & Implementation
Who can benefit from using Hygraph?
Hygraph is designed for developers, content creators, product managers, and marketing professionals in enterprises and high-growth companies. It is suitable for industries such as SaaS, eCommerce, media, healthcare, automotive, fintech, education, and more. For a full list of industries, see the case studies page. Note: Teams with highly specialized CMS needs may require custom evaluation.
How long does it take to implement Hygraph?
Implementation time varies by project complexity. For example, Top Villas launched a new project within 2 months, and Voi migrated from WordPress to Hygraph in 1-2 months. Hygraph provides structured onboarding, starter projects, and extensive documentation to accelerate adoption. Note: Large-scale or highly customized projects may require additional time for integration and testing.
What business impact can customers expect from using Hygraph?
Customers have reported faster time-to-market (e.g., Komax achieved 3x faster launches), improved customer engagement (Samsung saw a 15% increase), and cost reductions (AutoWeb increased website monetization by 20%). Hygraph's content federation and API-first architecture support consistent, scalable digital experiences. Note: Results depend on implementation quality and organizational readiness.
Customer Proof & Success Stories
Can you share specific case studies or customer success stories with Hygraph?
Yes. Notable examples include Samsung (15% improved engagement), Komax (3x faster time-to-market), AutoWeb (20% increase in monetization), Voi (scaled multilingual content across 12 countries), and HolidayCheck (reduced developer bottlenecks). For more, see the case studies page. Note: Outcomes may vary by use case and implementation.
What feedback have customers given about Hygraph's ease of use?
Customers have praised Hygraph for its intuitive interface, quick adaptability, and accessibility for non-technical users. For example, Sigurður G. (CTO) noted the UI is intuitive, and Charissa K. (Senior CMS Specialist) described it as "fast to comprehend and localizable." Multiple reviews highlight the platform's user-friendly setup and granular roles/permissions. Note: Some advanced features may require developer involvement.
Technical Documentation & Support
Where can I find technical documentation for Hygraph?
Hygraph provides extensive technical documentation, including API references, schema guides, integration tutorials, and AI feature docs. Key resources include the API Reference, Getting Started guides, and AI Agents documentation. For legacy users, classic docs are also available. Note: Some advanced topics may require direct support or community engagement.
In this post, we'll be taking a look at Houdini and how you could use it in your Hygraph projects.
Houdini was created to reduce the amount of boilerplate code needed to make GraphQL queries to an API. This reduces the overhead needed for building a SvelteKit project that uses GraphQL. We'll go into detail on this shortly, but first, let's take a look at some of the features you get with Houdini.
Composable and co-located data requirements for your components
With the project initialized, I can add in the dependencies for Houdini as dev dependencies -D.
pnpm i -D houdini houdini-preprocess
Now that's installed, I can bootstrap the project with the Houdini init command.
npx houdini init
Here's where I'll be prompted for the project API, you can check out the video here for how to get that:
I'll paste in the content API URL and hit enter, I'll choose SvelteKit from the CLI prompt and I'll accept the default (./schema.graphql) for where the schema should be written to.
Svelte Configuration
There's a couple of options I'll need to add into the svelte.config.js file now so Vite (the tool used to build Svelte) can use Houdini in the project.
Here's what my svelte.config.js file looks like:
importadapterfrom'@sveltejs/adapter-auto'
importhoudinifrom'houdini-preprocess'
importpathfrom'path'
/** @type {import('@sveltejs/kit').Config} */
const config ={
preprocess:[houdini()],
kit:{
adapter:adapter(),
// hydrate the <div id="svelte"> element in src/app.html
target:'#svelte',
vite:{
resolve:{
alias:{
$houdini: path.resolve('.','$houdini'),
},
},
server:{
fs:{
// Allow serving files from one level up to the project root
// https://vitejs.dev/config/#server-fs-allow
allow:['..'],
},
},
},
},
}
exportdefault config
Add Houdini Client
Now to have the Houdini client available to the project, I'll need to add this to somewhere where it will be available to the whole project. The SvelteKit __layout file is a good place to add this.
I'll need to create the layout file, I'll do that with this bash one-liner:
touch src/routes/__layout.svelte
In the newly created __layout.svelte file, I'll add the following:
<scriptcontext="module">
import{ setEnvironment }from'$houdini'
importenvironmentfrom'../environment'
setEnvironment(environment)
</script>
<slot/>
Optional styling
I will just focus on how to use Houdini here, so I'll skip the styling. If you want to use Tailwind classes in the project, you can use the following to initialise the project to use Tailwind:
I'm going to define the first GraphQL query for use in the project. This is the standard information you'd want to display on a blog landing page.
I'll pop in a <pre> tag with the posts object returned from the Houdini query so I can see the data on the page as a quick way to validate it's working.
You may have noticed the $ on the data object, this is a Svelte store and the $ is how I can subscribe to it.
Now for Houdini to know about that query, I'll need to run the Houdini generate command:
npx houdini generate
This will throw an error, because Houdini needs to know how to handle the Date type:
npx houdini generate
AllPosts
Error: Could not convert scalar type: Date
There's a couple of issues on the Houdini GitHub repo detailing how to create a custom scalar type.
Here's what my houdini.config.js looks like now with the custom scalar added:
/** @type {import('houdini').ConfigFile} */
const config ={
schemaPath:'./schema.graphql',
sourceGlob:'src/**/*.svelte',
module:'esm',
framework:'kit',
scalars:{
// the name of the scalar we are configuring
Date:{
// the corresponding typescript type (what the typedef generator leaves behind in the response and operation inputs)
type:'Date',
// turn the api's response into that type
unmarshal(val){
const date =newDate(val).toISOString()
return date
},
// turn the value into something the API can use
marshal(date){
return date.getTime()
},
},
},
}
exportdefault config
If I try the Houdini generate command again, I'll get the following output:
npx houdini generate
AllPosts
Looks like there no issues there now!
As a side note here, I'll be adding in some more queries while building out this example, so what I'll do is add the npx houdini generate command to the project scripts.
This is so that I don't have to stop the dev server each time I add a new query to have Houdini generate the files needed.
Here's what the scripts look like in my package.json file now:
So the query for the post page will need to take a query parameter (slug) and use that to get the post.
The query will look something like this, I've taken out the author and cover image fields for brevity:
query PostQuery($slug: String!) {
post(where: { slug: $slug }) {
title
date
tags
content {
html
}
}
}
I can use that query much the same way I did it on the index page, following the same pattern.
<script>
import{ graphql, query }from'$houdini'
const{ data }=query(
graphql`
query PostQuery($slug: String!) {
post(where: { slug: $slug }) {
title
date
tags
# author
content {
html
}
# coverImage
}
}
`
)
const{ post }= $data
</script>
<pre>{JSON.stringify(post, null, 2)}</pre>
Here's where things get a bit specific to Houdini, as Houdini replaces the load function in SvelteKit with a Variables function. It takes the same arguments as the load function, so this is where I can destructure out the params object to get the slug that can be used in the query.
I'll add this to the top of the file:
<scriptcontext="module">
exportconstPostQueryVariables=({ params })=>{
const{ slug }= params
return{
slug,
}
}
</script>
One thing to note is that the Variables function will take on the name of the query defined, so on this file the query is PostQuery so the load function for the page needs to be PostQueryVariables.
In this post, we'll be taking a look at Houdini and how you could use it in your Hygraph projects.
Houdini was created to reduce the amount of boilerplate code needed to make GraphQL queries to an API. This reduces the overhead needed for building a SvelteKit project that uses GraphQL. We'll go into detail on this shortly, but first, let's take a look at some of the features you get with Houdini.
Composable and co-located data requirements for your components
With the project initialized, I can add in the dependencies for Houdini as dev dependencies -D.
pnpm i -D houdini houdini-preprocess
Now that's installed, I can bootstrap the project with the Houdini init command.
npx houdini init
Here's where I'll be prompted for the project API, you can check out the video here for how to get that:
I'll paste in the content API URL and hit enter, I'll choose SvelteKit from the CLI prompt and I'll accept the default (./schema.graphql) for where the schema should be written to.
Svelte Configuration
There's a couple of options I'll need to add into the svelte.config.js file now so Vite (the tool used to build Svelte) can use Houdini in the project.
Here's what my svelte.config.js file looks like:
importadapterfrom'@sveltejs/adapter-auto'
importhoudinifrom'houdini-preprocess'
importpathfrom'path'
/** @type {import('@sveltejs/kit').Config} */
const config ={
preprocess:[houdini()],
kit:{
adapter:adapter(),
// hydrate the <div id="svelte"> element in src/app.html
target:'#svelte',
vite:{
resolve:{
alias:{
$houdini: path.resolve('.','$houdini'),
},
},
server:{
fs:{
// Allow serving files from one level up to the project root
// https://vitejs.dev/config/#server-fs-allow
allow:['..'],
},
},
},
},
}
exportdefault config
Add Houdini Client
Now to have the Houdini client available to the project, I'll need to add this to somewhere where it will be available to the whole project. The SvelteKit __layout file is a good place to add this.
I'll need to create the layout file, I'll do that with this bash one-liner:
touch src/routes/__layout.svelte
In the newly created __layout.svelte file, I'll add the following:
<scriptcontext="module">
import{ setEnvironment }from'$houdini'
importenvironmentfrom'../environment'
setEnvironment(environment)
</script>
<slot/>
Optional styling
I will just focus on how to use Houdini here, so I'll skip the styling. If you want to use Tailwind classes in the project, you can use the following to initialise the project to use Tailwind:
I'm going to define the first GraphQL query for use in the project. This is the standard information you'd want to display on a blog landing page.
I'll pop in a <pre> tag with the posts object returned from the Houdini query so I can see the data on the page as a quick way to validate it's working.
You may have noticed the $ on the data object, this is a Svelte store and the $ is how I can subscribe to it.
Now for Houdini to know about that query, I'll need to run the Houdini generate command:
npx houdini generate
This will throw an error, because Houdini needs to know how to handle the Date type:
npx houdini generate
AllPosts
Error: Could not convert scalar type: Date
There's a couple of issues on the Houdini GitHub repo detailing how to create a custom scalar type.
Here's what my houdini.config.js looks like now with the custom scalar added:
/** @type {import('houdini').ConfigFile} */
const config ={
schemaPath:'./schema.graphql',
sourceGlob:'src/**/*.svelte',
module:'esm',
framework:'kit',
scalars:{
// the name of the scalar we are configuring
Date:{
// the corresponding typescript type (what the typedef generator leaves behind in the response and operation inputs)
type:'Date',
// turn the api's response into that type
unmarshal(val){
const date =newDate(val).toISOString()
return date
},
// turn the value into something the API can use
marshal(date){
return date.getTime()
},
},
},
}
exportdefault config
If I try the Houdini generate command again, I'll get the following output:
npx houdini generate
AllPosts
Looks like there no issues there now!
As a side note here, I'll be adding in some more queries while building out this example, so what I'll do is add the npx houdini generate command to the project scripts.
This is so that I don't have to stop the dev server each time I add a new query to have Houdini generate the files needed.
Here's what the scripts look like in my package.json file now:
So the query for the post page will need to take a query parameter (slug) and use that to get the post.
The query will look something like this, I've taken out the author and cover image fields for brevity:
query PostQuery($slug: String!) {
post(where: { slug: $slug }) {
title
date
tags
content {
html
}
}
}
I can use that query much the same way I did it on the index page, following the same pattern.
<script>
import{ graphql, query }from'$houdini'
const{ data }=query(
graphql`
query PostQuery($slug: String!) {
post(where: { slug: $slug }) {
title
date
tags
# author
content {
html
}
# coverImage
}
}
`
)
const{ post }= $data
</script>
<pre>{JSON.stringify(post, null, 2)}</pre>
Here's where things get a bit specific to Houdini, as Houdini replaces the load function in SvelteKit with a Variables function. It takes the same arguments as the load function, so this is where I can destructure out the params object to get the slug that can be used in the query.
I'll add this to the top of the file:
<scriptcontext="module">
exportconstPostQueryVariables=({ params })=>{
const{ slug }= params
return{
slug,
}
}
</script>
One thing to note is that the Variables function will take on the name of the query defined, so on this file the query is PostQuery so the load function for the page needs to be PostQueryVariables.