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

itch-graphql

v1.0.2

Published

GraphQL server/types and resolvers for the itch.io API

Downloads

2

Readme

Logo of the project

itch-graphql

buddy pipeline Maintainability npm PRs Welcome GitHub license

Unofficial GraphQL server and typedefs/resolvers for the itch.io API.

If you've ever wanted a GraphQL wrapper around the itch.io REST API, you've come to the right place. I know this is pretty niche, but at least you have the option now.

  • [x] Export a built-in server
  • [x] Export typedefs and resolvers
  • [x] API key support
  • [ ] JWT support
  • [ ] NPM command
  • [ ] Socially acceptable tests

Installing / Getting started

First, you have to install it to the project:

# with NPM
npm install itch-graphql

# with yarn
yarn add itch-graphql

From here, there are (currently) two ways that you can use this package: Either as a standalone server, or by importing the types/resolvers and integrating them with your own server.

We'll assume you're using an ESM-supported environment for the purposes of this README, but if you're confused, just know that

import { server } from 'itch-graphql'

is the same thing as

const { server } = require('itch-graphql')

Standalone

This is pretty simple. All you need to do is import the server and call it with the port and a boolean for GraphiQL. Internally, it's using micro, apollo-server-micro, and microrouter.

For authorization, it's up to you whether to include a ItchToken: <your token here> HTTP header or to set up an ITCH_TOKEN environment variable. We recommend the latter.

import { server } from 'itch-graphql'

server(
  // Port number
  3000,
  // GraphiQL boolean, defaults to true
  false
)

Open up GraphQL Playground to http://localhost:3000/graphql or your web browser of choice to http://localhost:3000/graphiql and you're ready to play around.

Integrating with your own server

This is a little bit more in-depth, but not too terrible.

// import and alias our types and resolvers for readability
import { typeDefs as itchTypes, resolvers as itchResolvers } from 'itch-graphql'
import { makeExecutableSchema } from 'graphql-tools'
import { graphqlExpress } from 'apollo-server-express'
import express from 'express'

// Stitch together the schema of legends
const schema = makeExecutableSchema({
  typeDefs: [
    someType,
    moreType,
    ...itchTypes
  ],
  resolvers: {
    ...someResolvers,
    ...moreResolvers,
    ...itchResolvers
  }
})

// Assemble the GraphQL handler
const graphqlHandler = expressGraphql((req, res) => {
  return {
    schema,
    // Add our Itch token for authorization
    context: {
      // You can set this up however you like
      itchToken:
        process.env.ITCH_TOKEN || req.headers.ItchToken
    }
  }
})

// Start the app
const app = express()
app.get('/graphql', graphqlHandler)
app.listen(3000)

And you're golden!

Developing

Built With

Prerequisites

In order to get started developing, you're going to need a version of Node installed (preferably the latest release), and an itch.io token. You can create the token from your profile on the website.

Setting up Dev

If you're interested in contributing, it's pretty simple to get started locally:

git clone https://github.com/puregarlic/itch-graphql
cd itch-graphql/
npm install
npm run dev

And you're good to go. We recommend using GraphQL Playground to test the API, because you can pass HTTP Headers from the application. GraphiQL is only great if you're handing the token to context via an ITCH_TOKEN environment variable.

If you make any changes to the source code, the server will autoreload thanks to nodemon.

Deploying / Publishing

Publishing happens automatically via semantic-release, deployed with Buddy.

The main thing to know is that we use commitlint to enforce conventional commits. These are very important for correctly generating changelogs and creating new versions.

If you need to know more about how to write conventional commits, check out the spec, and if you need to know the different allowed types, check out this JSON file.

Tests

My current tests are absolutely horrible. If you can write better ones, or simply want to improve my existing ones, please please please make a PR.

If you want to run the tests locally, you're going to need a .env file in the project root. This needs to contain a few values:

# <REQUIRED> Itch API Token
ITCH_TOKEN=

# <REQUIRED> User ID number. You can retrieve this with the me query
USER_ID=

# You need one of these two, for the purchases and download key query:
GAME_ID=
EMAIL=

# You can add this if you really want:
DOWNLOAD_KEY=

My user account is downright lacking when it comes to test data, so if you're willing to donate an API token for the testing environment, please get in touch with me on Twitter.

Style guide

This project follows the Standard style, so if you want to install an editor linter for that, go right ahead. However, it's not really necessary -- Each time you commit, we'll lint your staged changes with the --fix flag, and then format it all with prettier-standard. As a result, you don't need to worry about styling too much, because it'll be fixed later.

Api Reference

Since this is a wrapper around the Itch server-side API, you can read the docs here.

Legal

I'm not affiliated with itch.io in any capacity, and the images used in the project logo are the property of their respective owners.