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

replit-graphql-api

v1.0.5

Published

A module to easily interact with Replit's graphql API!

Downloads

26

Readme

Replit's graphql package Node.js

A package to easily interact with Replit's graphql API!

This package includes:

  • fetch: A function to fetch the data from the endpoint
  • getUser: A function to get some informations on a user
  • getRepl:A function to get some informations on a repl
  • buildRequest: A function to get the body of the request (JSON)
  • buildQuery: A function to build the query from an object
  • getPossibleTargets: Return an array with the possible targets
  • getInfosOnTarget: return some infos on a target

Install the package

npm install replit-graphql-api

Import the package

import GraphQL from 'replit-graphql-api'

Fetch data

import { fetch } from 'replit-graphql-api'

fetch({
  operationName: 'UserCard',
  query: `
    query UserCard($username: String!) {
      userByUsername(username: $username) {
        id
        fullName
        username
        url
        bio
        image
        followerCount
        followCount
      }
    }
  `,
  variables: {
    username: 'nathanTi'
  }
})

Note: The following funtions will build the query themselves.

Get a user's data

import { getUser } from 'replit-graphql-api'

getUser({
  // the username
  username: 'nathanTi',

  // the infos you want to access to (optionnal, default is ['id', 'title', 'timeCreated', 'imageUrl', 'description', 'commentCount'])
  fields: [
    'id',
    'fullName',
    'username',
    'url',
    'bio',
    'image',
    'followerCount',
    'followCount'
  ]
})
  .then(data => {
    console.log(data);
  })

// Result:
{
  user: {
    id: '...',
    fullName: '...',
    username: '...'
    // ...
  }
}

Get a repl's data

To find a repl, you can search it with it's url or it's id

import { getRepl } from 'replit-graphql-api'

getRepl({
  // the username
  url: '/@<username>/<repl-name>',

  // the infos you want to access to (optionnal, default is ['id', 'title', 'timeCreated', 'imageUrl', 'description', 'commentCount']
  fields: ['id', 'title', 'timeCreated', 'imageUrl', 'description', 'commentCount']
})
  .then(data => {
    console.log(data);
  })

// Result:
{
  repl: {
    id: '...',
    title: '...',
    timeCreated: '...'
    // ...
  }
}

The buildRequest package

This function can be used to build a qraphql query. In the fields, you can specify a simple info,

import { fetch, buildRequest } from 'replit-graphql-api'

const request = buildRequest({
  // the typename of the thing you want to search
  target: 'Repl',

  // the data you want to access to
  fields: [
    'id',
    'title',

    // you can access to more complex data, as the infos on the owner of the repl
    {
      name: 'owner',
      fields: [
        'id',
        'username',
        'fullName'
      ]
    }
  ],

  // the variables to access to the data
  variables: {

    // YOu search a repl, so you set the variables to search for the repl here
    Repl: {
      url: '/@<username>/<repl-name>'
    }
  }
});

fetch(request)
  .then(data => {
    console.log(data);
  });

// Result:
{
  repl: {
    id: '...',
    title: '...',
    owner: {
      id: '...',
      username: '...',
      fullName: '...'
    }
  }
}

The buildQuery package

This function can be used to build a qraphql query:

import { buildQuery }

const query = buildQuery({
  target: 'Repl',
  fields: [
    'id',
    'title',
    {
      name: 'owner',
      fields: [
        'id',
        'username',
        'fullName'
      ]
    }
  ],
  variables: {
    Repl: {
      url: '/@<username>/<repl-name>'
    }
  }
});

Get all possible targets

import { getPossibleTargets } from 'replit-graphql-api'

console.log(getPossibleTargets())

Get some infos on a target

import { getInfosOnTarget } from 'replit-graphql-api'

console.log(getInfosOnTarget('Repl'))