majksa/api-template

GraphQL API template in Nette

Installs: 0

Dependents: 0

Suggesters: 0

Security: 0

Stars: 1

Forks: 1

Type:project

This package is not auto-updated.

Last update: 2024-04-22 03:21:04 UTC


README

1*ZBTCjHPrPRQqNtPnmwvfRQ.jpeg

Goal

Main goal is to provide best prepared GraphQL API starter-kit project in Nette with user registration and login.

Focused on:

  • latest PHP 8.0
  • mariadb
  • nette/* packages
  • GraphQL via maxa-ondrej/nette-graphql (and graphqlite)
  • Doctrine ORM via nettrine/*
  • Symfony components via contributte/*
  • codestyle checking via CodeSniffer and ninjify/*
  • static analysing via phpstan
  • unit / integration tests via Nette Tester and ninjify/*

Summary

  1. Initial Configuration
  2. Installation
  3. Quality Assurance
    1. Formatting
    2. Static Analysis
    3. Running tests
  4. Database

Initial Configuration

Since it is all running inside docker containers, no additional configuration is needed! Though you need to install some tools first:

  • docker and docker compose (included in docker from version 3.4)

Optional:

  • make - for easier scripts configuration
  • php8.0 and composer - if you want to run tests without having to start docker containers

Installation

  1. Create a local copy of docker-compose.local.dist.yml
    • cp docker-compose.local.dist.yml docker-compose.local.yml
  2. Start the server and run database migrations:
    1. Using Makefile
    2. Using docker compose
  3. And the backend is up and running on url: http://localhost:8080/graphql

If you wish to change the port, you can do so in docker-compose.local.yml: services > server > ports

Using Makefile

If you have installed Make, you can follow the steps bellow for the easiest setup.

  1. make compose-dev - starts docker network
  2. make prepare-db - runs database migrations and generates testing fixtures

Using docker compose

  1. docker compose -f docker-compose.local.yml up -d --force-recreate --build --remove-orphans - starts docker network
  2. docker exec -e NETTE_DEBUG=1 apitte-skeleton-app-1 bin/console orm:schema-tool:drop --force --full-database - drop the database schema
  3. docker exec -e NETTE_DEBUG=1 apitte-skeleton-app-1 bin/console migrations:migrate --no-interaction - runs database migrations
  4. docker exec -e NETTE_DEBUG=1 apitte-skeleton-app-1 bin/console doctrine:fixtures:load --no-interaction --append - generates testing fixtures

Quality Assurance

To make sure our code quality, we use 3 different tools:

  • CodeSniffer: for formatting
  • PHPStan: for static analysis
  • Nette Tester: for running tests

You can simply run all of them using composer run-script qa.

To make sure these tools run before every commit, please run: git config core.hooksPath .hooks

Formatting

We follow some basic conventions, which are set up in phpcs.xml file.

  • formatting and optimizing the code, run composer run-script cbf
  • just analysis, run composer run-script cs

Static Analysis

To prevent common and easy to find mistakes, we run a very useful tool PHPStan.

  • composer run-script phpstan

Running tests

Tests are a really important part of coding and exposes most errors before deployment.

To create a new TestCase, you can simply duplicate any existing Test inside /tests/Unit folder. \ If you wish to add a new integration test, create a new TestCase in /tests/Integration folder.

  • running all tests: composer run-script tests
  • running test coverage: composer run-script coverage

Running GraphQL request

Easiest way to run request to the api is using Altair.

Tracy bar

If you want to display the Tracy bar, that's definitely possible! Just copy the query - and variables if there are any- and add them inside the [GET] request as query and variables: