go-graphql-example

module
v0.0.0-...-541c98d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 22, 2024 License: MIT

README ยถ

Go GraphQL example

Description

The following repository contains a GraphQL API implementation example based on wind farms (i.e. a set of turbines) as entities. Included is the Rest client use case of getting insights on the weather and geography around the wind farms.

GraphQL Advantages over REST APIs

  1. ๐˜ฟ๐™–๐™ฉ๐™– ๐™๐™š๐™ฉ๐™˜๐™๐™ž๐™ฃ๐™œ: GraphQL allows clients to request only the data they need, reducing over-fetching and under-fetching.

  2. ๐™€๐™ฃ๐™™๐™ฅ๐™ค๐™ž๐™ฃ๐™ฉ ๐™Ž๐™ฉ๐™ง๐™ช๐™˜๐™ฉ๐™ช๐™ง๐™š: GraphQL has a single endpoint (/graphql) for all queries, simplifying the API surface.

  3. ๐™๐™š๐™จ๐™ฅ๐™ค๐™ฃ๐™จ๐™š ๐™๐™ค๐™ง๐™ข๐™–๐™ฉ: Clients define the structure of the response they want, enabling more precise control over data.

  4. ๐™‘๐™š๐™ง๐™จ๐™ž๐™ค๐™ฃ๐™ž๐™ฃ๐™œ: GraphQL eliminates the need for versioning by allowing clients to evolve queries independently.

  5. ๐™๐™ค๐™ค๐™ก๐™ž๐™ฃ๐™œ ๐˜ผ๐™ฃ๐™™ ๐™€๐™˜๐™ค๐™จ๐™ฎ๐™จ๐™ฉ๐™š๐™ข: GraphQL offers robust tooling and libraries for development and testing.

Description of the implementation

  • GraphQL is implemented with 99designs/gqlgen golang library
  • The API communicates with Open-Meteo for any weather or geography information.
  • The API allows CRUD operations, including pagination
  • Postgres is used to persist "Wind farm" entities
  • Wind farms store the following properties:
    • Name - string
    • Latitude - float
    • Longitude - float
  • When updating a wind farm info, an user is required to provide the id of the wind farm, but can optionally provide any of those three properties
  • When fetching wind farm info, there are a few expectations:
    • Wind farm properties, weatherForecasts and elevation should be retrieved from Weather Forecast API and Elevation API.
    • For the weatherForecasts property, we need the following Hourly Weather Variables from the Weather API below:
      • Temperature (2 m) in Celsius
      • Precipitation (rain + showers + snow) in Millimeter
      • Wind Speed (10 m) in Km/h
      • Wind Direction (10 m)
    • Wind farm property hasPrecipitationToday should be determined based on the provided weatherForecasts
  • Everything is Dockerized for continuous deployment purposes
  • Unit tests are provided

Directories ยถ

Path Synopsis
cmd
communication
pkg

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL