# modelizr

> Generate GraphQL queries from Data Models that can be mocked and normalized.

Latest version **1.0.5** (published 2017-10-30) · MIT license · 0 weekly downloads

## Install

```sh
npm install modelizr
pnpm add modelizr
yarn add modelizr
bun add modelizr
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.5 |
| Published | 2017-10-30 |
| First published | 2016-02-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 175 |
| Author | Julien Vincent |
| Maintainers | julienvincent |
| Keywords | modelizr, graphql, model, normalizr, mock, queries |

## Links

- npm: https://www.npmjs.com/package/modelizr
- Repository: https://github.com/julienvincent/modelizr
- Homepage: https://github.com/julienvincent/modelizr#readme
- Issues: https://github.com/julienvincent/modelizr/issues
- npm.io page: https://npm.io/package/modelizr

## Dependencies (4)

- [faker](https://npm.io/package/faker.md) ^3.1.0
- [lodash](https://npm.io/package/lodash.md) ^4.16.6
- [normalizr](https://npm.io/package/normalizr.md) ^2.2.1
- [isomorphic-fetch](https://npm.io/package/isomorphic-fetch.md) ^2.2.1

## Alternatives

- [apollo-link-http-common](https://npm.io/package/apollo-link-http-common.md) — 879.0K weekly downloads
- [react-relay](https://npm.io/package/react-relay.md) — 336.8K weekly downloads
- [relay-test-utils](https://npm.io/package/relay-test-utils.md) — 181.6K weekly downloads
- [@vendure/core](https://npm.io/package/@vendure/core.md) — 14.8K weekly downloads
- [@pnpm/deps.graph-sequencer](https://npm.io/package/@pnpm/deps.graph-sequencer.md) — 13.4K weekly downloads

## Recent versions

- 1.0.5 (latest) — 2017-10-30
- 0.7.9 (canary) — 2016-07-07
- 1.0.4 — 2017-06-25
- 1.0.3 — 2017-06-07
- 1.0.2 — 2017-06-05
- 1.0.1 — 2017-02-27
- 1.0.0 — 2017-02-27
- 1.0.0-beta.12 — 2017-02-24
- 1.0.0-beta.11 — 2017-02-24
- 1.0.0-beta.10 — 2017-01-14
- 1.0.0-beta.9 — 2016-12-07
- 1.0.0-beta.8 — 2016-11-17
- 1.0.0-beta.7 — 2016-11-11
- 1.0.0-beta.6 — 2016-11-09
- 1.0.0-beta.5 — 2016-11-09
- … 50 more at https://npm.io/package/modelizr/versions

## README

# modelizr
[![Coverage Status](https://coveralls.io/repos/github/julienvincent/modelizr/badge.svg?branch=master)](https://coveralls.io/github/julienvincent/modelizr?branch=master)
[![Build Status](https://travis-ci.org/julienvincent/modelizr.svg?branch=master)](https://travis-ci.org/julienvincent/modelizr)
[![npm version](https://badge.fury.io/js/modelizr.svg)](https://badge.fury.io/js/modelizr)
[![Gitter](https://badges.gitter.im/julienvincent/modelizr.svg)](https://gitter.im/julienvincent/modelizr?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)

A Combination of normalizr, fakerjs and GraphQL that allows you to define multipurpose models that can generate GraphQL queries, mock deeply nested data and normalize

## Installation

`$ yarn add modelizr`

## What can I use this for?

+ Easily generating GraphQL queries from models.
+ Flat-mapping responses using [normalizr](https://github.com/gaearon/normalizr).
+ Mocking deeply nested data that match the structure of a GraphQL query.

___

Read my [medium post](https://medium.com/@julienvincent/modelizr-99e59c1c4431#.applec5ut) on why I wrote modelizr.

## What does it look like?

```javascript
import { Modelizr } from 'modelizr'

const ModelData = {
  Person: {
    normalizeAs: "People",
    fields: {
      id: Number,
      firstName: String,
      Books: ["Book"]
    }
  },
    
  Book: {
    normalizeAs: "Books",
    fields: {
      id: Number,
      title: String,
      Author: "Person"
    }
  }
}

const {query, models: {Person, Book}} = new Modelizr({
  models: ModelData,
  config: {
    endpoint: "http:// ..."
  }
})

query(
  Person({id: 1}
    Book("Books")
  ),
  
  Book("Books", {ids: [4, 5]})
).then((res, normalize) => {
  normalize(res.body) // -> normalized response.
})
```
This will generate the following query and make a request using it.
```
{
  Person(id: 1) {
    id,
    firstName,
    Books {
      id,
      title
    }
  },
  
  Books(ids: [4, 5]) {
    id,
    title,
    Author {
      id,
      firstName
    }
  }
}
```

## Documentation

**NOTE:** Documentation for pre-`v1.0.0` can be found [Here](https://github.com/julienvincent/modelizr/tree/master/docs/v0.7.x)

All documentation is located at [julienvincent.github.io/modelizr](http://julienvincent.github.io/modelizr)

* [Usage](http://julienvincent.github.io/modelizr/docs/usage)
* [Patterns](http://julienvincent.github.io/modelizr/docs/patterns)
* [API Reference](http://julienvincent.github.io/modelizr/docs/api)
* [Changelog](https://github.com/julienvincent/modelizr/releases)

## Example

+ `$ yarn`
+ `$ yarn start`

navigate to `http://localhost:8000` in your browser

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