npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

houdini-plugin-svelte-global-stores

v1.2.62

Published

The svelte global store plugin for houdini

Downloads

18,495

Readme


➕ houdini-plugin-svelte-global-stores

This package provides global stores for houdini's svelte bindings.

Setup

To use this plugin, add it to the list of plugins in houdini.config.js:

/// <references types="houdini-svelte">
/// <references types="houdini-plugin-svelte-global-stores">

/** @type {import('houdini').ConfigFile} */
const config = {

  plugins: {
    'houdini-plugin-svelte-global-stores': {
      prefix: 'GQL_',
      generate: ['mutation', 'subscription', 'fragment']
    },
    'houdini-svelte': {}
  }

};

export default config;

The following configuration options are available:

  • prefix (optional, default: GQL_): The default prefix of your global stores. This lets your editor provide autocompletion with just a few characters.
  • generate (optional, default: ['mutation', 'subscription', 'fragment']). Note that by default, 'Query' is omitted on purpose. You can also pass "all" to generate all stores.

Usage

This plugin allows you to import a globally accesible store for your external documents. It's important to be careful when using global stores on the server since it can result in data leaking across requests.

# src/lib/queries/MyAwesomeQuery.gql

query MyAwesomeQuery {
	viewer {
		isAwesome
	}
}
// src/routes/myRoute/+page.js
import { GQL_MyAwesomeQuery } from '$houdini'

Note the prefix GQL_ is to enable easy autocompletion in your editor - give it a try!

Generating Loads For Stores

You can now tell the houdini plugin to generate loads for your stores. To do this, you need to export a houdini_load variable from your +page.js/ts file:

// src/routes/myProfile/+page.ts

import { GQL_MyQuery, GQL_Query1, GQL_Query2 } from '$houdini'

export const houdini_load = GQL_MyQuery
// or
export const houdini_load = [GQL_Query1, GQL_Query2]

Fragments example

Fragments stores can be created from your external documents by using the .get method on the global store in $houdini:

<script>
	import { GQL_UserAvatar } from '$houdini'

	// the reference will get passed as a prop
	export let user

	// load the the required UserAvatar for this component
	$: data = GQL_UserAvatar.get(user)
</script>

<img src={$data.profilePicture} />

Endpoints

Using a query store inside of an endpoint looks very similar to the load function: just pass the event you are handed in your route function:

import { GQL_MyQuery } from '$houdini'

export async function get(event) {
	const { data } = await GQL_MyQuery.fetch({ event })

	return {
		body: {
			data
		}
	}
}

HoudiniGraphQL.com 🚀