Skip to content
This repository has been archived by the owner on Mar 18, 2022. It is now read-only.

capelski/skills-matrix-api-graphql

Repository files navigation

Skills matrix

Skills matrix logo

Node.js GraphQL web Api exposing CRUD operations to query and modify the employees and skills of a company. The data model consists in three entities:

  • employee: Name and id
  • skill: Name and id
  • employee-skill: Relational entity containing the id of a skill and the id of an employee

The application is meant to connect against a PostgreSQL server. If no server is available or in case the connection fails, the application still will run using an In Memory data set (ideal if you don't want to bother installing PostgreSQL in your machine). The web Api exposes the following endpoints:

  • /: Graphql endpoint exposing the application schema, which does not require an Authorization token
  • /auth: Graphql endpoint exposing the application schema, which does require an Authorization token
  • /data-loader: Graphql endpoint exposing the application schema, which does require an Authorization token and uses dataloader to batch queries and improve database performance. Can be tested with any query like:
query PerformanceTest {
    One: employee(filter: { id: 1 }) {
        items {
            id
            name
        }
    }
    Two: employee(filter: { id: 2 }) {
        items {
            id
            name
        }
    }
    sqlQueries
}

This application does not implement user authentication so, in order to get authorization tokens for the /auth endpoint, the following mock endpoints can be used:

  • /nobody-token: Returns a JWT token for a user with no permissions
  • /employees-token: Returns a JWT token for a user with permissions on all employees operations
  • /skills-token: Returns a JWT token for a user with permissions on all skills operations
  • /admin-token: Returns a JWT token for a user with permissions on both skills and employees operations

To get the wep Api up and running:

npm install
npm start

And finally some Graphql queries that might come handy:

{
    __schema {
        mutationType {
            name
            fields {
                name
                description
            }
        }
        queryType {
            name
            fields {
                name
                description
            }
        }
    }
}
{
    employee(filter: { name: "A" }, first: 2, skip: 1, orderBy: { skills: -1 }) {
        totalCount
        items {
            id
            name
            skills(orderBy: { name: 1 }) {
                totalCount
                items {
                    id
                    name
                }
            }
        }
    }
}
mutation {
    addSkill(input: { name: "Vue.js", employeesId: [7, 23, 86] }) {
        id
        employees {
            items {
                name
            }
        }
    }
}

Have fun!

About

Migration of my skills-matrix-api-node web Api to GraphQL

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published