{"name":"@graphiql/plugin-collections","version":"0.0.0","_id":"@graphiql/plugin-collections@0.0.0","maintainers":[{"name":"benjie","email":"npm@benjiegillam.com"},{"name":"mjmahone","email":"mahoney.mattj@gmail.com"},{"name":"leebyron","email":"lee@leebyron.com"},{"name":"i1g","email":"ivan.goncharov.ua@gmail.com"}],"dist":{"shasum":"1683e66f92b468ff6f24ade463952ac95c1fc4f3","tarball":"http://registry-npm.ywwl.com/@graphiql/plugin-collections/download/@graphiql/plugin-collections-0.0.0.tgz","fileCount":1,"integrity":"sha512-og6zyhlR7eE1jzHPCFtcw1JPoeB8DwcK/cAkQ1oEvewXcqA2aWnBKJUxl777c3UCoX9Swk5iEqeDQv/AQTYXpA==","signatures":[{"sig":"MEQCIEGI9+73UOyzMjiFGFxLYRw4q6I8RQj5j+ZuIDAn1FkGAiAxRpUZrO4KtKfJOcIw/06g/eYg+mWorslCrvSlZaOO5w==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":67,"size":160,"noattachment":false,"key":"/@graphiql/plugin-collections/-/@graphiql/plugin-collections-0.0.0.tgz"},"_npmUser":{"name":"benjie","email":"npm@benjiegillam.com"},"_npmVersion":"12.0.2","directories":{},"_nodeVersion":"24.18.0","_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/plugin-collections_0.0.0_1788019536576_0.2576557861307416","host":"s3://npm-registry-packages-npm-production"},"readme":"# @graphiql/plugin-collections\n\nA first-party operation collections plugin for GraphiQL. Save named GraphQL operations into collections and reuse them later, with drag-and-drop reordering, clipboard sharing, and JSON import/export that merges by id instead of duplicating.\n\n## Installation\n\n```sh\nnpm install @graphiql/plugin-collections\n```\n\nMake sure the peer dependencies are installed too:\n\n```sh\nnpm install react react-dom graphql @graphiql/react\n```\n\n## Usage\n\nThe collections plugin is installed by default in GraphiQL, so an unmodified `<GraphiQL>` already shows a Collections rail icon. Use `COLLECTIONS_PLUGIN` when you pass a custom `plugins` array and want to keep the default collections configuration. Use `collectionsPlugin(options)` to supply a custom storage backend or restrict what users can do.\n\n> **Note:** passing the `plugins` prop replaces the default plugin set, so include the others you want alongside it.\n\n```jsx\nimport { GraphiQL } from 'graphiql';\nimport { createTransport } from '@graphiql/toolkit';\nimport { COLLECTIONS_PLUGIN } from '@graphiql/plugin-collections';\nimport 'graphiql/style.css';\nimport '@graphiql/plugin-collections/style.css';\n\nconst transport = createTransport({\n  url: 'https://swapi-graphql.netlify.app/.netlify/functions/index',\n});\n\nfunction GraphiQLWithCollections() {\n  return <GraphiQL transport={transport} plugins={[COLLECTIONS_PLUGIN]} />;\n}\n```\n\n## Options\n\n```ts\ncollectionsPlugin({\n  storage, // custom persistence backend; see below\n  readOnly, // default false\n  allowImportExport, // default true\n  allowReplace, // default true\n});\n```\n\n| Option              | Default              | Effect                                                                                                                                 |\n| ------------------- | -------------------- | -------------------------------------------------------------------------------------------------------------------------------------- |\n| `storage`           | localStorage adapter | A custom `CollectionsStorage` (see [Custom storage](#custom-storage)).                                                                 |\n| `readOnly`          | `false`              | Hides every write affordance (create, rename, delete, reorder, save, import). Export and copy stay available so users can still share. |\n| `allowImportExport` | `true`               | When `false`, hides the import/export dialog button and turns off paste/drop import.                                                   |\n| `allowReplace`      | `true`               | When `false`, hides the destructive \"replace everything\" import mode and leaves only merge.                                            |\n\n## Import and merge behavior\n\nCollections and the operations inside them carry stable UUIDs that survive export and import. On import, the plugin reconciles by id instead of duplicating:\n\n- A new operation is added. An operation you already have is updated in place wherever you keep it, even if you've moved it to a different collection. A missing parent collection is recreated.\n- Re-importing an unchanged export does nothing, so you never get duplicates.\n- When an incoming operation differs from your local copy, a dialog lets you apply the changes, keep your versions, or review each operation one at a time. Merge never deletes.\n\nAn operation can also be shared on its own with \"Copy operation\". It travels as a one-item collection envelope stamped with its parent collection, so the recipient can re-home it on import.\n\n## Custom storage\n\nPersistence is pluggable through the `CollectionsStorage` interface:\n\n```ts\ntype CollectionsStorage = {\n  storageKey?: string;\n  load(): Promise<Collection[]>;\n  save(collections: Collection[]): Promise<void>;\n};\n```\n\nThe default writes to `localStorage` under the key `graphiql:collections`. To use a different key, pass an adapter from the exported `createLocalStorageAdapter` factory:\n\n```ts\nimport {\n  collectionsPlugin,\n  createLocalStorageAdapter,\n} from '@graphiql/plugin-collections';\n\nconst collections = collectionsPlugin({\n  storage: createLocalStorageAdapter('my-key'),\n});\n```\n\nTo back collections with your own service (REST, a database, a team-shared store), implement the interface and pass it as `storage`:\n\n```ts\nimport { collectionsPlugin } from '@graphiql/plugin-collections';\nimport type {\n  Collection,\n  CollectionsStorage,\n} from '@graphiql/plugin-collections';\n\nconst apiStorage: CollectionsStorage = {\n  async load() {\n    const res = await fetch('/api/collections');\n    return (await res.json()) as Collection[];\n  },\n  async save(collections) {\n    const response = await fetch('/api/collections', {\n      method: 'PUT',\n      headers: { 'content-type': 'application/json' },\n      body: JSON.stringify(collections),\n    });\n    if (!response.ok) {\n      throw new Error(`Saving collections failed (${response.status})`);\n    }\n  },\n};\n\nconst collections = collectionsPlugin({ storage: apiStorage });\n```\n\n`load()` runs once when the panel first mounts. `save()` receives the full collection list after mutations. For toolbar or keyboard saves, its promise must resolve only after the write commits. A rejection keeps the operation dirty and shows an error in GraphiQL. Other collection editing actions still update the UI immediately.\n\n### Team-shared backends and sync\n\nThe plugin has no opinion about conflict resolution or synchronization; that lives in your storage adapter. Because every operation and collection has a stable id, your adapter can diff successive `save()` snapshots and reconcile them however it needs to, whether that is a plain backend write, a last-write-wins policy, or a CRDT such as Yjs or Automerge. The plugin itself stays a CRUD UI over a serializable model.\n\nThe plugin does not react to remote changes on its own. When your backend reports an external change, call `reload()` to re-read storage and refresh the UI:\n\n```ts\nimport { collectionsStore } from '@graphiql/plugin-collections';\n\nawait collectionsStore.getState().actions.reload();\n```\n\n## Programmatic access\n\nThe store and its React hook are exported for programmatic access:\n\n```ts\nimport {\n  collectionsStore, // the vanilla zustand store\n  useCollectionsStore, // React hook: useCollectionsStore(selector)\n} from '@graphiql/plugin-collections';\n\nconst { actions } = collectionsStore.getState();\n\n// Replace the in-memory collections (e.g. after merging remote state).\n// Does NOT write back to storage.\nactions.setCollections(nextCollections);\n\n// Re-read from the configured storage and refresh the UI.\nawait actions.reload();\n```\n\n`actions` also exposes the full CRUD surface (`createCollection`, `addItem`, `updateItem`, `deleteItem`, `moveItem`, `renameCollection`, and so on) plus `exportCollections` / `exportCollection` / `exportItem` and the two-phase `analyzeImport` / `applyImport`.\n\n## Exports\n\n- `COLLECTIONS_PLUGIN` — the default plugin configuration\n- `collectionsPlugin(options?)` — the plugin factory for custom configuration\n- `collectionsStore`, `useCollectionsStore` — the store and its React hook\n- `createLocalStorageAdapter(key)`, `localStorageAdapter` — built-in storage\n- `CollectionsSaveDialog` — the save dialog component\n- Types: `Collection`, `CollectionItem`, `CollectionsStorage`, `CollectionsConfig`, `ActiveOperation`\n","publish_time":1788019536703,"_cnpm_publish_time":1788019536703,"dist-tags":{"beta":"1.0.0-beta.4","latest":"1.0.1","rc":"1.0.0-rc.1"}}