# chimp-datasources-generator

> Helper that autogenerates DataSource-compatible APIs per controller for a given microservice, based on OpenAPI/Swagger specification

Latest version **3.0.0** (published 2022-06-08) · ISC license · 0 weekly downloads

## Install

```sh
npm install chimp-datasources-generator
pnpm add chimp-datasources-generator
yarn add chimp-datasources-generator
bun add chimp-datasources-generator
```

Provides the command `chimp-datasources-generator`.

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; large bundle.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.0.0 |
| Published | 2022-06-08 |
| First published | 2020-09-22 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 19.1 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 5 |
| Maintainers | lgandecki |

## Links

- npm: https://www.npmjs.com/package/chimp-datasources-generator
- Repository: https://github.com/xolvio/chimp-datasources-generator
- Homepage: https://github.com/xolvio/chimp-datasources-generator#readme
- Issues: https://github.com/xolvio/chimp-datasources-generator/issues
- npm.io page: https://npm.io/package/chimp-datasources-generator

## Dependencies (2)

- [shelljs](https://npm.io/package/shelljs.md) ^0.8.4
- [commander](https://npm.io/package/commander.md) ^6.1.0

## Recent versions

- 3.0.0 (latest) — 2022-06-08
- 2.0.0 — 2020-12-17
- 1.2.1 — 2020-12-07
- 1.2.0 — 2020-09-28
- 1.1.1 — 2020-09-23
- 1.1.0 — 2020-09-23
- 1.0.0 — 2020-09-22

## README

## Chimp DataSources Generator

## What

Helper that autogenerates DataSource-compatible APIs per controller for a given microservice, based on OpenAPI/Swagger specification.

You can see a real-life usage (article with a video) here: [https://www.xolv.io/blog/generate-your-apollo-datasources-2/](https://www.xolv.io/blog/generate-your-apollo-datasources-2/).

## Why

It's error-prone, slow and boring to create all those connectors manually. Most people either skip typing them, or type them manually (which is again error-prone, slow and boring). Having them generated makes the Developer Experience much nicer and the whole system significantly more maintainable.

## Usage
```
Usage: chimp-datasources-generator [options] 
[command]

Commands:
  create <directory> <api-location> [custom-data-source-import]  Create the datasources for api, pass either a URL or a yaml/json file. 
   Use http/https when pointing to a URL and relative location when pointing to a file 
     Examples: 
       chimp-datasources-generator create ./generated/external-apis https://domain.com/v3/api-docs.yaml
       chimp-datasources-generator create ./generated/external-apis ./api-docs.yaml
   You can also specify your own custom data source import:
  chimp-datasources-generator create ./generated/external-apis ./api-docs.yaml "@app/apis/DataSource#DataSource"   "@app/apis/DataSource#DataSource" will use an import of:
       import { DataSource } from "@app/apis/DataSource"
     For a default import just use the path:
       "@app/apis/BaseDataSource"

```

In your code create dataSources.ts file like this one:

```typescript
import { Controllers } from "@generated/external-apis";

export const dataSources = () => ({
  todoListsApi: new Controllers("http://localhost:8090/"),
});

export type DataSources = ReturnType<typeof dataSources>;

```

Add the dataSources to your ApolloServer configuration
```typescript
new ApolloServer({
    schema,
    dataSources,
  });
```

Make sure to add the DataSources to the GqlContext type in ./src/context.ts

```typescript
import { DataSources } from "@app/dataSources";

export type GqlContext = { dataSources: DataSources };
```

## How

We are using the swagger-codegen-cli with custom templates and a bit of extra scripting.

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