0.1.8 • Published 3 months ago

spore-graphql v0.1.8

Weekly downloads
-
License
MIT
Repository
github
Last release
3 months ago

spore-graphql

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.

Installation

Install spore-graphql as a dependency using any package manager, such as npm:

npm install spore-graphql @spore-sdk/core --save

How to use

  • 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.

Queries

We have provided some commonly used queries.

  • Get top clusters (sort by the number of spores)

    query GetTopClustersQuery {
      topClusters {
        name
        id
        description
      }
    }

    Open in GraphQL Explorer >>

  • Get spore by id, including its cluster

    query GetSporeById {
      spore(id: "0x95e5d57b6a9b2b35f26a8ade93e48ed736283ca2ca860654b809f8a1b9b8c8eb") {
        id
        contentType
        content
        cluster {
          id
          name
          description
        }
      }
    }

    Open in GraphQL Explorer >>

  • Get spores by content type (text/markdown)

    query GetMarkdownContentTypeSpores {
      spores(filter: { contentTypes: ["text/markdown"] }) {
        id
        contentType
      }
    }

    Open in GraphQL Explorer >>

  • Get mintable clusters by CKB address

    query GetMintableClusters {
      clusters(
        filter: {
          mintableBy: "ckt1qrejnmlar3r452tcg57gvq8patctcgy8acync0hxfnyka35ywafvkqgpwrcql790ua7gr9kam255sq3ussa09wtgqqjwqus2"
        }
      ) {
        id
        name
        description
      }
    }

    Open in GraphQL Explorer >>

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.

Advanced Usage

Configuring cache backends

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

Community

Chat everything about Spore here:

Contributing

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

License

MIT License

0.1.8

3 months ago

0.1.7

3 months ago

0.1.6

4 months ago

0.1.5

4 months ago

0.1.4

4 months ago

0.1.3

4 months ago

0.1.1-beta.0

5 months ago

0.1.2

5 months ago

0.1.1

5 months ago

0.1.0

6 months ago

0.1.0-beta.40

6 months ago

0.1.0-beta.32

6 months ago

0.1.0-beta.31

6 months ago

0.1.0-beta.30

6 months ago

0.1.0-beta.29

6 months ago

0.1.0-beta.28

6 months ago

0.1.0-beta.27

6 months ago

0.1.0-beta.26

6 months ago

0.1.0-beta.25

6 months ago

0.1.0-beta.24

6 months ago

0.1.0-beta.23

6 months ago

0.1.0-beta.22

6 months ago

0.1.0-beta.21

6 months ago

0.1.0-beta.20

6 months ago

0.1.0-beta.19

6 months ago

0.1.0-beta.18

6 months ago

0.1.0-beta.17

6 months ago

0.1.0-beta.16

6 months ago

0.1.0-beta.15

6 months ago

0.1.0-beta.14

6 months ago

0.1.0-beta.13

6 months ago

0.1.0-beta.12

6 months ago

0.1.0-beta.11

6 months ago

0.1.0-beta.10

6 months ago

0.1.0-beta.9

6 months ago

0.1.0-beta.8

6 months ago

0.1.0-beta.7

6 months ago

0.1.0-beta.6

6 months ago

0.1.0-beta.5

6 months ago

0.1.0-beta.4

6 months ago

0.1.0-beta.3

6 months ago

0.1.0-beta.2

6 months ago

0.1.0-beta.1

6 months ago

0.1.0-beta.0

6 months ago