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
๐ฟ๐๐ฉ๐ ๐๐๐ฉ๐๐๐๐ฃ๐: GraphQL allows clients to request only the data they need, reducing over-fetching and under-fetching.
๐๐ฃ๐๐ฅ๐ค๐๐ฃ๐ฉ ๐๐ฉ๐ง๐ช๐๐ฉ๐ช๐ง๐: GraphQL has a single endpoint (/graphql) for all queries, simplifying the API surface.
๐๐๐จ๐ฅ๐ค๐ฃ๐จ๐ ๐๐ค๐ง๐ข๐๐ฉ: Clients define the structure of the response they want, enabling more precise control over data.
๐๐๐ง๐จ๐๐ค๐ฃ๐๐ฃ๐: GraphQL eliminates the need for versioning by allowing clients to evolve queries independently.
๐๐ค๐ค๐ก๐๐ฃ๐ ๐ผ๐ฃ๐ ๐๐๐ค๐จ๐ฎ๐จ๐ฉ๐๐ข: 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: