Socket
Book a DemoInstallSign in
Socket

replit-graphql-api

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

replit-graphql-api

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

latest
Source
npmnpm
Version
1.0.5
Version published
Maintainers
1
Created
Source

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'))

Keywords

replit

FAQs

Package last updated on 23 Aug 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.