Spore Graphql is a Graphql Layer designed to simplify Spore data queries. It can be easily integrated into applications, allowing you to retrieve the desired data based on your specific needs.
Install spore-graphql
as a dependency using any package manager, such as npm
:
npm install spore-graphql @spore-sdk/core --save
-
Integrating into your application (using Next.js as an example)
// 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 };
-
Fetch data with GraphQL client
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)
You can use any GraphQL client you like to make requests, and you can debug your query on the Spore GraphQL Explorer provided by us.
We have provided some commonly used queries.
-
Get top clusters (sort by the number of spores)
query GetTopClustersQuery { topClusters { name id description } }
-
Get spore by id, including its cluster
query GetSporeById { spore(id: "0x95e5d57b6a9b2b35f26a8ade93e48ed736283ca2ca860654b809f8a1b9b8c8eb") { id contentType content cluster { id name description } } }
-
Get spores by content type (text/markdown)
query GetMarkdownContentTypeSpores { spores(filter: { contentTypes: ["text/markdown"] }) { id contentType } }
-
Get mintable clusters by CKB address
query GetMintableClusters { clusters( filter: { mintableBy: "ckt1qrejnmlar3r452tcg57gvq8patctcgy8acync0hxfnyka35ywafvkqgpwrcql790ua7gr9kam255sq3ussa09wtgqqjwqus2" } ) { id name description } }
For other queries or requirements, you can explore them in the GraphQL Explorer. If your needs are not met, feel free to create an issue or submit a pull request to collectively improve spore-graphql.
spore-graphql is based on Apollo GraphQL, which means you can refer to the documentation of Apollo GraphQL for implementation
Here is a simple code implementation:
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 };
If you are using Vercel KV as a cache backend, you can refer to the implementation of Spore Demo
Chat everything about Spore here:
- Join our discord channel: HaCKBee
- Contact via email: [email protected]
To submit pull requests, make sure:
- Please submit pull requests based on the
master
branch - Please ensure your commit styling won't conflict with the existing commits
- Please provide a clear and descriptive title and description for your pull requests
MIT License