Code Monkey home page Code Monkey logo

data-shaper's People

Contributors

kbrabrand avatar rexxars avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

data-shaper's Issues

Support referencing data from incoming relations

Right now its possible to express one-to-one and many-to-one relations, but there's no way of expressing one-to-many or many-to-many. The following is a proposal on how *-to-many could be described as a way of looking up incoming connections from coupling tables.

var participantShape = {
    collectionName: 'participants',
    shape: {
        id: 'id',
        type: 'name'
    }
}

var eventIncidentsShape = {
    collectionName: 'eventIncidents',
    shape: {
        id: 'id',
        elapsed: 'elapsed',
        participants: {
            reference: 'eventIncidentDetails(eventIncidents=id).participantId',
            shape: participantShape
        }
    }
};

Given the following data in the database;

# eventIncidents
+----+---------+---------------------+---------+
| id | eventId | eventIncidentTypeId | elapsed |
+----+---------+---------------------+---------+
|  1 |      48 |                 724 |       0 |
|  2 |      39 |                 724 |       0 |
|  3 |      48 |                 832 |       0 |
+----+---------+---------------------+---------+

# eventIncidentDetails
+-----+-------------+-----------------+---------------+--------------------------+
| id  | type        | eventIncidentId | participantId | value                    |
+-----+-------------+-----------------+---------------+--------------------------+
| 115 | team        |              39 |          5672 |                          |
| 123 | statusTime  |              39 |             0 | 2015-02-17T19:55:18.000Z |
| 147 | team        |              48 |          5672 |                          |
| 159 | statusTime  |              48 |             0 | 2015-02-17T19:57:56.000Z |
| 162 | player1     |              48 |         30529 |                          |
| 163 | coordinates |              48 |             0 | 20:7                     |
+-----+-------------+-----------------+---------------+--------------------------+

If we fetch the eventIncidents and use the eventIncidentsShape, the resolver will
parse the reference eventIncidentDetails(eventIncidents=id).participantId, look
up all items in the eventIncidentDetails collection where eventIncidents=id (the id
from the referring object) and fetch all non-null participantIds.

Next the participantShape will be used for each of the participantIds ending with the
result looking like this;

{
    eventIncidents: {
        '39' : {
            id: 39,
            elapsed: 0,
            participants: { participants: [5672] }
        },
        '48' : {
            id: 48,
            elapsed: 0,
            participants: { participants: [30529] }
        }
    },
    participants: {
        '5672': {..},
        '30529': {..}
    }
}

In another case an incident may have more than one participant and then the participants
array would hold more than one id.

Support single reverse reference

Let's say I have two collection called catBreeds and translations. It contains the following:

catBreeds

id name description
1 Norwegian Forest Cat the most awesome of cats
2 Scottish fold the cutest of cats

translations

id catBreedId translatedName
11 1 Norsk skogkatt
12 2 Skotsk kattepus

The problem

I want the shape of my catBreeds to return the translated name for the cat:

{
    collectionName: 'catBreeds',
    shape: {
        id: 'id',
        name: 'name',
        translated: {
            reference: 'translations(catBreedId=id)',
            shape: {
                collectionName: 'translations',
                shape: {
                    id: 'id',
                    translatedName: 'translatedName'
                }
            }
        }
    }
}

The problem is that this assumes a multi-reference - that is, it returns an array of IDs instead of a single ID:

translated: {
    catBreeds: [
        1
    ]
}

It would be nice if there was a way to specify that this is a single reverse reference, which would return an ID instead of an array in this case.

Write test for nulled fragment data

I'm having a hard time figuring out the flow and how this bug occurs. Basically it has to do with references that can't be resolved (0, for instance). They are returned from the fetcher as null and something in the resolve-fragment code tries to map over the values and extract the IDs from it. That obviously fails when encountering a null.

I hotfixed it with d566b43, but someone(tm) should add a test to ensure there are no regressions later.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.