# remote-graphql-binding

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

Latest version **2.3.0** (published 2018-09-17) · MIT license · 0 weekly downloads

## Install

```sh
npm install remote-graphql-binding
pnpm add remote-graphql-binding
yarn add remote-graphql-binding
bun add remote-graphql-binding
```

Provides the command `remote-graphql-binding`.

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.3.0 |
| Published | 2018-09-17 |
| First published | 2018-06-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 12 |
| Unpacked size | 59.8 KB |
| Known vulnerabilities | 0 (+3 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Johannes Schickling |
| Maintainers | ezeki |

## Links

- npm: https://www.npmjs.com/package/remote-graphql-binding
- Repository: https://github.com/jokio/remote-graphql-binding
- Issues: https://github.com/graphcool/graphcool-binding/issues
- npm.io page: https://npm.io/package/remote-graphql-binding

## Dependencies (12)

- [node-fetch](https://npm.io/package/node-fetch.md) ^2.1.2
- [apollo-link](https://npm.io/package/apollo-link.md) 1.2.2
- [cross-fetch](https://npm.io/package/cross-fetch.md) 2.1.1
- [jsonwebtoken](https://npm.io/package/jsonwebtoken.md) 8.2.1
- [graphql-tools](https://npm.io/package/graphql-tools.md) 3.0.1
- [apollo-link-ws](https://npm.io/package/apollo-link-ws.md) 1.0.8
- [graphql-binding](https://npm.io/package/graphql-binding.md) 2.1.1
- [apollo-link-http](https://npm.io/package/apollo-link-http.md) ^1.5.4
- [apollo-link-error](https://npm.io/package/apollo-link-error.md) 1.0.9
- [http-link-dataloader](https://npm.io/package/http-link-dataloader.md) ^0.1.2
- [@jokio/graphql-import](https://npm.io/package/@jokio/graphql-import.md) ^0.0.4
- [subscriptions-transport-ws](https://npm.io/package/subscriptions-transport-ws.md) 0.9.8

## Recent versions

- 2.3.0 (latest) — 2018-09-17
- 2.2.6 — 2018-09-17
- 2.2.5 — 2018-06-30
- 2.2.4 — 2018-06-30
- 2.2.3 — 2018-06-30
- 2.2.2 — 2018-06-30
- 2.2.1 — 2018-06-30
- 2.2.0 — 2018-06-30
- 2.1.11 — 2018-06-30
- 2.1.10 — 2018-06-30
- 2.1.9 — 2018-06-30
- 2.1.8 — 2018-06-30
- 2.1.7 — 2018-06-30
- 2.1.6 — 2018-06-30
- 2.1.5 — 2018-06-30
- … 5 more at https://npm.io/package/remote-graphql-binding/versions

## README

# remote-graphql-binding

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


## 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:
```sh
graphql init
``` 
2. Add generation script in package.json:
```js
{
  ...
  "scripts": {
    ...
    "generate": "graphql get-schema --all && graphql codegen"
  }
}
```
3. Generate sdk for remote graphql service:
```sh
yarn generate
# or
npm run generate
```

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


## Install
```sh
yarn add remote-graphql-binding
# or
npm install --save remote-graphql-binding
```

## Example
folder structure:
- src/index.ts
- .grpahqlconfig
- .env

.grpahqlconfig
```json
{
  "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
```env
DB_SERVICE_URL=
DB_AUTH_TOKEN=
```

src/index.ts
```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`](https://github.com/graphcool/graphql-request) under the hood.

Here is an example of how it can be used:

```js
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" } } }
```

---
_Source: https://npm.io/package/remote-graphql-binding · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
