TITLE: Fetch Spore data using a GraphQL client DESCRIPTION: Demonstrates how to use `graphql-request` to fetch the first 10 spores and their cluster names from the Spore GraphQL API. SOURCE: https://github.com/sporeprotocol/spore-graphql/blob/master/README.md#_snippet_2 LANGUAGE: typescript CODE: ``` import { request, gql } from 'graphql-request' // Get the first 10 spores and their cluster names const document = gql` { spores { id contentType cluster { name } } } ` await request('/api/graphql/', document) ``` ---------------------------------------- TITLE: Integrate Spore GraphQL server into Next.js API route DESCRIPTION: Example of setting up the Spore GraphQL server handler in a Next.js API route, using `startSporeServerNextHandler` and `predefinedSporeConfigs`. SOURCE: https://github.com/sporeprotocol/spore-graphql/blob/master/README.md#_snippet_1 LANGUAGE: typescript CODE: ``` // app/api/graphql/route.js import { startSporeServerNextHandler } from 'spore-graphql/next'; import { predefinedSporeConfigs } from '@spore-sdk/core'; const handler = startSporeServerNextHandler(predefinedSporeConfigs.Aggron4); export { handler as GET, handler as POST }; ``` ---------------------------------------- TITLE: Install spore-graphql dependency DESCRIPTION: Instructions to install `spore-graphql` and `@spore-sdk/core` using npm as a package manager. SOURCE: https://github.com/sporeprotocol/spore-graphql/blob/master/README.md#_snippet_0 LANGUAGE: shell CODE: ``` npm install spore-graphql @spore-sdk/core --save ``` ---------------------------------------- TITLE: Configure Spore GraphQL with Redis Cache Backend DESCRIPTION: This TypeScript example demonstrates how to set up a cache backend for a spore-graphql server using `KeyvAdapter` with a Redis instance. It includes `ApolloServerPluginCacheControl` for default max age and `responseCachePlugin` for response caching, ensuring efficient handling of GraphQL queries. SOURCE: https://github.com/sporeprotocol/spore-graphql/blob/master/README.md#_snippet_7 LANGUAGE: typescript CODE: ``` import { startSporeServerNextHandler } from 'spore-graphql/next'; import responseCachePlugin from '@apollo/server-plugin-response-cache'; import { ApolloServerPluginCacheControl } from '@apollo/server/plugin/cacheControl'; import { KeyvAdapter } from '@apollo/utils.keyvadapter'; import Keyv from 'keyv'; import { predefinedSporeConfigs } from '@spore-sdk/core'; export const fetchCache = 'force-no-store'; export const maxDuration = 300; const cache = new KeyvAdapter(new Keyv("redis://...")); const handler = startSporeServerNextHandler(predefinedSporeConfigs.Aggron4, { cache, plugins: [ ApolloServerPluginCacheControl({ defaultMaxAge: 60 * 60 * 24, }), responseCachePlugin(), ], }, }); export { handler as GET, handler as POST }; ``` ---------------------------------------- TITLE: Get Spore by ID with cluster details (GraphQL) DESCRIPTION: GraphQL query to fetch a specific Spore by its ID, including its content type, content, and associated cluster's details. SOURCE: https://github.com/sporeprotocol/spore-graphql/blob/master/README.md#_snippet_4 LANGUAGE: graphql CODE: ``` query GetSporeById { spore(id: "0x95e5d57b6a9b2b35f26a8ade93e48ed736283ca2ca860654b809f8a1b9b8c8eb") { id contentType content cluster { id name description } } } ``` ---------------------------------------- TITLE: Get mintable clusters by CKB address (GraphQL) DESCRIPTION: GraphQL query to find clusters that are mintable by a specific CKB address, returning their ID, name, and description. SOURCE: https://github.com/sporeprotocol/spore-graphql/blob/master/README.md#_snippet_6 LANGUAGE: graphql CODE: ``` query GetMintableClusters { clusters( filter: { mintableBy: "ckt1qrejnmlar3r452tcg57gvq8patctcgy8acync0hxfnyka35ywafvkqgpwrcql790ua7gr9kam255sq3ussa09wtgqqjwqus2" } ) { id name description } } ``` ---------------------------------------- TITLE: Get top clusters by spore count (GraphQL) DESCRIPTION: GraphQL query to retrieve top clusters, sorted by the number of associated spores, including their name, ID, and description. SOURCE: https://github.com/sporeprotocol/spore-graphql/blob/master/README.md#_snippet_3 LANGUAGE: graphql CODE: ``` query GetTopClustersQuery { topClusters { name id description } } ``` ---------------------------------------- TITLE: Get Spores by content type (GraphQL) DESCRIPTION: GraphQL query to filter and retrieve Spores based on their content type, specifically 'text/markdown'. SOURCE: https://github.com/sporeprotocol/spore-graphql/blob/master/README.md#_snippet_5 LANGUAGE: graphql CODE: ``` query GetMarkdownContentTypeSpores { spores(filter: { contentTypes: ["text/markdown"] }) { id contentType } } ``` ---------------------------------------- TITLE: Start Next.js Development Server DESCRIPTION: Commands to initiate the local development server for a Next.js application, supporting npm, yarn, pnpm, and bun package managers. The server will typically run on `http://localhost:3000`. SOURCE: https://github.com/sporeprotocol/spore-graphql/blob/master/example/README.md#_snippet_0 LANGUAGE: bash CODE: ``` npm run dev ``` LANGUAGE: bash CODE: ``` yarn dev ``` LANGUAGE: bash CODE: ``` pnpm dev ``` LANGUAGE: bash CODE: ``` bun dev ```