Giter Club home page Giter Club logo

arvore's Introduction

Arvore

Phoenix API server to manage school networks, schools and classes.

The one and only database model is called Entity. It represent school networks, schools and classes based on the type key, and those entities are related through their parent_id keys.

  • A network may have many schools as children. It cannot have a parent.
  • A school may have only one network as parent, and many classes as children.
  • A class may have only one school as parent and no children.

The subtree_ids key must contain the ids of all the entity's children, and their children recursively. Entities are fetched using a recursive common table expression.

Ex: A network has 100 schools, and each school has 1 to 10 classes. subtree_ids must contain the ids of all related schools and classes.

Running locally

  • Run docker-compose up -d to setup the MySQL database container.
  • Run mix setup to install and setup dependencies
  • Start Phoenix endpoint with mix phx.server or inside IEx with iex -S mix phx.server

Now you can visit localhost:4000/api/graphql to use the interactive GraphQL interface.

API

A GraphQL API is exposed at /api.

To authenticate your local requests use the x-api-key header with test_key as value. The same is required to run queries via the interactive GraphQL interface.

The following queries are available:

Create Entity

mutation CreateEntity(
  $name: String!,
  $entityType: String!,
  $inep: String,
  $parentId: Int,
) {
createEntity(
  name: $name,
  entityType: $entityType, 
  inep: $inep,
  parent_id: $parentId
) {
  id
  name
  entityType
  inep
  parentId
  subtreeIds
}

Update Entity

mutation UpdateEntity(
  $id: Int!,
  $name: String,
  $entityType: String,
  $inep: String,
  $parentId: Int,
) {
updateEntity(
  id: $id,
  name: $name,
  entityType: $entityType, 
  inep: $inep,
  parent_id: $parentId
) {
  id
  name
  entityType
  inep
  parentId
  subtreeIds
}

Get Entity

query GetEntity($id: Int!) {
  getEntity(id: $id) {
    id
    name
    entityType
    inep
    parentId
    subtreeIds
  }
}

E2E Tests

Domain and GraphQL API modules are fully tested on test/e2e/entities_test.ex.

Coverage

Load Tests

Simple wrk load test lua scripts are at test/load_tests.

  • Install wrk
  • Start the server locally
  • Run: wrk http://localhost:4000/api/ -s test/load_tests/<load_test_file>.lua

Create Entity load test

Low complexity validation + I/O operation. CreateEntity

Fetch Entity load test

High complexity recursive fetch on 2000+ nested entities.

If you created any enitities before running the seeder, drop the local database and run the seeder before running this test. This will query for a network with thousands of entities in it's subtree.

FetchEntities

arvore's People

Contributors

vitorlimadev avatar

Watchers

 avatar

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.