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

remote-graphql-binding

v2.3.0

Published

[![npm version](https://badge.fury.io/js/remote-graphql-binding.svg)](https://badge.fury.io/js/remote-graphql-binding)

Downloads

28

Readme

remote-graphql-binding

npm version

Overview

remote-graphql-binding helps to generate sdk for remote graphql services and use power of intellisense & type safety (using Typescript).

How it works

  1. Create graphqlconfig file using graphql cli:
graphql init
  1. Add generation script in package.json:
{
  ...
  "scripts": {
    ...
    "generate": "graphql get-schema --all && graphql codegen"
  }
}
  1. Generate sdk for remote graphql service:
yarn generate
# or
npm run generate

Thats it, now you can use generated file to make remote calls, please check example

Install

yarn add remote-graphql-binding
# or
npm install --save remote-graphql-binding

Example

folder structure:

  • src/index.ts
  • .grpahqlconfig
  • .env

.grpahqlconfig

{
  "projects": {
    "Neo4jService": {
      "schemaPath": "schemas/db.graphql",
      "extensions": {
        "endpoints": {
          "dev": {
            "url": "${env:DB_SERVICE_URL}",
            "headers": {
              "Authorization": "basic ${env:DB_AUTH_TOKEN}"
            }
          }
        },
        "codegen": [
          {
            "generator": "remote-graphql-binding",
            "language": "typescript",
            "output": {
              "binding": "src/generated/neo4j-service.ts"
            }
          }
        ]
      }
    }
  }
}

.env

DB_SERVICE_URL=
DB_AUTH_TOKEN=

src/index.ts

import { Binding as DB } from './generated/neo4j-service'

const service = new DB({
  endpoint: process.env.DB_SERVICE_URL,
  authorizationHeader: `basic ${process.env.DB_AUTH_TOKEN}`,
})

service.query.Song({}).then(x => console.log(x))

API

constructor(options: Options): Binding

The Options type has the following fields:

| Key | Required | Type | Default | Note | | --- | --- | --- | --- | --- | | endpoint | Yes | string | - | The endpoint of your Prisma service | | authorizationHeader | No | string | null | Authorization header for secured services | | fragmentReplacements | No | FragmentReplacements | null | A list of GraphQL fragment definitions, specifying fields that are required for the resolver to function correctly | | debug | No | boolean | false | Log all queries/mutations to the console |

request

The request method lets you send GraphQL queries/mutations to your Prisma service. The functionality is identical to the auto-generated delegate resolves, but the API is more verbose as you need to spell out the full query/mutation. request uses graphql-request under the hood.

Here is an example of how it can be used:

const query = `
  query ($userId: ID!){
    user(id: $userId) {
      id
      name
    }
  }
`

const variables = { userId: 'abc' }

binding.request(query, variables)
  .then(result => console.log(result))
// sample result:
// {"data": { "user": { "id": "abc", "name": "Sarah" } } }