Skip to content
Generate GraphQL queries from models that can be mocked and normalized.
Branch: master
Clone or download
Latest commit 8dc8a02 Oct 30, 2017
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
__tests__ Number type primary keys get numeric ids when mocked Feb 27, 2017
docs
example
src fix function buildParameters omits key-value pair in params when the … Oct 30, 2017
.babelrc built model creation flow Nov 4, 2016
.editorconfig rebuilt modelbuilder and fixed mocks Feb 23, 2017
.eslintrc added debugger Nov 6, 2016
.flowconfig
.gitignore
.npmignore
.travis.yml fixed lint errors Feb 23, 2017
README.md
SUMMARY.md updated documentation to reflex v1.0.0 Feb 24, 2017
book.json
package.json 1.0.4 Jun 25, 2017
yarn.lock

README.md

modelizr

Coverage Status Build Status npm version Gitter

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.
  • Mocking deeply nested data that match the structure of a GraphQL query.

Read my medium post on why I wrote modelizr.

What does it look like?

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

All documentation is located at julienvincent.github.io/modelizr

Example

  • $ yarn
  • $ yarn start

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

You can’t perform that action at this time.