diff --git a/README.md b/README.md index 79befbe..63fa9dc 100644 --- a/README.md +++ b/README.md @@ -1 +1,88 @@ -# covid_GraphQL_API \ No newline at end of file +# covid_GraphQL_API + +## This project contains both GraphQL API and a REST API for fetching data from `https://api.covid19api.com` for certain countries. + +### The features that are included are the following: +* Registering and Loggin in for Users. +* Additional layer of authintication using JWT Tokens +* Adding, Removing, Updating, and deleting countries +* Adding, Removing, Updating, and deleteing indivisual Covid Statistics. +* Pagination for GraphQL Responses +* Monitoring certain countrie for certain users +* Subscription to certain countries and getting updates on stats for them daily + +### To run the server, you'll need to do the following: +1. Clone the repo +2. Run `go mod tidy` to get all of the reuquired packages from "go.mod". +3. Change the port inside of `server.go` file if needed, by default it runs on ```8080``` +4. Run `go run server.go` in the terminal to launch the server + +## To use the GraphQL UI to see all of the documentations for each query, head to `http://localhost:8080/` to see the UI. However, to interact with the API, you'll need to use `http://localhost:8080/query` +*Note: Keep in mind you'll need to provide authorization when using this approach to send requests. + +## To use the REST API, you can use the following URLs to query the API by navigating to /api/ +- GET /user: Returns a User by username. +- GET /countries/{id}: Returns a Country by ID. +- GET /countries: Returns a list of countries. +- POST /countries: Creates a new Country. +- PUT /countries/{id}: Updates an existing Country by ID. +- DELETE /countries/{id}: Deletes an existing Country by ID. +- GET /covid-stats/{id}: Returns a CovidStatistic by ID. +- GET /covid-stats: Returns a list of CovidStatistics. +- POST /covid-stats: Creates a new CovidStatistic. +- PUT /covid-stats/{id}: Updates an existing CovidStatistic by ID. +- DELETE /covid-stats/{id}: Deletes an existing CovidStatistic by ID. +- GET /users/{userid}/monitored-countries: Returns a list of monitored countries for a User by ID. +- POST /users/{userid}/monitored-countries: Adds a new monitored country for a User by ID. +- DELETE /users/{userid}/monitored-countries/{countryId}: Removes a monitored country for a User by ID and Country ID. +- GET /countries/top-by-case-type/{caseType}/{limit}/{userId}: Returns a list of top countries by case type for a User by ID. +- GET /countries/{countryId}/death-percentage: Returns the death percentage for a Country by ID. +- POST /register: Registers a new user. +- POST /login: Logs in a user. +- DELETE /users/{userId}: Deletes a user by ID. +- PUT /users/{userId}: Updates a user by ID. +- POST /refresh-covid-data: Refreshes COVID data for all countries. + + * Addition/Updating a new country body looks like this: + ``` +{ + "name": "Canada", + "code": "CA" +} +``` +* Addition/Updating a single covid stat looks like this: +``` +{ + "id": 1, + "country_id": 1, + "date": "2022-03-29T00:00:00Z", + "confirmed_cases": 5000, + "deaths": 200, + "recovered": 3000 +} +``` + +* Addition/Updating monitored countries: +``` +{ + "countryId": 1 +} +``` +* Registering a new user: + +``` +{ + "username": "examplename", + "email": "examplename@example.com", + "password": "Password1234!" +} +``` + +* Logging in: +``` +{ + "username": "examplename", + "password": "Password1234!" +} +``` + diff --git a/api/api.go b/api/api.go new file mode 100644 index 0000000..a0b4b32 --- /dev/null +++ b/api/api.go @@ -0,0 +1,648 @@ +package api + +import ( + "covid/database" + "covid/fetcher" + "covid/graph" + "covid/graph/model" + "database/sql" + "encoding/json" + "fmt" + "net/http" + "strconv" + "strings" + "time" + + "github.com/go-chi/chi/v5" + "golang.org/x/crypto/bcrypt" +) + +func UserHandler(db *sql.DB) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + username := r.URL.Query().Get("username") + if username == "" { + http.Error(w, "username parameter is required", http.StatusBadRequest) + return + } + + var user database.User + d := database.NewDB(db) + user, err := d.GetUserByUsername(username) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + + user.Salt = "" + user.Password = "" + + user.MonitoredCountries, err = d.GetUserMonitoredCountries(user.ID) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + + apiUser := MapDatabaseUserToAPIModel(&user) + + // Encode the user object as JSON and return it in the response + w.Header().Set("Content-Type", "application/json") + json.NewEncoder(w).Encode(apiUser) + } +} + +func CountryByIDHandler(db *sql.DB) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + idStr := chi.URLParam(r, "id") + id, err := strconv.Atoi(idStr) + if err != nil { + http.Error(w, "Invalid country ID", http.StatusBadRequest) + return + } + + d := database.NewDB(db) + country, err := d.GetCountryByID(id) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + + apiCountry := MapDatabaseCountryToAPIModel(&country) + + w.Header().Set("Content-Type", "application/json") + json.NewEncoder(w).Encode(apiCountry) + } +} + +func CountriesHandler(db *sql.DB) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + filterNameContains := r.URL.Query().Get("filterNameContains") + filterCodeEquals := r.URL.Query().Get("filterCodeEquals") + + filter := CountryFilterInput{} + if filterNameContains != "" { + filter.NameContains = &filterNameContains + } + if filterCodeEquals != "" { + filter.CodeEquals = &filterCodeEquals + } + + d := database.NewDB(db) + countries, err := d.GetCountries(nil, nil, filter.CodeEquals, filter.NameContains) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + + var apiCountries []*Country + for _, country := range countries { + apiCountries = append(apiCountries, MapDatabaseCountryToAPIModel(&country)) + } + + w.Header().Set("Content-Type", "application/json") + json.NewEncoder(w).Encode(apiCountries) + } +} + +func AddCountryHandler(db *sql.DB) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + switch r.Method { + case http.MethodPost: + var input CountryInput + err := json.NewDecoder(r.Body).Decode(&input) + if err != nil { + http.Error(w, err.Error(), http.StatusBadRequest) + return + } + + if len(input.Code) != 2 { + http.Error(w, "country code must be 2 characters long", http.StatusBadRequest) + return + } + + d := database.NewDB(db) + country, ifExists, err := d.CreateCountry(input.Name, input.Code) + if err != nil { + http.Error(w, fmt.Sprintf("failed to insert new country: %v", err), http.StatusInternalServerError) + return + } + + if ifExists { + http.Error(w, "country already exists", http.StatusBadRequest) + return + } + + url := fmt.Sprintf("/api/countries/%d", country.ID) + w.Header().Set("Location", url) + w.WriteHeader(http.StatusCreated) + + default: + http.Error(w, "Method not allowed", http.StatusMethodNotAllowed) + } + } +} + +func UpdateCountryHandler(db *sql.DB) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + switch r.Method { + case http.MethodPut: + idStr := chi.URLParam(r, "id") + id, err := strconv.Atoi(idStr) + if err != nil { + http.Error(w, "Invalid country ID", http.StatusBadRequest) + return + } + + var input CountryInput + err = json.NewDecoder(r.Body).Decode(&input) + if err != nil { + http.Error(w, err.Error(), http.StatusBadRequest) + return + } + + if len(input.Code) != 2 { + http.Error(w, "country code must be 2 characters long", http.StatusBadRequest) + return + } + + d := database.NewDB(db) + country, err := d.UpdateCountry(id, input.Name, input.Code) + if err != nil { + http.Error(w, fmt.Sprintf("failed to update country: %v", err), http.StatusInternalServerError) + return + } + + url := fmt.Sprintf("/api/countries/%d", country.ID) + w.Header().Set("Location", url) + w.WriteHeader(http.StatusCreated) + + default: + http.Error(w, "Method not allowed", http.StatusMethodNotAllowed) + } + } +} + +func DeleteCountryHandler(db *sql.DB) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + switch r.Method { + case http.MethodDelete: + idStr := chi.URLParam(r, "id") + id, err := strconv.Atoi(idStr) + if err != nil { + http.Error(w, "Invalid country ID", http.StatusBadRequest) + return + } + + d := database.NewDB(db) + err = d.DeleteCountry(id) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + + w.WriteHeader(http.StatusOK) + + default: + http.Error(w, "Method not allowed", http.StatusMethodNotAllowed) + } + } +} + +func CovidStatisticByIDHandler(db *sql.DB) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + idStr := chi.URLParam(r, "id") + id, err := strconv.Atoi(idStr) + if err != nil { + http.Error(w, "Invalid CovidStatistic ID", http.StatusBadRequest) + return + } + + d := database.NewDB(db) + covidStat, err := d.GetCovidStatistic(id) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + + apiCovidStat := MapDatabaseCovidStatisticToAPIModel(&covidStat) + + w.Header().Set("Content-Type", "application/json") + json.NewEncoder(w).Encode(apiCovidStat) + } +} + +func CovidStatisticsHandler(db *sql.DB) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + if r.Method != http.MethodGet { + http.Error(w, "Method not allowed", http.StatusMethodNotAllowed) + return + } + + queryParams := r.URL.Query() + countryID := queryParams.Get("country_id") + + countryIDInt, err := strconv.Atoi(countryID) + if err != nil { + http.Error(w, "Invalid country ID", http.StatusBadRequest) + return + } + + d := database.NewDB(db) + covidStats, err := d.GetCovidStatistics(countryIDInt, nil, nil) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + + var apiCovidStats []*CovidStatistic + for i := range covidStats { + apiCovidStats = append(apiCovidStats, MapDatabaseCovidStatisticToAPIModel(&covidStats[i])) + } + + w.Header().Set("Content-Type", "application/json") + json.NewEncoder(w).Encode(apiCovidStats) + } +} + +func AddCovidStatisticHandler(db *sql.DB) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + switch r.Method { + case http.MethodPost: + var input CovidStatisticInput + err := json.NewDecoder(r.Body).Decode(&input) + if err != nil { + http.Error(w, err.Error(), http.StatusBadRequest) + return + } + + countryID, err := strconv.Atoi(input.CountryID) + if err != nil { + http.Error(w, fmt.Sprintf("invalid country ID: %v", err), http.StatusBadRequest) + return + } + + date, err := time.Parse("2006-01-02", input.Date) + if err != nil { + http.Error(w, fmt.Sprintf("invalid date: %v", err), http.StatusBadRequest) + return + } + + d := database.NewDB(db) + covidStatisticID, err := d.AddCovidStatistic(countryID, date.Format("2006-01-02"), input.Confirmed, input.Recovered, input.Deaths) + if err != nil { + http.Error(w, fmt.Sprintf("failed to insert new covid statistic: %v", err), http.StatusInternalServerError) + return + } + + url := fmt.Sprintf("/covid-stats/%d", covidStatisticID) + w.Header().Set("Location", url) + w.WriteHeader(http.StatusCreated) + + default: + http.Error(w, "Method not allowed", http.StatusMethodNotAllowed) + } + } +} + +func UpdateCovidStatisticHandler(db *sql.DB) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + id := chi.URLParam(r, "id") + covidStatisticID, err := strconv.Atoi(id) + if err != nil { + http.Error(w, "Invalid covid statistic ID", http.StatusBadRequest) + return + } + + var input CovidStatisticInput + err = json.NewDecoder(r.Body).Decode(&input) + if err != nil { + http.Error(w, "Invalid request body", http.StatusBadRequest) + return + } + + dateTime, err := time.Parse("2006-01-02", input.Date) + if err != nil { + http.Error(w, "Invalid date", http.StatusBadRequest) + return + } + + d := database.NewDB(db) + _, err = d.UpdateCovidStatistic(covidStatisticID, dateTime.Format("2006-01-02"), input.Confirmed, input.Recovered, input.Deaths) + if err != nil { + http.Error(w, "Failed to update covid statistic", http.StatusInternalServerError) + return + } + + w.Header().Set("Location", fmt.Sprintf("/covid-stats/%s", id)) + w.WriteHeader(http.StatusNoContent) + } +} + +func DeleteCovidStatisticHandler(db *sql.DB) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + id := chi.URLParam(r, "id") + covidStatisticID, err := strconv.Atoi(id) + if err != nil { + http.Error(w, "Invalid covid statistic ID", http.StatusBadRequest) + return + } + + d := database.NewDB(db) + err = d.DeleteCovidStatistic(covidStatisticID) + if err != nil { + http.Error(w, "Failed to delete covid statistic", http.StatusInternalServerError) + return + } + + w.Header().Set("Location", fmt.Sprintf("/api/covid-stats/%s", id)) + w.WriteHeader(http.StatusNoContent) + } +} + +func GetMonitoredCountriesHandler(db *sql.DB) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + userID := chi.URLParam(r, "userid") + id, err := strconv.Atoi(userID) + if err != nil { + fmt.Println("ID: ", id) + http.Error(w, "Invalid user ID", http.StatusBadRequest) + return + } + + d := database.NewDB(db) + monitoredCountries, err := d.GetUserMonitoredCountries(id) + if err != nil { + http.Error(w, "Failed to get monitored countries", http.StatusInternalServerError) + return + } + + apiMonitoredCountries := MapDatabaseCountriesToAPIModels(monitoredCountries) + + w.Header().Set("Content-Type", "application/json") + json.NewEncoder(w).Encode(apiMonitoredCountries) + } +} + +func AddUserMonitoredCountryHandler(db *sql.DB) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + userID := chi.URLParam(r, "userid") + userIDInt, err := strconv.Atoi(userID) + if err != nil { + http.Error(w, "Invalid user ID", http.StatusBadRequest) + return + } + + var input struct { + CountryID int `json:"countryId"` + } + err = json.NewDecoder(r.Body).Decode(&input) + if err != nil { + http.Error(w, "Invalid request body", http.StatusBadRequest) + return + } + + d := database.NewDB(db) + if err := d.AddUserMonitoredCountry(userIDInt, input.CountryID); err != nil { + http.Error(w, "Failed to add monitored country", http.StatusInternalServerError) + return + } + + location := fmt.Sprintf("/users/%s/monitored-countries", userID) + w.Header().Set("Location", location) + w.WriteHeader(http.StatusCreated) + } +} + +func DeleteUserMonitoredCountryHandler(db *sql.DB) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + userID := chi.URLParam(r, "userid") + countryID := chi.URLParam(r, "countryid") + userIDInt, err := strconv.Atoi(userID) + if err != nil { + http.Error(w, "Invalid user ID", http.StatusBadRequest) + return + } + countryIDInt, err := strconv.Atoi(countryID) + if err != nil { + http.Error(w, "Invalid country ID", http.StatusBadRequest) + return + } + + d := database.NewDB(db) + if err := d.RemoveUserMonitoredCountry(userIDInt, countryIDInt); err != nil { + http.Error(w, "Failed to remove monitored country", http.StatusInternalServerError) + return + } + w.WriteHeader(http.StatusOK) + } +} + +func GetTopCountriesByCaseTypeForUserHandler(db *sql.DB) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + // Parse user ID from URL parameter + userID := chi.URLParam(r, "userid") + userIDInt, err := strconv.Atoi(userID) + if err != nil { + http.Error(w, "Invalid user ID", http.StatusBadRequest) + return + } + + caseTypeString := chi.URLParam(r, "caseType") + caseType := model.CaseType(strings.ToUpper(caseTypeString)) + if !caseType.IsValid() { + http.Error(w, "Invalid case type", http.StatusBadRequest) + return + } + + limitString := chi.URLParam(r, "limit") + limit, err := strconv.Atoi(limitString) + if err != nil { + http.Error(w, "Invalid limit", http.StatusBadRequest) + return + } + + d := database.NewDB(db) + countries, err := d.GetTopCountriesByCaseTypeForUser(userIDInt, caseType.String(), limit) + if err != nil { + http.Error(w, "Failed to get top countries by case type", http.StatusInternalServerError) + return + } + + apiCountries := MapDatabaseCountriesToAPIModels(countries) + + w.Header().Set("Content-Type", "application/json") + json.NewEncoder(w).Encode(apiCountries) + } +} + +func GetDeathPercentageHandler(db *sql.DB) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + // Parse country ID from URL parameter + countryID := chi.URLParam(r, "countryId") + countryIDInt, err := strconv.Atoi(countryID) + if err != nil { + http.Error(w, "Invalid country ID", http.StatusBadRequest) + return + } + + d := database.NewDB(db) + deathPercentage, err := d.GetDeathPercentage(countryIDInt) + if err != nil { + http.Error(w, "Failed to get death percentage", http.StatusInternalServerError) + return + } + + w.Header().Set("Content-Type", "application/json") + json.NewEncoder(w).Encode(map[string]float64{"deathPercentage": deathPercentage}) + } +} + +func RegisterHandler(db *sql.DB) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + input := UserInput{} + + err := json.NewDecoder(r.Body).Decode(&input) + if err != nil { + http.Error(w, "Invalid request body", http.StatusBadRequest) + return + } + d := database.NewDB(db) + err = validation(input, w, d) + if err != nil { + return + } + + hashedPassword, salt, err := graph.HashPassword(input.Password) + if err != nil { + http.Error(w, "Failed to hash password", http.StatusInternalServerError) + return + } + + userID, err := d.RegisterUser(input.Username, input.Email, hashedPassword, salt) + if err != nil { + http.Error(w, "Failed to register user", http.StatusInternalServerError) + return + } + + // Generate a JWT token + token, err := graph.GenerateToken(input.Username) + if err != nil { + http.Error(w, "Failed to generate token", http.StatusInternalServerError) + return + } + + // Return the response + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusCreated) + json.NewEncoder(w).Encode(LoginResponse{ + Token: token, + User: MapDatabaseUserToAPIModel(&database.User{ + ID: int(userID), + Username: input.Username, + Email: input.Email, + }), + }) + } +} + +func validation(input UserInput, w http.ResponseWriter, d *database.DB) error { + if input.Username == "" || input.Email == "" || input.Password == "" { + http.Error(w, "Username, email, and password are required", http.StatusBadRequest) + return fmt.Errorf("username, email, and password are required") + } + + if err := graph.ValidateUsername(input.Username); err != nil { + return err + } + + if err := graph.ValidateEmail(input.Email); err != nil { + return err + } + + if err := graph.ValidatePassword(input.Password); err != nil { + return err + } + + if err := d.CheckIfUserExists(input.Username); err != nil { + return err + } + + if err := d.CheckIfEmailExists(input.Email); err != nil { + return err + } + + return nil +} + +func LoginHandler(db *sql.DB) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + var input UserInput + + err := json.NewDecoder(r.Body).Decode(&input) + if err != nil { + http.Error(w, "Invalid request body", http.StatusBadRequest) + return + } + + if input.Username == "" || input.Password == "" { + http.Error(w, "Username and password are required", http.StatusBadRequest) + return + } + + d := database.NewDB(db) + user, err := d.GetUserByUsername(input.Username) + if err != nil { + http.Error(w, "Invalid username or password", http.StatusBadRequest) + return + } + + err = bcrypt.CompareHashAndPassword([]byte(user.Password), []byte(input.Password+user.Salt)) + if err != nil { + http.Error(w, "Invalid username or password", http.StatusBadRequest) + return + } + + token, err := graph.GenerateToken(input.Username) + if err != nil { + http.Error(w, "Failed to generate token", http.StatusInternalServerError) + return + } + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + json.NewEncoder(w).Encode(LoginResponse{ + Token: token, + User: MapDatabaseUserToAPIModel(&user), + }) + } +} + +func DeleteUserHandler(db *sql.DB) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + userID := chi.URLParam(r, "userid") + userIDInt, err := strconv.Atoi(userID) + if err != nil { + http.Error(w, "Invalid user ID", http.StatusBadRequest) + return + } + + d := database.NewDB(db) + if err := d.DeleteUser(userIDInt); err != nil { + http.Error(w, "Failed to delete user", http.StatusInternalServerError) + return + } + + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + } +} + +func RefreshCovidDataForAllCountriesHandler(db *sql.DB) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + + if err := fetcher.FetchAndUpdateData(db); err != nil { + http.Error(w, "Failed to refresh COVID data", http.StatusInternalServerError) + return + } + + w.WriteHeader(http.StatusOK) + } +} diff --git a/api/apiMapping.go b/api/apiMapping.go new file mode 100644 index 0000000..17ff463 --- /dev/null +++ b/api/apiMapping.go @@ -0,0 +1,145 @@ +package api + +import ( + "covid/database" + "fmt" + "strconv" +) + +type UserInput struct { + Username string `json:"username"` + Email string `json:"email"` + Password string `json:"password"` +} + +type User struct { + ID string `json:"id"` + Username string `json:"username"` + Email string `json:"email"` + MonitoredCountries []*Country `json:"monitored_countries"` +} + +type Country struct { + ID string `json:"id"` + Name string `json:"name"` + Code string `json:"code"` +} + +type CovidStatistic struct { + ID string `json:"id"` + CountryID string `json:"country_id"` + Date string `json:"date"` + Confirmed int `json:"confirmed"` + Recovered int `json:"recovered"` + Deaths int `json:"deaths"` +} + +type CountryFilterInput struct { + NameContains *string `json:"nameContains,omitempty"` + CodeEquals *string `json:"codeEquals,omitempty"` +} + +type CountryInput struct { + Name string `json:"name"` + Code string `json:"code"` +} + +type CovidStatisticInput struct { + CountryID string `json:"countryID"` + Date string `json:"date"` + Confirmed int `json:"confirmed"` + Recovered int `json:"recovered"` + Deaths int `json:"deaths"` +} + +type LoginResponse struct { + Token string `json:"token"` + User *User `json:"user"` +} + +func MapDatabaseCovidStatisticsToAPIModels(covidStatistics []*database.CovidStatistic) []*CovidStatistic { + var apiModels []*CovidStatistic + for _, cs := range covidStatistics { + apiModels = append(apiModels, MapDatabaseCovidStatisticToAPIModel(cs)) + } + return apiModels +} + +func MapDatabaseCovidStatisticToAPIModel(covidStatistic *database.CovidStatistic) *CovidStatistic { + return &CovidStatistic{ + ID: fmt.Sprint(covidStatistic.ID), + CountryID: fmt.Sprint(covidStatistic.CountryID), + Date: covidStatistic.Date, + Confirmed: covidStatistic.Confirmed, + Recovered: covidStatistic.Recovered, + Deaths: covidStatistic.Deaths, + } +} + +func MapDatabaseCountryToAPIModel(country *database.Country) *Country { + return &Country{ + ID: fmt.Sprint(country.ID), + Name: country.Name, + Code: country.Code, + } +} + +func MapDatabaseCountriesToAPIModels(countries []database.Country) []*Country { + var apiModels []*Country + for _, country := range countries { + apiModels = append(apiModels, MapDatabaseCountryToAPIModel(&country)) + } + return apiModels +} + +func MapDatabaseUserToAPIModel(user *database.User) *User { + return &User{ + ID: fmt.Sprint(user.ID), + Email: user.Email, + Username: user.Username, + MonitoredCountries: MapDatabaseCountriesToAPIModels(user.MonitoredCountries), + } +} + +func MapDatabaseUsersToAPIModels(users []database.User) []*User { + var apiModels []*User + for _, user := range users { + apiModels = append(apiModels, MapDatabaseUserToAPIModel(&user)) + } + return apiModels +} + +func MapAPIUserToDatabaseModel(user *User) *database.User { + return &database.User{ + ID: mustParseInt(user.ID), + Email: user.Email, + Username: user.Username, + } +} + +func MapAPICountryToDatabaseModel(country *Country) *database.Country { + return &database.Country{ + ID: mustParseInt(country.ID), + Name: country.Name, + Code: country.Code, + } +} + +func MapAPICovidStatisticToDatabaseModel(covidStat *CovidStatistic) *database.CovidStatistic { + return &database.CovidStatistic{ + ID: mustParseInt(covidStat.ID), + CountryID: mustParseInt(covidStat.CountryID), + Date: covidStat.Date, + Confirmed: covidStat.Confirmed, + Recovered: covidStat.Recovered, + Deaths: covidStat.Deaths, + } +} + +func mustParseInt(str string) int { + i, err := strconv.Atoi(str) + if err != nil { + panic(err) + } + return i +} diff --git a/database/DELETE.go b/database/DELETE.go new file mode 100644 index 0000000..a4480ad --- /dev/null +++ b/database/DELETE.go @@ -0,0 +1,83 @@ +package database + +import ( + "fmt" +) + +func (d *DB) DeleteCovidStatistic(id int) error { + deleteCovidStatistic := "DELETE FROM covid_statistics WHERE id = ?" + result, err := d.db.Exec(deleteCovidStatistic, id) + if err != nil { + return fmt.Errorf("could not delete covid statistic: %w", err) + } + + rowsAffected, err := result.RowsAffected() + if err != nil { + return fmt.Errorf("no covid stats were affected: %s", err) + } + + if rowsAffected == 0 { + return fmt.Errorf("covid stat not found") + } + + return nil + +} + +func (d *DB) DeleteCountry(countryID int) error { + deleteCountry := "DELETE FROM countries WHERE id = ?" + result, err := d.db.Exec(deleteCountry, countryID) + if err != nil { + return fmt.Errorf("could not delete country: %w", err) + } + + rowsAffected, err := result.RowsAffected() + if err != nil { + return fmt.Errorf("no countries were affected: %s", err) + } + + if rowsAffected == 0 { + return fmt.Errorf("country not found") + } + + return nil +} + +func (d *DB) DeleteUser(id int) error { + deleteUserQuery := "DELETE FROM users WHERE id = ?" + res, err := d.db.Exec(deleteUserQuery, id) + if err != nil { + return fmt.Errorf("failed to execute delete query: %w", err) + } + + rowsAffected, err := res.RowsAffected() + if err != nil { + return fmt.Errorf("failed to get number of affected rows: %w", err) + } + + if rowsAffected == 0 { + return fmt.Errorf("user with ID %d not found", id) + } + + return nil +} + +func (d *DB) RemoveUserMonitoredCountry(userID int, countryID int) error { + removeUserMonitoredCountryQuery := ` + DELETE FROM user_monitored_countries + WHERE user_id = ? AND country_id = ?;` + result, err := d.db.Exec(removeUserMonitoredCountryQuery, userID, countryID) + if err != nil { + return fmt.Errorf("error removing user monitored country from database: %w", err) + } + + affectedRows, err := result.RowsAffected() + if err != nil { + return fmt.Errorf("failed to get affected rows: %w", err) + } + + if affectedRows == 0 { + return fmt.Errorf("no rows were affected by the delete statement") + } + return nil +} diff --git a/database/GET.go b/database/GET.go new file mode 100644 index 0000000..657ed61 --- /dev/null +++ b/database/GET.go @@ -0,0 +1,399 @@ +package database + +import ( + "database/sql" + "encoding/base64" + "errors" + "fmt" + "strings" +) + +func (d *DB) GetUserByID(id int) (User, error) { + user := User{} + getUserQuery := "SELECT id, username, email, password FROM users WHERE id = ?" + row := d.db.QueryRow(getUserQuery, id) + err := row.Scan(&user.ID, &user.Username, &user.Email, &user.Password) + if err != nil { + return user, fmt.Errorf("could not get user: %w", err) + } + return user, nil +} + +func (d *DB) GetUserByUsername(username string) (User, error) { + user := User{} + getUserQuery := "SELECT id, username, email, password, salt FROM users WHERE username = ?" + row := d.db.QueryRow(getUserQuery, username) + err := row.Scan(&user.ID, &user.Username, &user.Email, &user.Password, &user.Salt) + if err != nil { + return user, fmt.Errorf("could not get user: %w", err) + } + return user, nil +} + +// get user by email: +func (d *DB) GetUserByEmail(email string) (User, error) { + user := User{} + getUserQuery := "SELECT id, username, email, password, salt FROM users WHERE email = ?" + row := d.db.QueryRow(getUserQuery, email) + err := row.Scan(&user.ID, &user.Username, &user.Email, &user.Password, &user.Salt) + if err != nil { + return user, fmt.Errorf("could not get user: %w", err) + } + return user, nil +} + +func (d *DB) CheckIfUserExists(username string) error { + var count int + countUsers := "SELECT COUNT(*) FROM users WHERE username = ?" + row := d.db.QueryRow(countUsers, username) + err := row.Scan(&count) + if err != nil { + return fmt.Errorf("error while scanning number of users: %w", err) + } + if count > 0 { + return errors.New("username already exists") + } + return nil +} + +func (d *DB) CheckIfEmailExists(email string) error { + var count int + countUsersEmails := "SELECT COUNT(*) FROM users WHERE email = ?" + row := d.db.QueryRow(countUsersEmails, email) + err := row.Scan(&count) + if err != nil { + return fmt.Errorf("error while scanning number of users: %w", err) + } + + if count > 0 { + return errors.New("email already exists") + } + return nil +} + +// get one sinle covid statistic +func (d *DB) GetCovidStatistic(id int) (CovidStatistic, error) { + covidStatistic := CovidStatistic{} + getCovidStatisticQuery := "SELECT id, country_id, date, confirmed, recovered, deaths FROM covid_statistics WHERE id = ?" + row := d.db.QueryRow(getCovidStatisticQuery, id) + err := row.Scan(&covidStatistic.ID, &covidStatistic.CountryID, &covidStatistic.Date, &covidStatistic.Confirmed, &covidStatistic.Recovered, &covidStatistic.Deaths) + if err != nil { + return covidStatistic, fmt.Errorf("could not get covid statistic: %w", err) + } + return covidStatistic, nil +} + +type covidStatisticsQuery struct { + sqlQuery string + args []any +} + +func (d *DB) GetCovidStatistics(countryID int, first *int, after *string) ([]CovidStatistic, error) { + covidStatsQuery, err := buildCovidStatisticsQuery(countryID, after, first) + if err != nil { + return nil, err + } + + rows, err := d.db.Query(covidStatsQuery.sqlQuery, covidStatsQuery.args...) + if err != nil { + return nil, fmt.Errorf("could not get covid statistics for country: %w", err) + } + defer rows.Close() + + var covidStatistics []CovidStatistic + for rows.Next() { + err := mapCovidStatisticsAndCountryFromRows(rows, &covidStatistics) + if err != nil { + return nil, err + } + } + + err = rows.Err() + if err != nil { + return nil, err + } + + return covidStatistics, nil +} + +func buildCovidStatisticsQuery(countryID int, after *string, first *int) (covidStatisticsQuery, error) { + query := covidStatisticsQuery{ + sqlQuery: ` + SELECT cs.id, cs.date, cs.confirmed, cs.deaths, cs.recovered, c.id, c.name, c.code + FROM covid_statistics cs + JOIN countries c ON c.id = cs.country_id + WHERE c.id = ?`, + args: []any{countryID}, + } + + // add pagination: + if after != nil { + cursor, err := base64.StdEncoding.DecodeString(*after) + if err != nil { + return query, err + } + query.sqlQuery += " AND cs.id > ?" + query.args = append(query.args, string(cursor)) + } + + //get one mroe record to check if there is a next page later: + if first != nil { + query.sqlQuery += " LIMIT ?" + query.args = append(query.args, *first+1) + } + + return query, nil +} + +func mapCovidStatisticsAndCountryFromRows(rows *sql.Rows, covidStatistics *[]CovidStatistic) error { + covidStatistic := CovidStatistic{} + country := Country{} + + err := rows.Scan( + &covidStatistic.ID, &covidStatistic.Date, &covidStatistic.Confirmed, + &covidStatistic.Deaths, &covidStatistic.Recovered, + &country.ID, &country.Name, &country.Code, + ) + if err != nil { + return fmt.Errorf("could not scan covid statistic: %w", err) + } + covidStatistic.Date = covidStatistic.Date[:10] + + covidStatistic.Country = country + *covidStatistics = append(*covidStatistics, covidStatistic) + return nil +} + +// get a speicific country by its id: +func (d *DB) GetCountryByID(id int) (Country, error) { + country := Country{} + getCountryQuery := "SELECT id, name, code FROM countries WHERE id = ?" + row := d.db.QueryRow(getCountryQuery, id) + + CovidStatistic, err := d.GetCovidStatistics(id, nil, nil) + if err != nil { + return country, fmt.Errorf("could not get covid statistics for country: %s", err) + } + country.CovidStatistics = CovidStatistic + if row.Scan(&country.ID, &country.Name, &country.Code) != nil { + return country, fmt.Errorf("could not scan country row: %w", err) + } + return country, nil +} + +func (d *DB) GetCountryIDByCovidStatisticID(covidStatisticID int) (int, error) { + getCountryIDQuery := "SELECT country_id FROM covid_statistics WHERE id = ?" + var countryID int + err := d.db.QueryRow(getCountryIDQuery, covidStatisticID).Scan(&countryID) + if err != nil { + return 0, fmt.Errorf("error getting country ID for covid statistic with ID %d: %w", covidStatisticID, err) + } + return countryID, nil +} + +func (d *DB) GetUserMonitoredCountries(userID int) ([]Country, error) { + getMonitoredCountriesQuery := ` + SELECT c.id, c.name, c.code + FROM user_monitored_countries umc + JOIN countries c ON c.id = umc.country_id + WHERE umc.user_id = ?` + rows, err := d.db.Query(getMonitoredCountriesQuery, userID) + if err != nil { + return nil, fmt.Errorf("could not get monitored countries: %w", err) + } + defer rows.Close() + + var MonitoredCountries []Country + for rows.Next() { + country := Country{} + err := rows.Scan(&country.ID, &country.Name, &country.Code) + if err != nil { + return MonitoredCountries, fmt.Errorf("could not scan monitored country: %w", err) + } + MonitoredCountries = append(MonitoredCountries, country) + } + + if err := rows.Err(); err != nil { + return MonitoredCountries, fmt.Errorf("error with rows: %w", err) + } + return MonitoredCountries, nil +} + +type countriesQuery struct { + sqlQuery string + args []any +} + +func (d *DB) GetCountries(first *int, after *string, CodeEquals *string, nameContains *string) ([]Country, error) { + countriesQuery, err := buildCountriesQuery(after, first, CodeEquals, nameContains) + if err != nil { + return nil, err + } + rows, err := d.db.Query(countriesQuery.sqlQuery, countriesQuery.args...) + if err != nil { + return nil, fmt.Errorf("could not get countries: %w", err) + } + defer rows.Close() + + var countries []Country + for rows.Next() { + err := mapCountryFromRows(rows, &countries) + if err != nil { + return nil, err + } + } + + err = rows.Err() + if err != nil { + return nil, err + } + + return countries, nil +} + +func buildCountriesQuery(after *string, first *int, CodeEquals *string, nameContains *string) (countriesQuery, error) { + query := countriesQuery{ + sqlQuery: ` + SELECT id, name, code + FROM countries`, + } + var conditions []string + + // Add code equals condition: + if CodeEquals != nil { + conditions = append(conditions, "code = ?") + query.args = append(query.args, *CodeEquals) + } + + // Add name contains condition: + if nameContains != nil { + conditions = append(conditions, "name LIKE ?") + query.args = append(query.args, "%"+*nameContains+"%") + } + + // Add pagination: + if after != nil { + cursor, err := base64.StdEncoding.DecodeString(*after) + if err != nil { + return query, err + } + conditions = append(conditions, "id > ?") + query.args = append(query.args, string(cursor)) + } + + if len(conditions) > 0 { + query.sqlQuery += " WHERE " + strings.Join(conditions, " AND ") + } + + // Get one more record to check if there is a next page later: + if first != nil { + query.sqlQuery += " LIMIT ?" + query.args = append(query.args, *first+1) + } + + return query, nil +} + +func mapCountryFromRows(rows *sql.Rows, countries *[]Country) error { + country := Country{} + err := rows.Scan(&country.ID, &country.Name, &country.Code) + if err != nil { + return fmt.Errorf("could not scan country: %w", err) + } + *countries = append(*countries, country) + return nil +} + +// get percentage of deaths in a country: +func (d *DB) GetDeathPercentage(countryID int) (float64, error) { + //case the Sum of deaths to a real number instead of an integer. + // Cause Otherwise the result will be 0 cause the division of two integers is an integer. + getDeathPercentageQuery := ` + SELECT SUM(deaths) * 1.0 / SUM(confirmed) * 100 + FROM covid_statistics + WHERE country_id = ?` + var deathPercentage float64 + err := d.db.QueryRow(getDeathPercentageQuery, countryID).Scan(&deathPercentage) + if err != nil { + return 0, fmt.Errorf("could not get death percentage: %w", err) + } + + fmt.Println("Death percentage:", deathPercentage) + return deathPercentage, nil +} + +func (d *DB) GetTopCountriesByCaseTypeForUser(userID int, caseType string, limit int) ([]Country, error) { + getTopCountriesByCaseTypeForUserQuery := buildTopCountriesByCaseTypeForUserQuery(userID, caseType, limit) + rows, err := d.db.Query(getTopCountriesByCaseTypeForUserQuery, userID, limit) + if err != nil { + return nil, fmt.Errorf("could not get top countries by case type for user: %w", err) + } + defer rows.Close() + + var countries []Country + for rows.Next() { + err := mapCountryFromRows(rows, &countries) + if err != nil { + return nil, fmt.Errorf("could not map country from rows: %w", err) + } + } + + err = rows.Err() + if err != nil { + return nil, fmt.Errorf("error with rows: %w", err) + } + + return countries, nil +} + +func buildTopCountriesByCaseTypeForUserQuery(userID int, caseType string, limit int) string { + getTopCountriesByCaseTypeForUserQuery := ` + SELECT c.id, c.name, c.code + FROM covid_statistics cs + JOIN countries c ON c.id = cs.country_id + JOIN ( + SELECT country_id, MAX(date) as latest_date + FROM covid_statistics + GROUP BY country_id + ) latest_stats ON cs.country_id = latest_stats.country_id AND cs.date = latest_stats.latest_date + WHERE cs.country_id IN ( + SELECT country_id + FROM user_monitored_countries + WHERE user_id = ? + ) + ORDER BY cs.` + caseType + ` DESC + LIMIT ?` + + return getTopCountriesByCaseTypeForUserQuery +} + +func (d *DB) GetLatestCovidStatisticsByCountryID(countryID int) (CovidStatistic, error) { + getLatestCovidStatisticsByCountryIDQuery := ` + SELECT id, country_id, confirmed, deaths, recovered, date + FROM covid_statistics + WHERE country_id = ? + ORDER BY date DESC + LIMIT 1` + row := d.db.QueryRow(getLatestCovidStatisticsByCountryIDQuery, countryID) + covidStatistics := CovidStatistic{} + err := row.Scan(&covidStatistics.ID, &covidStatistics.CountryID, &covidStatistics.Confirmed, &covidStatistics.Deaths, &covidStatistics.Recovered, &covidStatistics.Date) + if err != nil { + return covidStatistics, fmt.Errorf("could not get latest covid statistics by country id: %w", err) + } + return covidStatistics, nil +} + +func (d *DB) CheckCovidStatisticExists(countryID int, date string) (bool, error) { + checkCovidStatisticExistsQuery := ` + SELECT EXISTS ( + SELECT 1 + FROM covid_statistics + WHERE country_id = ? AND date = ? + )` + var exists bool + err := d.db.QueryRow(checkCovidStatisticExistsQuery, countryID, date).Scan(&exists) + if err != nil { + return false, fmt.Errorf("could not check covid statistic exists: %w", err) + } + return exists, nil +} diff --git a/database/POST.go b/database/POST.go new file mode 100644 index 0000000..7313843 --- /dev/null +++ b/database/POST.go @@ -0,0 +1,104 @@ +package database + +import ( + "database/sql" + "fmt" +) + +func (d *DB) CreateCovidStatistic(countryID int, date string, confirmed int, recovered int, deaths int) (CovidStatistic, error) { + result, err := d.db.Exec("INSERT INTO covid_statistics (country_id, date, confirmed, recovered, deaths) VALUES (?, ?, ?, ?, ?)", countryID, date, confirmed, recovered, deaths) + if err != nil { + return CovidStatistic{}, err + } + + id, err := result.LastInsertId() + if err != nil { + return CovidStatistic{}, err + } + + return CovidStatistic{ + ID: int(id), + CountryID: countryID, + Date: date, + Confirmed: confirmed, + Recovered: recovered, + Deaths: deaths, + }, nil +} + +func (d *DB) CreateCountry(name string, code string) (Country, bool, error) { + ifExists := checkIfCountryExists(d.db, name) + if ifExists { + return Country{}, true, nil + } + + insertCountryQuery := "INSERT INTO countries (name, code) VALUES (?, ?)" + result, err := d.db.Exec(insertCountryQuery, name, code) + if err != nil { + return Country{}, false, err + } + + id, err := result.LastInsertId() + if err != nil { + return Country{}, false, err + } + return Country{ + ID: int(id), + Name: name, + Code: code, + }, false, nil +} + +func checkIfCountryExists(db *sql.DB, name string) bool { + var id int + getCountryQuery := "SELECT id FROM countries WHERE name = ?" + row := db.QueryRow(getCountryQuery, name) + err := row.Scan(&id) + return err == nil +} + +func (d *DB) RegisterUser(username string, email string, hashedPassword []byte, salt []byte) (int64, error) { + registerNewUserQuery := "INSERT INTO users (username, email, password, salt) VALUES (?, ?, ?, ?)" + result, err := d.db.Exec(registerNewUserQuery, username, email, hashedPassword, salt) + if err != nil { + return 0, fmt.Errorf("error inserting user into database: %w", err) + } + + userID, err := result.LastInsertId() + if err != nil { + return 0, fmt.Errorf("error getting user ID: %w", err) + } + + return userID, nil +} + +func (d *DB) AddCovidStatistic(countryID int, date string, confirmed int, recovered int, deaths int) (int, error) { + addCovidStatisticQuery := ` + INSERT INTO covid_statistics + (country_id, date, confirmed, recovered, deaths) + VALUES (?, ?, ?, ?, ?);` + res, err := d.db.Exec(addCovidStatisticQuery, countryID, date, confirmed, recovered, deaths) + if err != nil { + return 0, fmt.Errorf("error inserting covid statistic into database: %w", err) + } + + covidStatisticID, err := res.LastInsertId() + if err != nil { + return 0, fmt.Errorf("error getting covid statistic ID: %w", err) + } + + return int(covidStatisticID), nil +} + +func (d *DB) AddUserMonitoredCountry(userID int, countryID int) error { + addUserMonitoredCountryQuery := ` + INSERT INTO user_monitored_countries + (user_id, country_id) + VALUES (?, ?);` + _, err := d.db.Exec(addUserMonitoredCountryQuery, userID, countryID) + if err != nil { + return fmt.Errorf("error inserting user monitored country into database: %w", err) + } + + return nil +} diff --git a/database/PUT.go b/database/PUT.go new file mode 100644 index 0000000..5e4eb2a --- /dev/null +++ b/database/PUT.go @@ -0,0 +1,56 @@ +package database + +import "fmt" + +func (d *DB) UpdateCountry(id int, name string, code string) (Country, error) { + updateNameCode := "UPDATE countries SET name = ?, code = ? WHERE id = ?" + result, err := d.db.Exec(updateNameCode, name, code, id) + if err != nil { + return Country{}, fmt.Errorf("could not update country: %w", err) + } + + rowsAffected, err := result.RowsAffected() + if err != nil { + return Country{}, fmt.Errorf("no countries were affected: %w", err) + } + + if rowsAffected == 0 { + return Country{}, fmt.Errorf("country not found") + } + + return Country{ + ID: id, + Name: name, + Code: code, + }, nil +} + +func (d *DB) UpdateCovidStatistic(id int, date string, confirmed int, recovered int, deaths int) (CovidStatistic, error) { + updateCovidStatistic := "UPDATE covid_statistics SET date = ?, confirmed = ?, recovered = ?, deaths = ? WHERE id = ?" + result, err := d.db.Exec(updateCovidStatistic, date, confirmed, recovered, deaths, id) + if err != nil { + return CovidStatistic{}, fmt.Errorf("could not update covid statistic: %w", err) + } + + rowsAffected, err := result.RowsAffected() + if err != nil { + return CovidStatistic{}, fmt.Errorf("no covid statistics were affected: %w", err) + } + if rowsAffected == 0 { + return CovidStatistic{}, fmt.Errorf("covid statistic not found") + } + + countryID, err := d.GetCountryIDByCovidStatisticID(id) + if err != nil { + return CovidStatistic{}, err + } + + return CovidStatistic{ + ID: id, + Date: date, + Confirmed: confirmed, + Recovered: recovered, + Deaths: deaths, + CountryID: countryID, + }, nil +} diff --git a/database/connection.go b/database/connection.go new file mode 100644 index 0000000..84c9e6e --- /dev/null +++ b/database/connection.go @@ -0,0 +1,122 @@ +package database + +import ( + "database/sql" + + _ "github.com/mattn/go-sqlite3" +) + +type DB struct { + db *sql.DB +} + +func ConnectDB() (db *sql.DB, err error) { + db, err = sql.Open("sqlite3", "covid.db") + if err != nil { + return nil, err + } + + _, err = db.Exec("PRAGMA foreign_keys = ON") + if err != nil { + return nil, err + } + + // create tables all at once in a transaction: + tx, err := db.Begin() + if err != nil { + return nil, err + } + + err = CreateTables(tx) + if err != nil { + tx.Rollback() + return nil, err + } + + err = tx.Commit() + if err != nil { + return nil, err + } + + return db, nil +} + +func CreateTables(tx *sql.Tx) error { + err := createCountryTable(tx) + if err != nil { + return err + } + + err = createCovidStatisticTable(tx) + if err != nil { + return err + } + + err = createUserTable(tx) + if err != nil { + return err + } + + err = createUserMonitoredCountriesTable(tx) + if err != nil { + return err + } + + return nil +} + +func createCountryTable(tx *sql.Tx) error { + createCountryTable := ` + CREATE TABLE IF NOT EXISTS countries ( + id INTEGER PRIMARY KEY, + name TEXT NOT NULL UNIQUE, + code TEXT NOT NULL UNIQUE + );` + _, err := tx.Exec(createCountryTable) + return err +} + +func createCovidStatisticTable(tx *sql.Tx) error { + createCovidStatisticTable := ` + CREATE TABLE IF NOT EXISTS covid_statistics ( + id INTEGER PRIMARY KEY, + country_id INTEGER NOT NULL, + date TEXT NOT NULL, + confirmed INTEGER NOT NULL, + recovered INTEGER NOT NULL, + deaths INTEGER NOT NULL, + FOREIGN KEY (country_id) REFERENCES countries (id) ON DELETE CASCADE + );` + _, err := tx.Exec(createCovidStatisticTable) + return err +} + +func createUserTable(tx *sql.Tx) error { + createUserTable := ` + CREATE TABLE IF NOT EXISTS users ( + id INTEGER PRIMARY KEY, + username TEXT NOT NULL UNIQUE, + email TEXT NOT NULL UNIQUE, + password TEXT NOT NULL, + salt BLOB NOT NULL + );` + _, err := tx.Exec(createUserTable) + return err +} + +func createUserMonitoredCountriesTable(tx *sql.Tx) error { + createUserMonitoredCountriesTable := ` + CREATE TABLE IF NOT EXISTS user_monitored_countries ( + user_id INTEGER NOT NULL, + country_id INTEGER NOT NULL, + PRIMARY KEY (user_id, country_id), + FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE CASCADE, + FOREIGN KEY (country_id) REFERENCES countries (id) ON DELETE CASCADE + );` + _, err := tx.Exec(createUserMonitoredCountriesTable) + return err +} + +func NewDB(db *sql.DB) *DB { + return &DB{db: db} +} diff --git a/database/models.go b/database/models.go new file mode 100644 index 0000000..7f799d1 --- /dev/null +++ b/database/models.go @@ -0,0 +1,27 @@ +package database + +type Country struct { + ID int + Name string + Code string + CovidStatistics []CovidStatistic +} + +type CovidStatistic struct { + ID int + CountryID int + Country Country + Date string + Confirmed int + Recovered int + Deaths int +} + +type User struct { + ID int + Username string + Email string + Password string + Salt string + MonitoredCountries []Country +} diff --git a/fetcher/fetcher.go b/fetcher/fetcher.go new file mode 100644 index 0000000..672fddb --- /dev/null +++ b/fetcher/fetcher.go @@ -0,0 +1,153 @@ +package fetcher + +import ( + "covid/database" + "database/sql" + "encoding/json" + "errors" + "fmt" + "io" + "log" + "net/http" + "time" +) + +type Covid19APIResponse struct { + Country string `json:"Country"` + CountryCode string `json:"CountryCode"` + Province string `json:"Province"` + Cases int `json:"Cases"` + Status string `json:"Status"` + Date string `json:"Date"` +} + +var counter int = 0 + +func StartFetchingRoutine(db *sql.DB, updateInterval time.Duration) { + go func() { + FetchAndUpdateData(db) // Call this function immediately for the initial data fetch. + for range time.Tick(updateInterval) { + FetchAndUpdateData(db) + } + }() +} + +func FetchAndUpdateData(db *sql.DB) error { + d := database.NewDB(db) + countries, err := d.GetCountries(nil, nil, nil, nil) + if err != nil { + log.Printf("Error fetching country list: %v", err) + return err + } + + for _, country := range countries { + confirmedData, err := FetchDailyDataForCountry(country.Name, "confirmed") + if err != nil { + log.Printf("Error fetching confirmed data for country %s: %v", country.Name, err) + continue + } + + deathsData, err := FetchDailyDataForCountry(country.Name, "deaths") + if err != nil { + log.Printf("Error fetching deaths data for country %s: %v", country.Name, err) + continue + } + + recoveredData, err := FetchDailyDataForCountry(country.Name, "recovered") + if err != nil { + log.Printf("Error fetching recovered data for country %s: %v", country.Name, err) + continue + } + + if err := UpdateCountryData(db, country.Name, country.ID, confirmedData, deathsData, recoveredData); err != nil { + log.Printf("Error updating country data for %s: %v", country.Name, err) + continue + } + } + return nil +} + +func FetchDailyDataForCountry(countryName string, status string) ([]Covid19APIResponse, error) { + url := fmt.Sprintf("https://api.covid19api.com/dayone/country/%s/status/%s", countryName, status) + resp, err := http.Get(url) + if err != nil { + return nil, err + } + defer resp.Body.Close() + + body, err := io.ReadAll(resp.Body) + if err != nil { + return nil, err + } + + err = handleRateLimitingError(resp, countryName, status) + if err != nil { + return nil, err + } + + var data []Covid19APIResponse + if err := json.Unmarshal(body, &data); err != nil { + return nil, err + } + + return data, nil +} + +func handleRateLimitingError(resp *http.Response, countryName string, status string) error { + // Sleep for 2 seconds to avoid rate limiting by the API caused by too many requests. + time.Sleep(5 * time.Second) + + if resp.StatusCode == http.StatusTooManyRequests { + log.Println("Too many requests, retrying in 5 seconds...") + time.Sleep(5 * time.Second) + FetchDailyDataForCountry(countryName, status) + if counter > 5 { + counter = 0 + return errors.New("too many retries, aborting") + } + counter++ + } + return nil +} + +// FindCountryByName retrieves a country record from the database by name. +func FindCountryByName(db *sql.DB, name string) (database.Country, error) { + var country database.Country + err := db.QueryRow("SELECT id, name, code FROM countries WHERE name = ?", name).Scan(&country.ID, &country.Name, &country.Code) + if err != nil { + return database.Country{}, err + } + return country, nil +} + +// UpdateCountryData updates covid statistics for a specific country in the database. +func UpdateCountryData(db *sql.DB, countryName string, countryID int, confirmedData, deathsData, recoveredData []Covid19APIResponse) error { + d := database.NewDB(db) + + country, err := d.GetCountryByID(countryID) + if err != nil { + return err + } + + for i := 0; i < len(confirmedData); i++ { + date, err := time.Parse(time.RFC3339, confirmedData[i].Date) + if err != nil { + return err + } + dateStr := date.Format("2006-01-02") + + exists, err := d.CheckCovidStatisticExists(country.ID, dateStr) + if err != nil { + return err + } + + if !exists { + _, err := d.AddCovidStatistic(country.ID, dateStr, confirmedData[i].Cases, recoveredData[i].Cases, deathsData[i].Cases) + if err != nil { + return err + } + } + } + + return nil +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..c434e02 --- /dev/null +++ b/go.mod @@ -0,0 +1,28 @@ +module covid + +go 1.20 + +require ( + github.com/99designs/gqlgen v0.17.27 + github.com/go-chi/chi/v5 v5.0.8 + github.com/golang-jwt/jwt/v5 v5.0.0-rc.2 + github.com/mattn/go-sqlite3 v1.14.16 + github.com/vektah/gqlparser/v2 v2.5.1 + golang.org/x/crypto v0.7.0 +) + +require ( + github.com/agnivade/levenshtein v1.1.1 // indirect + github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect + github.com/gorilla/websocket v1.5.0 // indirect + github.com/hashicorp/golang-lru/v2 v2.0.1 // indirect + github.com/mitchellh/mapstructure v1.5.0 // indirect + github.com/russross/blackfriday/v2 v2.1.0 // indirect + github.com/urfave/cli/v2 v2.24.4 // indirect + github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect + golang.org/x/mod v0.8.0 // indirect + golang.org/x/sys v0.6.0 // indirect + golang.org/x/text v0.8.0 // indirect + golang.org/x/tools v0.6.0 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..f9c5124 --- /dev/null +++ b/go.sum @@ -0,0 +1,68 @@ +github.com/99designs/gqlgen v0.17.27 h1:XPsaZiWY1lL2qqVYtBt37GzkyX7bBiVvda7k1buC/Ao= +github.com/99designs/gqlgen v0.17.27/go.mod h1:i4rEatMrzzu6RXaHydq1nmEPZkb3bKQsnxNRHS4DQB4= +github.com/agnivade/levenshtein v1.0.1/go.mod h1:CURSv5d9Uaml+FovSIICkLbAUZ9S4RqaHDIsdSBg7lM= +github.com/agnivade/levenshtein v1.1.1 h1:QY8M92nrzkmr798gCo3kmMyqXFzdQVpxLlGPRBij0P8= +github.com/agnivade/levenshtein v1.1.1/go.mod h1:veldBMzWxcCG2ZvUTKD2kJNRdCk5hVbJomOvKkmgYbo= +github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883 h1:bvNMNQO63//z+xNgfBlViaCIJKLlCJ6/fmUseuG0wVQ= +github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883/go.mod h1:rCTlJbsFo29Kk6CurOXKm700vrz8f0KW0JNfpkRJY/8= +github.com/arbovm/levenshtein v0.0.0-20160628152529-48b4e1c0c4d0 h1:jfIu9sQUG6Ig+0+Ap1h4unLjW6YQJpKZVmUzxsD4E/Q= +github.com/arbovm/levenshtein v0.0.0-20160628152529-48b4e1c0c4d0/go.mod h1:t2tdKJDJF9BV14lnkjHmOQgcvEKgtqs5a1N3LNdJhGE= +github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w= +github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/dgryski/trifles v0.0.0-20200323201526-dd97f9abfb48 h1:fRzb/w+pyskVMQ+UbP35JkH8yB7MYb4q/qhBarqZE6g= +github.com/dgryski/trifles v0.0.0-20200323201526-dd97f9abfb48/go.mod h1:if7Fbed8SFyPtHLHbg49SI7NAdJiC5WIA09pe59rfAA= +github.com/go-chi/chi/v5 v5.0.8 h1:lD+NLqFcAi1ovnVZpsnObHGW4xb4J8lNmoYVfECH1Y0= +github.com/go-chi/chi/v5 v5.0.8/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8= +github.com/golang-jwt/jwt/v5 v5.0.0-rc.2 h1:hXPcSazn8wKOfSb9y2m1bdgUMlDxVDarxh3lJVbC6JE= +github.com/golang-jwt/jwt/v5 v5.0.0-rc.2/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk= +github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc= +github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= +github.com/hashicorp/golang-lru/v2 v2.0.1 h1:5pv5N1lT1fjLg2VQ5KWc7kmucp2x/kvFOnxuVTqZ6x4= +github.com/hashicorp/golang-lru/v2 v2.0.1/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM= +github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/mattn/go-sqlite3 v1.14.16 h1:yOQRA0RpS5PFz/oikGwBEqvAWhWg5ufRz4ETLjwpU1Y= +github.com/mattn/go-sqlite3 v1.14.16/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg= +github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= +github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= +github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= +github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0= +github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= +github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8= +github.com/urfave/cli/v2 v2.24.4 h1:0gyJJEBYtCV87zI/x2nZCPyDxD51K6xM8SkwjHFCNEU= +github.com/urfave/cli/v2 v2.24.4/go.mod h1:GHupkWPMM0M/sj1a2b4wUrWBPzazNrIjouW6fmdJLxc= +github.com/vektah/gqlparser/v2 v2.5.1 h1:ZGu+bquAY23jsxDRcYpWjttRZrUz07LbiY77gUOHcr4= +github.com/vektah/gqlparser/v2 v2.5.1/go.mod h1:mPgqFBu/woKTVYWyNk8cO3kh4S/f4aRFZrvOnp3hmCs= +github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU= +github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8= +golang.org/x/crypto v0.7.0 h1:AvwMYaRytfdeVt3u6mLaxYtErKYjxA2OXjJ1HHq6t3A= +golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU= +golang.org/x/mod v0.8.0 h1:LUYupSeNrTNCGzR/hVBk2NHZO4hXcVaW1k4Qx7rjPx8= +golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= +golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o= +golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ= +golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/text v0.8.0 h1:57P1ETyNKtuIjB4SRd15iJxuhj8Gc416Y78H3qgMh68= +golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= +golang.org/x/tools v0.6.0 h1:BOw41kyTf3PuCW1pVQf8+Cyg8pMlkYB1oo9iJ6D/lKM= +golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= +gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10= +gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/gqlgen.yml b/gqlgen.yml new file mode 100644 index 0000000..49acdc3 --- /dev/null +++ b/gqlgen.yml @@ -0,0 +1,63 @@ +# Where are all the schema files located? globs are supported eg src/**/*.graphqls +schema: + - graph/*.graphqls + +# Where should the generated server code go? +exec: + filename: graph/generated.go + package: graph + +# Uncomment to enable federation +# federation: +# filename: graph/federation.go +# package: graph + +# Where should any generated models go? +model: + filename: graph/model/models_gen.go + package: model + +# Where should the resolver implementations go? +resolver: + layout: follow-schema + dir: graph + package: graph + +# Optional: turn on use ` + "`" + `gqlgen:"fieldName"` + "`" + ` tags in your models +# struct_tag: json + +# Optional: turn on to use []Thing instead of []*Thing +# omit_slice_element_pointers: false + +# Optional: turn off to make struct-type struct fields not use pointers +# e.g. type Thing struct { FieldA OtherThing } instead of { FieldA *OtherThing } +# struct_fields_always_pointers: true + +# Optional: turn off to make resolvers return values instead of pointers for structs +# resolvers_always_return_pointers: true + +# Optional: set to speed up generation time by not performing a final validation pass. +# skip_validation: true + +# gqlgen will search for any type names in the schema in these go packages +# if they match it will use them, otherwise it will generate them. +autobind: +# - "covid/graph/model" + +# This section declares type mapping between the GraphQL and go type systems +# +# The first line in each type will be used as defaults for resolver arguments and +# modelgen, the others will be allowed when binding to fields. Configure them to +# your liking +models: + ID: + model: + - github.com/99designs/gqlgen/graphql.ID + - github.com/99designs/gqlgen/graphql.Int + - github.com/99designs/gqlgen/graphql.Int64 + - github.com/99designs/gqlgen/graphql.Int32 + Int: + model: + - github.com/99designs/gqlgen/graphql.Int + - github.com/99designs/gqlgen/graphql.Int64 + - github.com/99designs/gqlgen/graphql.Int32 diff --git a/graph/auth.go b/graph/auth.go new file mode 100644 index 0000000..7658f87 --- /dev/null +++ b/graph/auth.go @@ -0,0 +1,53 @@ +package graph + +import ( + "errors" + "time" + + "github.com/golang-jwt/jwt/v5" +) + +var jwtKey = []byte("1234") + +type Claims struct { + Username string `json:"username"` + jwt.RegisteredClaims +} + +func GenerateToken(username string) (string, error) { + expirationTime := time.Now().Add(24 * time.Hour) + claims := &Claims{ + Username: username, + RegisteredClaims: jwt.RegisteredClaims{ + ExpiresAt: jwt.NewNumericDate(expirationTime), + }, + } + + token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims) + tokenString, err := token.SignedString(jwtKey) + + if err != nil { + return "", err + } + + return tokenString, nil +} + +func ValidateToken(tokenStr string) (string, error) { + token, err := jwt.ParseWithClaims(tokenStr, &Claims{}, func(token *jwt.Token) (interface{}, error) { + if _, ok := token.Method.(*jwt.SigningMethodHMAC); !ok { + return nil, errors.New("unexpected signing method") + } + return jwtKey, nil + }) + + if err != nil { + return "", err + } + + if claims, ok := token.Claims.(*Claims); ok && token.Valid { + return claims.Username, nil + } else { + return "", errors.New("invalid token") + } +} diff --git a/graph/generated.go b/graph/generated.go new file mode 100644 index 0000000..92aba63 --- /dev/null +++ b/graph/generated.go @@ -0,0 +1,7984 @@ +// Code generated by github.com/99designs/gqlgen, DO NOT EDIT. + +package graph + +import ( + "bytes" + "context" + "covid/graph/model" + "embed" + "errors" + "fmt" + "io" + "strconv" + "sync" + "sync/atomic" + + "github.com/99designs/gqlgen/graphql" + "github.com/99designs/gqlgen/graphql/introspection" + gqlparser "github.com/vektah/gqlparser/v2" + "github.com/vektah/gqlparser/v2/ast" +) + +// region ************************** generated!.gotpl ************************** + +// NewExecutableSchema creates an ExecutableSchema from the ResolverRoot interface. +func NewExecutableSchema(cfg Config) graphql.ExecutableSchema { + return &executableSchema{ + resolvers: cfg.Resolvers, + directives: cfg.Directives, + complexity: cfg.Complexity, + } +} + +type Config struct { + Resolvers ResolverRoot + Directives DirectiveRoot + Complexity ComplexityRoot +} + +type ResolverRoot interface { + Mutation() MutationResolver + Query() QueryResolver + Subscription() SubscriptionResolver +} + +type DirectiveRoot struct { +} + +type ComplexityRoot struct { + CountriesConnection struct { + Edges func(childComplexity int) int + PageInfo func(childComplexity int) int + } + + Country struct { + Code func(childComplexity int) int + CovidStats func(childComplexity int, after *string, first *int) int + ID func(childComplexity int) int + Name func(childComplexity int) int + } + + CountryEdge struct { + Cursor func(childComplexity int) int + Node func(childComplexity int) int + } + + CovidStatistic struct { + Confirmed func(childComplexity int) int + Country func(childComplexity int) int + Date func(childComplexity int) int + Deaths func(childComplexity int) int + ID func(childComplexity int) int + Recovered func(childComplexity int) int + } + + CovidStatisticConnection struct { + Edges func(childComplexity int) int + PageInfo func(childComplexity int) int + } + + CovidStatisticEdge struct { + Cursor func(childComplexity int) int + Node func(childComplexity int) int + } + + LoginResponse struct { + Token func(childComplexity int) int + User func(childComplexity int) int + } + + Mutation struct { + AddCountry func(childComplexity int, input model.CountryInput) int + AddCovidStatistic func(childComplexity int, input model.CovidStatisticInput) int + AddUserMonitoredCountry func(childComplexity int, userID string, countryID string) int + DeleteCountry func(childComplexity int, countryID string) int + DeleteCovidStatistic func(childComplexity int, id string) int + DeleteUser func(childComplexity int, userID string) int + RefreshCovidDataForAllCountries func(childComplexity int) int + Register func(childComplexity int, username string, email string, password string) int + RemoveUserMonitoredCountry func(childComplexity int, userID string, countryID string) int + UpdateCountry func(childComplexity int, id string, name string, code string) int + UpdateCovidStatistic func(childComplexity int, id string, date string, confirmed int, recovered int, deaths int) int + } + + PageInfo struct { + EndCursor func(childComplexity int) int + HasNextPage func(childComplexity int) int + } + + Query struct { + Countries func(childComplexity int, first *int, after *string, filter *model.CountryFilterInput) int + Country func(childComplexity int, id string) int + CovidStatistic func(childComplexity int, id string) int + CovidStatistics func(childComplexity int, countryID string, after *string, first *int) int + DeathPercentage func(childComplexity int, countryID string) int + Login func(childComplexity int, username string, password string) int + MonitoredCountries func(childComplexity int, userID string) int + TopCountriesByCaseTypeForUser func(childComplexity int, caseType model.CaseType, limit int, userID string) int + User func(childComplexity int, username *string, email *string) int + } + + Subscription struct { + CovidStatisticUpdated func(childComplexity int, countryIDs []string) int + } + + User struct { + Email func(childComplexity int) int + ID func(childComplexity int) int + MonitoredCountries func(childComplexity int) int + Password func(childComplexity int) int + Username func(childComplexity int) int + } +} + +type MutationResolver interface { + Register(ctx context.Context, username string, email string, password string) (*model.LoginResponse, error) + DeleteUser(ctx context.Context, userID string) (bool, error) + AddCountry(ctx context.Context, input model.CountryInput) (*model.Country, error) + UpdateCountry(ctx context.Context, id string, name string, code string) (*model.Country, error) + DeleteCountry(ctx context.Context, countryID string) (bool, error) + AddCovidStatistic(ctx context.Context, input model.CovidStatisticInput) (*model.CovidStatistic, error) + DeleteCovidStatistic(ctx context.Context, id string) (bool, error) + UpdateCovidStatistic(ctx context.Context, id string, date string, confirmed int, recovered int, deaths int) (*model.CovidStatistic, error) + AddUserMonitoredCountry(ctx context.Context, userID string, countryID string) (*model.User, error) + RemoveUserMonitoredCountry(ctx context.Context, userID string, countryID string) (*model.User, error) + RefreshCovidDataForAllCountries(ctx context.Context) (bool, error) +} +type QueryResolver interface { + Login(ctx context.Context, username string, password string) (*model.LoginResponse, error) + User(ctx context.Context, username *string, email *string) (*model.User, error) + Country(ctx context.Context, id string) (*model.Country, error) + Countries(ctx context.Context, first *int, after *string, filter *model.CountryFilterInput) (*model.CountriesConnection, error) + MonitoredCountries(ctx context.Context, userID string) ([]*model.Country, error) + CovidStatistics(ctx context.Context, countryID string, after *string, first *int) (*model.CovidStatisticConnection, error) + CovidStatistic(ctx context.Context, id string) (*model.CovidStatistic, error) + DeathPercentage(ctx context.Context, countryID string) (float64, error) + TopCountriesByCaseTypeForUser(ctx context.Context, caseType model.CaseType, limit int, userID string) ([]*model.Country, error) +} +type SubscriptionResolver interface { + CovidStatisticUpdated(ctx context.Context, countryIDs []string) (<-chan []*model.CovidStatistic, error) +} + +type executableSchema struct { + resolvers ResolverRoot + directives DirectiveRoot + complexity ComplexityRoot +} + +func (e *executableSchema) Schema() *ast.Schema { + return parsedSchema +} + +func (e *executableSchema) Complexity(typeName, field string, childComplexity int, rawArgs map[string]interface{}) (int, bool) { + ec := executionContext{nil, e} + _ = ec + switch typeName + "." + field { + + case "CountriesConnection.edges": + if e.complexity.CountriesConnection.Edges == nil { + break + } + + return e.complexity.CountriesConnection.Edges(childComplexity), true + + case "CountriesConnection.pageInfo": + if e.complexity.CountriesConnection.PageInfo == nil { + break + } + + return e.complexity.CountriesConnection.PageInfo(childComplexity), true + + case "Country.code": + if e.complexity.Country.Code == nil { + break + } + + return e.complexity.Country.Code(childComplexity), true + + case "Country.covidStats": + if e.complexity.Country.CovidStats == nil { + break + } + + args, err := ec.field_Country_covidStats_args(context.TODO(), rawArgs) + if err != nil { + return 0, false + } + + return e.complexity.Country.CovidStats(childComplexity, args["after"].(*string), args["first"].(*int)), true + + case "Country.id": + if e.complexity.Country.ID == nil { + break + } + + return e.complexity.Country.ID(childComplexity), true + + case "Country.name": + if e.complexity.Country.Name == nil { + break + } + + return e.complexity.Country.Name(childComplexity), true + + case "CountryEdge.cursor": + if e.complexity.CountryEdge.Cursor == nil { + break + } + + return e.complexity.CountryEdge.Cursor(childComplexity), true + + case "CountryEdge.node": + if e.complexity.CountryEdge.Node == nil { + break + } + + return e.complexity.CountryEdge.Node(childComplexity), true + + case "CovidStatistic.confirmed": + if e.complexity.CovidStatistic.Confirmed == nil { + break + } + + return e.complexity.CovidStatistic.Confirmed(childComplexity), true + + case "CovidStatistic.country": + if e.complexity.CovidStatistic.Country == nil { + break + } + + return e.complexity.CovidStatistic.Country(childComplexity), true + + case "CovidStatistic.date": + if e.complexity.CovidStatistic.Date == nil { + break + } + + return e.complexity.CovidStatistic.Date(childComplexity), true + + case "CovidStatistic.deaths": + if e.complexity.CovidStatistic.Deaths == nil { + break + } + + return e.complexity.CovidStatistic.Deaths(childComplexity), true + + case "CovidStatistic.id": + if e.complexity.CovidStatistic.ID == nil { + break + } + + return e.complexity.CovidStatistic.ID(childComplexity), true + + case "CovidStatistic.recovered": + if e.complexity.CovidStatistic.Recovered == nil { + break + } + + return e.complexity.CovidStatistic.Recovered(childComplexity), true + + case "CovidStatisticConnection.edges": + if e.complexity.CovidStatisticConnection.Edges == nil { + break + } + + return e.complexity.CovidStatisticConnection.Edges(childComplexity), true + + case "CovidStatisticConnection.pageInfo": + if e.complexity.CovidStatisticConnection.PageInfo == nil { + break + } + + return e.complexity.CovidStatisticConnection.PageInfo(childComplexity), true + + case "CovidStatisticEdge.cursor": + if e.complexity.CovidStatisticEdge.Cursor == nil { + break + } + + return e.complexity.CovidStatisticEdge.Cursor(childComplexity), true + + case "CovidStatisticEdge.node": + if e.complexity.CovidStatisticEdge.Node == nil { + break + } + + return e.complexity.CovidStatisticEdge.Node(childComplexity), true + + case "LoginResponse.token": + if e.complexity.LoginResponse.Token == nil { + break + } + + return e.complexity.LoginResponse.Token(childComplexity), true + + case "LoginResponse.user": + if e.complexity.LoginResponse.User == nil { + break + } + + return e.complexity.LoginResponse.User(childComplexity), true + + case "Mutation.addCountry": + if e.complexity.Mutation.AddCountry == nil { + break + } + + args, err := ec.field_Mutation_addCountry_args(context.TODO(), rawArgs) + if err != nil { + return 0, false + } + + return e.complexity.Mutation.AddCountry(childComplexity, args["input"].(model.CountryInput)), true + + case "Mutation.addCovidStatistic": + if e.complexity.Mutation.AddCovidStatistic == nil { + break + } + + args, err := ec.field_Mutation_addCovidStatistic_args(context.TODO(), rawArgs) + if err != nil { + return 0, false + } + + return e.complexity.Mutation.AddCovidStatistic(childComplexity, args["input"].(model.CovidStatisticInput)), true + + case "Mutation.addUserMonitoredCountry": + if e.complexity.Mutation.AddUserMonitoredCountry == nil { + break + } + + args, err := ec.field_Mutation_addUserMonitoredCountry_args(context.TODO(), rawArgs) + if err != nil { + return 0, false + } + + return e.complexity.Mutation.AddUserMonitoredCountry(childComplexity, args["userID"].(string), args["countryID"].(string)), true + + case "Mutation.deleteCountry": + if e.complexity.Mutation.DeleteCountry == nil { + break + } + + args, err := ec.field_Mutation_deleteCountry_args(context.TODO(), rawArgs) + if err != nil { + return 0, false + } + + return e.complexity.Mutation.DeleteCountry(childComplexity, args["countryID"].(string)), true + + case "Mutation.deleteCovidStatistic": + if e.complexity.Mutation.DeleteCovidStatistic == nil { + break + } + + args, err := ec.field_Mutation_deleteCovidStatistic_args(context.TODO(), rawArgs) + if err != nil { + return 0, false + } + + return e.complexity.Mutation.DeleteCovidStatistic(childComplexity, args["id"].(string)), true + + case "Mutation.deleteUser": + if e.complexity.Mutation.DeleteUser == nil { + break + } + + args, err := ec.field_Mutation_deleteUser_args(context.TODO(), rawArgs) + if err != nil { + return 0, false + } + + return e.complexity.Mutation.DeleteUser(childComplexity, args["userID"].(string)), true + + case "Mutation.refreshCovidDataForAllCountries": + if e.complexity.Mutation.RefreshCovidDataForAllCountries == nil { + break + } + + return e.complexity.Mutation.RefreshCovidDataForAllCountries(childComplexity), true + + case "Mutation.register": + if e.complexity.Mutation.Register == nil { + break + } + + args, err := ec.field_Mutation_register_args(context.TODO(), rawArgs) + if err != nil { + return 0, false + } + + return e.complexity.Mutation.Register(childComplexity, args["username"].(string), args["email"].(string), args["password"].(string)), true + + case "Mutation.removeUserMonitoredCountry": + if e.complexity.Mutation.RemoveUserMonitoredCountry == nil { + break + } + + args, err := ec.field_Mutation_removeUserMonitoredCountry_args(context.TODO(), rawArgs) + if err != nil { + return 0, false + } + + return e.complexity.Mutation.RemoveUserMonitoredCountry(childComplexity, args["userID"].(string), args["countryID"].(string)), true + + case "Mutation.updateCountry": + if e.complexity.Mutation.UpdateCountry == nil { + break + } + + args, err := ec.field_Mutation_updateCountry_args(context.TODO(), rawArgs) + if err != nil { + return 0, false + } + + return e.complexity.Mutation.UpdateCountry(childComplexity, args["id"].(string), args["name"].(string), args["code"].(string)), true + + case "Mutation.updateCovidStatistic": + if e.complexity.Mutation.UpdateCovidStatistic == nil { + break + } + + args, err := ec.field_Mutation_updateCovidStatistic_args(context.TODO(), rawArgs) + if err != nil { + return 0, false + } + + return e.complexity.Mutation.UpdateCovidStatistic(childComplexity, args["id"].(string), args["date"].(string), args["confirmed"].(int), args["recovered"].(int), args["deaths"].(int)), true + + case "PageInfo.endCursor": + if e.complexity.PageInfo.EndCursor == nil { + break + } + + return e.complexity.PageInfo.EndCursor(childComplexity), true + + case "PageInfo.hasNextPage": + if e.complexity.PageInfo.HasNextPage == nil { + break + } + + return e.complexity.PageInfo.HasNextPage(childComplexity), true + + case "Query.countries": + if e.complexity.Query.Countries == nil { + break + } + + args, err := ec.field_Query_countries_args(context.TODO(), rawArgs) + if err != nil { + return 0, false + } + + return e.complexity.Query.Countries(childComplexity, args["first"].(*int), args["after"].(*string), args["filter"].(*model.CountryFilterInput)), true + + case "Query.country": + if e.complexity.Query.Country == nil { + break + } + + args, err := ec.field_Query_country_args(context.TODO(), rawArgs) + if err != nil { + return 0, false + } + + return e.complexity.Query.Country(childComplexity, args["id"].(string)), true + + case "Query.covidStatistic": + if e.complexity.Query.CovidStatistic == nil { + break + } + + args, err := ec.field_Query_covidStatistic_args(context.TODO(), rawArgs) + if err != nil { + return 0, false + } + + return e.complexity.Query.CovidStatistic(childComplexity, args["id"].(string)), true + + case "Query.covidStatistics": + if e.complexity.Query.CovidStatistics == nil { + break + } + + args, err := ec.field_Query_covidStatistics_args(context.TODO(), rawArgs) + if err != nil { + return 0, false + } + + return e.complexity.Query.CovidStatistics(childComplexity, args["countryID"].(string), args["after"].(*string), args["first"].(*int)), true + + case "Query.deathPercentage": + if e.complexity.Query.DeathPercentage == nil { + break + } + + args, err := ec.field_Query_deathPercentage_args(context.TODO(), rawArgs) + if err != nil { + return 0, false + } + + return e.complexity.Query.DeathPercentage(childComplexity, args["countryID"].(string)), true + + case "Query.login": + if e.complexity.Query.Login == nil { + break + } + + args, err := ec.field_Query_login_args(context.TODO(), rawArgs) + if err != nil { + return 0, false + } + + return e.complexity.Query.Login(childComplexity, args["username"].(string), args["password"].(string)), true + + case "Query.monitoredCountries": + if e.complexity.Query.MonitoredCountries == nil { + break + } + + args, err := ec.field_Query_monitoredCountries_args(context.TODO(), rawArgs) + if err != nil { + return 0, false + } + + return e.complexity.Query.MonitoredCountries(childComplexity, args["userID"].(string)), true + + case "Query.topCountriesByCaseTypeForUser": + if e.complexity.Query.TopCountriesByCaseTypeForUser == nil { + break + } + + args, err := ec.field_Query_topCountriesByCaseTypeForUser_args(context.TODO(), rawArgs) + if err != nil { + return 0, false + } + + return e.complexity.Query.TopCountriesByCaseTypeForUser(childComplexity, args["caseType"].(model.CaseType), args["limit"].(int), args["userId"].(string)), true + + case "Query.user": + if e.complexity.Query.User == nil { + break + } + + args, err := ec.field_Query_user_args(context.TODO(), rawArgs) + if err != nil { + return 0, false + } + + return e.complexity.Query.User(childComplexity, args["username"].(*string), args["email"].(*string)), true + + case "Subscription.covidStatisticUpdated": + if e.complexity.Subscription.CovidStatisticUpdated == nil { + break + } + + args, err := ec.field_Subscription_covidStatisticUpdated_args(context.TODO(), rawArgs) + if err != nil { + return 0, false + } + + return e.complexity.Subscription.CovidStatisticUpdated(childComplexity, args["countryIDs"].([]string)), true + + case "User.email": + if e.complexity.User.Email == nil { + break + } + + return e.complexity.User.Email(childComplexity), true + + case "User.id": + if e.complexity.User.ID == nil { + break + } + + return e.complexity.User.ID(childComplexity), true + + case "User.monitoredCountries": + if e.complexity.User.MonitoredCountries == nil { + break + } + + return e.complexity.User.MonitoredCountries(childComplexity), true + + case "User.password": + if e.complexity.User.Password == nil { + break + } + + return e.complexity.User.Password(childComplexity), true + + case "User.username": + if e.complexity.User.Username == nil { + break + } + + return e.complexity.User.Username(childComplexity), true + + } + return 0, false +} + +func (e *executableSchema) Exec(ctx context.Context) graphql.ResponseHandler { + rc := graphql.GetOperationContext(ctx) + ec := executionContext{rc, e} + inputUnmarshalMap := graphql.BuildUnmarshalerMap( + ec.unmarshalInputCountryFilterInput, + ec.unmarshalInputCountryInput, + ec.unmarshalInputCovidStatisticInput, + ) + first := true + + switch rc.Operation.Operation { + case ast.Query: + return func(ctx context.Context) *graphql.Response { + if !first { + return nil + } + first = false + ctx = graphql.WithUnmarshalerMap(ctx, inputUnmarshalMap) + data := ec._Query(ctx, rc.Operation.SelectionSet) + var buf bytes.Buffer + data.MarshalGQL(&buf) + + return &graphql.Response{ + Data: buf.Bytes(), + } + } + case ast.Mutation: + return func(ctx context.Context) *graphql.Response { + if !first { + return nil + } + first = false + ctx = graphql.WithUnmarshalerMap(ctx, inputUnmarshalMap) + data := ec._Mutation(ctx, rc.Operation.SelectionSet) + var buf bytes.Buffer + data.MarshalGQL(&buf) + + return &graphql.Response{ + Data: buf.Bytes(), + } + } + case ast.Subscription: + next := ec._Subscription(ctx, rc.Operation.SelectionSet) + + var buf bytes.Buffer + return func(ctx context.Context) *graphql.Response { + buf.Reset() + data := next(ctx) + + if data == nil { + return nil + } + data.MarshalGQL(&buf) + + return &graphql.Response{ + Data: buf.Bytes(), + } + } + + default: + return graphql.OneShot(graphql.ErrorResponse(ctx, "unsupported GraphQL operation")) + } +} + +type executionContext struct { + *graphql.OperationContext + *executableSchema +} + +func (ec *executionContext) introspectSchema() (*introspection.Schema, error) { + if ec.DisableIntrospection { + return nil, errors.New("introspection disabled") + } + return introspection.WrapSchema(parsedSchema), nil +} + +func (ec *executionContext) introspectType(name string) (*introspection.Type, error) { + if ec.DisableIntrospection { + return nil, errors.New("introspection disabled") + } + return introspection.WrapTypeFromDef(parsedSchema, parsedSchema.Types[name]), nil +} + +//go:embed "schema.graphqls" +var sourcesFS embed.FS + +func sourceData(filename string) string { + data, err := sourcesFS.ReadFile(filename) + if err != nil { + panic(fmt.Sprintf("codegen problem: %s not available", filename)) + } + return string(data) +} + +var sources = []*ast.Source{ + {Name: "schema.graphqls", Input: sourceData("schema.graphqls"), BuiltIn: false}, +} +var parsedSchema = gqlparser.MustLoadSchema(sources...) + +// endregion ************************** generated!.gotpl ************************** + +// region ***************************** args.gotpl ***************************** + +func (ec *executionContext) field_Country_covidStats_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 *string + if tmp, ok := rawArgs["after"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("after")) + arg0, err = ec.unmarshalOString2ᚖstring(ctx, tmp) + if err != nil { + return nil, err + } + } + args["after"] = arg0 + var arg1 *int + if tmp, ok := rawArgs["first"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("first")) + arg1, err = ec.unmarshalOInt2ᚖint(ctx, tmp) + if err != nil { + return nil, err + } + } + args["first"] = arg1 + return args, nil +} + +func (ec *executionContext) field_Mutation_addCountry_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 model.CountryInput + if tmp, ok := rawArgs["input"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("input")) + arg0, err = ec.unmarshalNCountryInput2covidᚋgraphᚋmodelᚐCountryInput(ctx, tmp) + if err != nil { + return nil, err + } + } + args["input"] = arg0 + return args, nil +} + +func (ec *executionContext) field_Mutation_addCovidStatistic_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 model.CovidStatisticInput + if tmp, ok := rawArgs["input"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("input")) + arg0, err = ec.unmarshalNCovidStatisticInput2covidᚋgraphᚋmodelᚐCovidStatisticInput(ctx, tmp) + if err != nil { + return nil, err + } + } + args["input"] = arg0 + return args, nil +} + +func (ec *executionContext) field_Mutation_addUserMonitoredCountry_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 string + if tmp, ok := rawArgs["userID"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("userID")) + arg0, err = ec.unmarshalNID2string(ctx, tmp) + if err != nil { + return nil, err + } + } + args["userID"] = arg0 + var arg1 string + if tmp, ok := rawArgs["countryID"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("countryID")) + arg1, err = ec.unmarshalNID2string(ctx, tmp) + if err != nil { + return nil, err + } + } + args["countryID"] = arg1 + return args, nil +} + +func (ec *executionContext) field_Mutation_deleteCountry_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 string + if tmp, ok := rawArgs["countryID"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("countryID")) + arg0, err = ec.unmarshalNID2string(ctx, tmp) + if err != nil { + return nil, err + } + } + args["countryID"] = arg0 + return args, nil +} + +func (ec *executionContext) field_Mutation_deleteCovidStatistic_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 string + if tmp, ok := rawArgs["id"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("id")) + arg0, err = ec.unmarshalNID2string(ctx, tmp) + if err != nil { + return nil, err + } + } + args["id"] = arg0 + return args, nil +} + +func (ec *executionContext) field_Mutation_deleteUser_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 string + if tmp, ok := rawArgs["userID"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("userID")) + arg0, err = ec.unmarshalNID2string(ctx, tmp) + if err != nil { + return nil, err + } + } + args["userID"] = arg0 + return args, nil +} + +func (ec *executionContext) field_Mutation_register_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 string + if tmp, ok := rawArgs["username"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("username")) + arg0, err = ec.unmarshalNString2string(ctx, tmp) + if err != nil { + return nil, err + } + } + args["username"] = arg0 + var arg1 string + if tmp, ok := rawArgs["email"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("email")) + arg1, err = ec.unmarshalNString2string(ctx, tmp) + if err != nil { + return nil, err + } + } + args["email"] = arg1 + var arg2 string + if tmp, ok := rawArgs["password"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("password")) + arg2, err = ec.unmarshalNString2string(ctx, tmp) + if err != nil { + return nil, err + } + } + args["password"] = arg2 + return args, nil +} + +func (ec *executionContext) field_Mutation_removeUserMonitoredCountry_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 string + if tmp, ok := rawArgs["userID"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("userID")) + arg0, err = ec.unmarshalNID2string(ctx, tmp) + if err != nil { + return nil, err + } + } + args["userID"] = arg0 + var arg1 string + if tmp, ok := rawArgs["countryID"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("countryID")) + arg1, err = ec.unmarshalNID2string(ctx, tmp) + if err != nil { + return nil, err + } + } + args["countryID"] = arg1 + return args, nil +} + +func (ec *executionContext) field_Mutation_updateCountry_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 string + if tmp, ok := rawArgs["id"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("id")) + arg0, err = ec.unmarshalNID2string(ctx, tmp) + if err != nil { + return nil, err + } + } + args["id"] = arg0 + var arg1 string + if tmp, ok := rawArgs["name"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("name")) + arg1, err = ec.unmarshalNString2string(ctx, tmp) + if err != nil { + return nil, err + } + } + args["name"] = arg1 + var arg2 string + if tmp, ok := rawArgs["code"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("code")) + arg2, err = ec.unmarshalNString2string(ctx, tmp) + if err != nil { + return nil, err + } + } + args["code"] = arg2 + return args, nil +} + +func (ec *executionContext) field_Mutation_updateCovidStatistic_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 string + if tmp, ok := rawArgs["id"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("id")) + arg0, err = ec.unmarshalNID2string(ctx, tmp) + if err != nil { + return nil, err + } + } + args["id"] = arg0 + var arg1 string + if tmp, ok := rawArgs["date"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("date")) + arg1, err = ec.unmarshalNString2string(ctx, tmp) + if err != nil { + return nil, err + } + } + args["date"] = arg1 + var arg2 int + if tmp, ok := rawArgs["confirmed"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("confirmed")) + arg2, err = ec.unmarshalNInt2int(ctx, tmp) + if err != nil { + return nil, err + } + } + args["confirmed"] = arg2 + var arg3 int + if tmp, ok := rawArgs["recovered"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("recovered")) + arg3, err = ec.unmarshalNInt2int(ctx, tmp) + if err != nil { + return nil, err + } + } + args["recovered"] = arg3 + var arg4 int + if tmp, ok := rawArgs["deaths"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("deaths")) + arg4, err = ec.unmarshalNInt2int(ctx, tmp) + if err != nil { + return nil, err + } + } + args["deaths"] = arg4 + return args, nil +} + +func (ec *executionContext) field_Query___type_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 string + if tmp, ok := rawArgs["name"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("name")) + arg0, err = ec.unmarshalNString2string(ctx, tmp) + if err != nil { + return nil, err + } + } + args["name"] = arg0 + return args, nil +} + +func (ec *executionContext) field_Query_countries_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 *int + if tmp, ok := rawArgs["first"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("first")) + arg0, err = ec.unmarshalOInt2ᚖint(ctx, tmp) + if err != nil { + return nil, err + } + } + args["first"] = arg0 + var arg1 *string + if tmp, ok := rawArgs["after"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("after")) + arg1, err = ec.unmarshalOString2ᚖstring(ctx, tmp) + if err != nil { + return nil, err + } + } + args["after"] = arg1 + var arg2 *model.CountryFilterInput + if tmp, ok := rawArgs["filter"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("filter")) + arg2, err = ec.unmarshalOCountryFilterInput2ᚖcovidᚋgraphᚋmodelᚐCountryFilterInput(ctx, tmp) + if err != nil { + return nil, err + } + } + args["filter"] = arg2 + return args, nil +} + +func (ec *executionContext) field_Query_country_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 string + if tmp, ok := rawArgs["id"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("id")) + arg0, err = ec.unmarshalNID2string(ctx, tmp) + if err != nil { + return nil, err + } + } + args["id"] = arg0 + return args, nil +} + +func (ec *executionContext) field_Query_covidStatistic_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 string + if tmp, ok := rawArgs["id"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("id")) + arg0, err = ec.unmarshalNID2string(ctx, tmp) + if err != nil { + return nil, err + } + } + args["id"] = arg0 + return args, nil +} + +func (ec *executionContext) field_Query_covidStatistics_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 string + if tmp, ok := rawArgs["countryID"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("countryID")) + arg0, err = ec.unmarshalNID2string(ctx, tmp) + if err != nil { + return nil, err + } + } + args["countryID"] = arg0 + var arg1 *string + if tmp, ok := rawArgs["after"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("after")) + arg1, err = ec.unmarshalOString2ᚖstring(ctx, tmp) + if err != nil { + return nil, err + } + } + args["after"] = arg1 + var arg2 *int + if tmp, ok := rawArgs["first"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("first")) + arg2, err = ec.unmarshalOInt2ᚖint(ctx, tmp) + if err != nil { + return nil, err + } + } + args["first"] = arg2 + return args, nil +} + +func (ec *executionContext) field_Query_deathPercentage_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 string + if tmp, ok := rawArgs["countryID"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("countryID")) + arg0, err = ec.unmarshalNID2string(ctx, tmp) + if err != nil { + return nil, err + } + } + args["countryID"] = arg0 + return args, nil +} + +func (ec *executionContext) field_Query_login_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 string + if tmp, ok := rawArgs["username"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("username")) + arg0, err = ec.unmarshalNString2string(ctx, tmp) + if err != nil { + return nil, err + } + } + args["username"] = arg0 + var arg1 string + if tmp, ok := rawArgs["password"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("password")) + arg1, err = ec.unmarshalNString2string(ctx, tmp) + if err != nil { + return nil, err + } + } + args["password"] = arg1 + return args, nil +} + +func (ec *executionContext) field_Query_monitoredCountries_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 string + if tmp, ok := rawArgs["userID"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("userID")) + arg0, err = ec.unmarshalNID2string(ctx, tmp) + if err != nil { + return nil, err + } + } + args["userID"] = arg0 + return args, nil +} + +func (ec *executionContext) field_Query_topCountriesByCaseTypeForUser_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 model.CaseType + if tmp, ok := rawArgs["caseType"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("caseType")) + arg0, err = ec.unmarshalNCaseType2covidᚋgraphᚋmodelᚐCaseType(ctx, tmp) + if err != nil { + return nil, err + } + } + args["caseType"] = arg0 + var arg1 int + if tmp, ok := rawArgs["limit"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("limit")) + arg1, err = ec.unmarshalNInt2int(ctx, tmp) + if err != nil { + return nil, err + } + } + args["limit"] = arg1 + var arg2 string + if tmp, ok := rawArgs["userId"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("userId")) + arg2, err = ec.unmarshalNID2string(ctx, tmp) + if err != nil { + return nil, err + } + } + args["userId"] = arg2 + return args, nil +} + +func (ec *executionContext) field_Query_user_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 *string + if tmp, ok := rawArgs["username"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("username")) + arg0, err = ec.unmarshalOString2ᚖstring(ctx, tmp) + if err != nil { + return nil, err + } + } + args["username"] = arg0 + var arg1 *string + if tmp, ok := rawArgs["email"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("email")) + arg1, err = ec.unmarshalOString2ᚖstring(ctx, tmp) + if err != nil { + return nil, err + } + } + args["email"] = arg1 + return args, nil +} + +func (ec *executionContext) field_Subscription_covidStatisticUpdated_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 []string + if tmp, ok := rawArgs["countryIDs"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("countryIDs")) + arg0, err = ec.unmarshalNID2ᚕstringᚄ(ctx, tmp) + if err != nil { + return nil, err + } + } + args["countryIDs"] = arg0 + return args, nil +} + +func (ec *executionContext) field___Type_enumValues_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 bool + if tmp, ok := rawArgs["includeDeprecated"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("includeDeprecated")) + arg0, err = ec.unmarshalOBoolean2bool(ctx, tmp) + if err != nil { + return nil, err + } + } + args["includeDeprecated"] = arg0 + return args, nil +} + +func (ec *executionContext) field___Type_fields_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 bool + if tmp, ok := rawArgs["includeDeprecated"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("includeDeprecated")) + arg0, err = ec.unmarshalOBoolean2bool(ctx, tmp) + if err != nil { + return nil, err + } + } + args["includeDeprecated"] = arg0 + return args, nil +} + +// endregion ***************************** args.gotpl ***************************** + +// region ************************** directives.gotpl ************************** + +// endregion ************************** directives.gotpl ************************** + +// region **************************** field.gotpl ***************************** + +func (ec *executionContext) _CountriesConnection_pageInfo(ctx context.Context, field graphql.CollectedField, obj *model.CountriesConnection) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_CountriesConnection_pageInfo(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.PageInfo, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(*model.PageInfo) + fc.Result = res + return ec.marshalNPageInfo2ᚖcovidᚋgraphᚋmodelᚐPageInfo(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_CountriesConnection_pageInfo(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "CountriesConnection", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "endCursor": + return ec.fieldContext_PageInfo_endCursor(ctx, field) + case "hasNextPage": + return ec.fieldContext_PageInfo_hasNextPage(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type PageInfo", field.Name) + }, + } + return fc, nil +} + +func (ec *executionContext) _CountriesConnection_edges(ctx context.Context, field graphql.CollectedField, obj *model.CountriesConnection) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_CountriesConnection_edges(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Edges, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.([]*model.CountryEdge) + fc.Result = res + return ec.marshalNCountryEdge2ᚕᚖcovidᚋgraphᚋmodelᚐCountryEdgeᚄ(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_CountriesConnection_edges(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "CountriesConnection", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "cursor": + return ec.fieldContext_CountryEdge_cursor(ctx, field) + case "node": + return ec.fieldContext_CountryEdge_node(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type CountryEdge", field.Name) + }, + } + return fc, nil +} + +func (ec *executionContext) _Country_id(ctx context.Context, field graphql.CollectedField, obj *model.Country) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Country_id(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.ID, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + fc.Result = res + return ec.marshalNID2string(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_Country_id(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Country", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type ID does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) _Country_name(ctx context.Context, field graphql.CollectedField, obj *model.Country) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Country_name(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Name, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + fc.Result = res + return ec.marshalNString2string(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_Country_name(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Country", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type String does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) _Country_code(ctx context.Context, field graphql.CollectedField, obj *model.Country) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Country_code(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Code, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + fc.Result = res + return ec.marshalNString2string(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_Country_code(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Country", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type String does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) _Country_covidStats(ctx context.Context, field graphql.CollectedField, obj *model.Country) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Country_covidStats(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.CovidStats, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*model.CovidStatisticConnection) + fc.Result = res + return ec.marshalOCovidStatisticConnection2ᚖcovidᚋgraphᚋmodelᚐCovidStatisticConnection(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_Country_covidStats(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Country", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "pageInfo": + return ec.fieldContext_CovidStatisticConnection_pageInfo(ctx, field) + case "edges": + return ec.fieldContext_CovidStatisticConnection_edges(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type CovidStatisticConnection", field.Name) + }, + } + defer func() { + if r := recover(); r != nil { + err = ec.Recover(ctx, r) + ec.Error(ctx, err) + } + }() + ctx = graphql.WithFieldContext(ctx, fc) + if fc.Args, err = ec.field_Country_covidStats_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { + ec.Error(ctx, err) + return + } + return fc, nil +} + +func (ec *executionContext) _CountryEdge_cursor(ctx context.Context, field graphql.CollectedField, obj *model.CountryEdge) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_CountryEdge_cursor(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Cursor, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + fc.Result = res + return ec.marshalNString2string(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_CountryEdge_cursor(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "CountryEdge", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type String does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) _CountryEdge_node(ctx context.Context, field graphql.CollectedField, obj *model.CountryEdge) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_CountryEdge_node(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Node, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(*model.Country) + fc.Result = res + return ec.marshalNCountry2ᚖcovidᚋgraphᚋmodelᚐCountry(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_CountryEdge_node(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "CountryEdge", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "id": + return ec.fieldContext_Country_id(ctx, field) + case "name": + return ec.fieldContext_Country_name(ctx, field) + case "code": + return ec.fieldContext_Country_code(ctx, field) + case "covidStats": + return ec.fieldContext_Country_covidStats(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type Country", field.Name) + }, + } + return fc, nil +} + +func (ec *executionContext) _CovidStatistic_id(ctx context.Context, field graphql.CollectedField, obj *model.CovidStatistic) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_CovidStatistic_id(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.ID, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + fc.Result = res + return ec.marshalNID2string(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_CovidStatistic_id(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "CovidStatistic", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type ID does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) _CovidStatistic_country(ctx context.Context, field graphql.CollectedField, obj *model.CovidStatistic) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_CovidStatistic_country(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Country, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(*model.Country) + fc.Result = res + return ec.marshalNCountry2ᚖcovidᚋgraphᚋmodelᚐCountry(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_CovidStatistic_country(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "CovidStatistic", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "id": + return ec.fieldContext_Country_id(ctx, field) + case "name": + return ec.fieldContext_Country_name(ctx, field) + case "code": + return ec.fieldContext_Country_code(ctx, field) + case "covidStats": + return ec.fieldContext_Country_covidStats(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type Country", field.Name) + }, + } + return fc, nil +} + +func (ec *executionContext) _CovidStatistic_date(ctx context.Context, field graphql.CollectedField, obj *model.CovidStatistic) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_CovidStatistic_date(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Date, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + fc.Result = res + return ec.marshalNString2string(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_CovidStatistic_date(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "CovidStatistic", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type String does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) _CovidStatistic_confirmed(ctx context.Context, field graphql.CollectedField, obj *model.CovidStatistic) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_CovidStatistic_confirmed(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Confirmed, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(int) + fc.Result = res + return ec.marshalNInt2int(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_CovidStatistic_confirmed(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "CovidStatistic", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type Int does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) _CovidStatistic_recovered(ctx context.Context, field graphql.CollectedField, obj *model.CovidStatistic) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_CovidStatistic_recovered(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Recovered, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(int) + fc.Result = res + return ec.marshalNInt2int(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_CovidStatistic_recovered(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "CovidStatistic", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type Int does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) _CovidStatistic_deaths(ctx context.Context, field graphql.CollectedField, obj *model.CovidStatistic) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_CovidStatistic_deaths(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Deaths, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(int) + fc.Result = res + return ec.marshalNInt2int(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_CovidStatistic_deaths(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "CovidStatistic", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type Int does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) _CovidStatisticConnection_pageInfo(ctx context.Context, field graphql.CollectedField, obj *model.CovidStatisticConnection) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_CovidStatisticConnection_pageInfo(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.PageInfo, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(*model.PageInfo) + fc.Result = res + return ec.marshalNPageInfo2ᚖcovidᚋgraphᚋmodelᚐPageInfo(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_CovidStatisticConnection_pageInfo(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "CovidStatisticConnection", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "endCursor": + return ec.fieldContext_PageInfo_endCursor(ctx, field) + case "hasNextPage": + return ec.fieldContext_PageInfo_hasNextPage(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type PageInfo", field.Name) + }, + } + return fc, nil +} + +func (ec *executionContext) _CovidStatisticConnection_edges(ctx context.Context, field graphql.CollectedField, obj *model.CovidStatisticConnection) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_CovidStatisticConnection_edges(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Edges, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.([]*model.CovidStatisticEdge) + fc.Result = res + return ec.marshalNCovidStatisticEdge2ᚕᚖcovidᚋgraphᚋmodelᚐCovidStatisticEdgeᚄ(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_CovidStatisticConnection_edges(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "CovidStatisticConnection", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "cursor": + return ec.fieldContext_CovidStatisticEdge_cursor(ctx, field) + case "node": + return ec.fieldContext_CovidStatisticEdge_node(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type CovidStatisticEdge", field.Name) + }, + } + return fc, nil +} + +func (ec *executionContext) _CovidStatisticEdge_cursor(ctx context.Context, field graphql.CollectedField, obj *model.CovidStatisticEdge) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_CovidStatisticEdge_cursor(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Cursor, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + fc.Result = res + return ec.marshalNString2string(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_CovidStatisticEdge_cursor(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "CovidStatisticEdge", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type String does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) _CovidStatisticEdge_node(ctx context.Context, field graphql.CollectedField, obj *model.CovidStatisticEdge) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_CovidStatisticEdge_node(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Node, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(*model.CovidStatistic) + fc.Result = res + return ec.marshalNCovidStatistic2ᚖcovidᚋgraphᚋmodelᚐCovidStatistic(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_CovidStatisticEdge_node(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "CovidStatisticEdge", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "id": + return ec.fieldContext_CovidStatistic_id(ctx, field) + case "country": + return ec.fieldContext_CovidStatistic_country(ctx, field) + case "date": + return ec.fieldContext_CovidStatistic_date(ctx, field) + case "confirmed": + return ec.fieldContext_CovidStatistic_confirmed(ctx, field) + case "recovered": + return ec.fieldContext_CovidStatistic_recovered(ctx, field) + case "deaths": + return ec.fieldContext_CovidStatistic_deaths(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type CovidStatistic", field.Name) + }, + } + return fc, nil +} + +func (ec *executionContext) _LoginResponse_token(ctx context.Context, field graphql.CollectedField, obj *model.LoginResponse) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_LoginResponse_token(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Token, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + fc.Result = res + return ec.marshalNString2string(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_LoginResponse_token(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "LoginResponse", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type String does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) _LoginResponse_user(ctx context.Context, field graphql.CollectedField, obj *model.LoginResponse) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_LoginResponse_user(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.User, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(*model.User) + fc.Result = res + return ec.marshalNUser2ᚖcovidᚋgraphᚋmodelᚐUser(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_LoginResponse_user(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "LoginResponse", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "id": + return ec.fieldContext_User_id(ctx, field) + case "username": + return ec.fieldContext_User_username(ctx, field) + case "email": + return ec.fieldContext_User_email(ctx, field) + case "password": + return ec.fieldContext_User_password(ctx, field) + case "monitoredCountries": + return ec.fieldContext_User_monitoredCountries(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type User", field.Name) + }, + } + return fc, nil +} + +func (ec *executionContext) _Mutation_register(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Mutation_register(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Mutation().Register(rctx, fc.Args["username"].(string), fc.Args["email"].(string), fc.Args["password"].(string)) + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(*model.LoginResponse) + fc.Result = res + return ec.marshalNLoginResponse2ᚖcovidᚋgraphᚋmodelᚐLoginResponse(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_Mutation_register(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Mutation", + Field: field, + IsMethod: true, + IsResolver: true, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "token": + return ec.fieldContext_LoginResponse_token(ctx, field) + case "user": + return ec.fieldContext_LoginResponse_user(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type LoginResponse", field.Name) + }, + } + defer func() { + if r := recover(); r != nil { + err = ec.Recover(ctx, r) + ec.Error(ctx, err) + } + }() + ctx = graphql.WithFieldContext(ctx, fc) + if fc.Args, err = ec.field_Mutation_register_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { + ec.Error(ctx, err) + return + } + return fc, nil +} + +func (ec *executionContext) _Mutation_deleteUser(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Mutation_deleteUser(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Mutation().DeleteUser(rctx, fc.Args["userID"].(string)) + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(bool) + fc.Result = res + return ec.marshalNBoolean2bool(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_Mutation_deleteUser(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Mutation", + Field: field, + IsMethod: true, + IsResolver: true, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type Boolean does not have child fields") + }, + } + defer func() { + if r := recover(); r != nil { + err = ec.Recover(ctx, r) + ec.Error(ctx, err) + } + }() + ctx = graphql.WithFieldContext(ctx, fc) + if fc.Args, err = ec.field_Mutation_deleteUser_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { + ec.Error(ctx, err) + return + } + return fc, nil +} + +func (ec *executionContext) _Mutation_addCountry(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Mutation_addCountry(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Mutation().AddCountry(rctx, fc.Args["input"].(model.CountryInput)) + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(*model.Country) + fc.Result = res + return ec.marshalNCountry2ᚖcovidᚋgraphᚋmodelᚐCountry(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_Mutation_addCountry(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Mutation", + Field: field, + IsMethod: true, + IsResolver: true, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "id": + return ec.fieldContext_Country_id(ctx, field) + case "name": + return ec.fieldContext_Country_name(ctx, field) + case "code": + return ec.fieldContext_Country_code(ctx, field) + case "covidStats": + return ec.fieldContext_Country_covidStats(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type Country", field.Name) + }, + } + defer func() { + if r := recover(); r != nil { + err = ec.Recover(ctx, r) + ec.Error(ctx, err) + } + }() + ctx = graphql.WithFieldContext(ctx, fc) + if fc.Args, err = ec.field_Mutation_addCountry_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { + ec.Error(ctx, err) + return + } + return fc, nil +} + +func (ec *executionContext) _Mutation_updateCountry(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Mutation_updateCountry(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Mutation().UpdateCountry(rctx, fc.Args["id"].(string), fc.Args["name"].(string), fc.Args["code"].(string)) + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(*model.Country) + fc.Result = res + return ec.marshalNCountry2ᚖcovidᚋgraphᚋmodelᚐCountry(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_Mutation_updateCountry(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Mutation", + Field: field, + IsMethod: true, + IsResolver: true, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "id": + return ec.fieldContext_Country_id(ctx, field) + case "name": + return ec.fieldContext_Country_name(ctx, field) + case "code": + return ec.fieldContext_Country_code(ctx, field) + case "covidStats": + return ec.fieldContext_Country_covidStats(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type Country", field.Name) + }, + } + defer func() { + if r := recover(); r != nil { + err = ec.Recover(ctx, r) + ec.Error(ctx, err) + } + }() + ctx = graphql.WithFieldContext(ctx, fc) + if fc.Args, err = ec.field_Mutation_updateCountry_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { + ec.Error(ctx, err) + return + } + return fc, nil +} + +func (ec *executionContext) _Mutation_deleteCountry(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Mutation_deleteCountry(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Mutation().DeleteCountry(rctx, fc.Args["countryID"].(string)) + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(bool) + fc.Result = res + return ec.marshalNBoolean2bool(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_Mutation_deleteCountry(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Mutation", + Field: field, + IsMethod: true, + IsResolver: true, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type Boolean does not have child fields") + }, + } + defer func() { + if r := recover(); r != nil { + err = ec.Recover(ctx, r) + ec.Error(ctx, err) + } + }() + ctx = graphql.WithFieldContext(ctx, fc) + if fc.Args, err = ec.field_Mutation_deleteCountry_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { + ec.Error(ctx, err) + return + } + return fc, nil +} + +func (ec *executionContext) _Mutation_addCovidStatistic(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Mutation_addCovidStatistic(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Mutation().AddCovidStatistic(rctx, fc.Args["input"].(model.CovidStatisticInput)) + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(*model.CovidStatistic) + fc.Result = res + return ec.marshalNCovidStatistic2ᚖcovidᚋgraphᚋmodelᚐCovidStatistic(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_Mutation_addCovidStatistic(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Mutation", + Field: field, + IsMethod: true, + IsResolver: true, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "id": + return ec.fieldContext_CovidStatistic_id(ctx, field) + case "country": + return ec.fieldContext_CovidStatistic_country(ctx, field) + case "date": + return ec.fieldContext_CovidStatistic_date(ctx, field) + case "confirmed": + return ec.fieldContext_CovidStatistic_confirmed(ctx, field) + case "recovered": + return ec.fieldContext_CovidStatistic_recovered(ctx, field) + case "deaths": + return ec.fieldContext_CovidStatistic_deaths(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type CovidStatistic", field.Name) + }, + } + defer func() { + if r := recover(); r != nil { + err = ec.Recover(ctx, r) + ec.Error(ctx, err) + } + }() + ctx = graphql.WithFieldContext(ctx, fc) + if fc.Args, err = ec.field_Mutation_addCovidStatistic_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { + ec.Error(ctx, err) + return + } + return fc, nil +} + +func (ec *executionContext) _Mutation_deleteCovidStatistic(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Mutation_deleteCovidStatistic(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Mutation().DeleteCovidStatistic(rctx, fc.Args["id"].(string)) + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(bool) + fc.Result = res + return ec.marshalNBoolean2bool(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_Mutation_deleteCovidStatistic(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Mutation", + Field: field, + IsMethod: true, + IsResolver: true, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type Boolean does not have child fields") + }, + } + defer func() { + if r := recover(); r != nil { + err = ec.Recover(ctx, r) + ec.Error(ctx, err) + } + }() + ctx = graphql.WithFieldContext(ctx, fc) + if fc.Args, err = ec.field_Mutation_deleteCovidStatistic_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { + ec.Error(ctx, err) + return + } + return fc, nil +} + +func (ec *executionContext) _Mutation_updateCovidStatistic(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Mutation_updateCovidStatistic(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Mutation().UpdateCovidStatistic(rctx, fc.Args["id"].(string), fc.Args["date"].(string), fc.Args["confirmed"].(int), fc.Args["recovered"].(int), fc.Args["deaths"].(int)) + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(*model.CovidStatistic) + fc.Result = res + return ec.marshalNCovidStatistic2ᚖcovidᚋgraphᚋmodelᚐCovidStatistic(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_Mutation_updateCovidStatistic(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Mutation", + Field: field, + IsMethod: true, + IsResolver: true, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "id": + return ec.fieldContext_CovidStatistic_id(ctx, field) + case "country": + return ec.fieldContext_CovidStatistic_country(ctx, field) + case "date": + return ec.fieldContext_CovidStatistic_date(ctx, field) + case "confirmed": + return ec.fieldContext_CovidStatistic_confirmed(ctx, field) + case "recovered": + return ec.fieldContext_CovidStatistic_recovered(ctx, field) + case "deaths": + return ec.fieldContext_CovidStatistic_deaths(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type CovidStatistic", field.Name) + }, + } + defer func() { + if r := recover(); r != nil { + err = ec.Recover(ctx, r) + ec.Error(ctx, err) + } + }() + ctx = graphql.WithFieldContext(ctx, fc) + if fc.Args, err = ec.field_Mutation_updateCovidStatistic_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { + ec.Error(ctx, err) + return + } + return fc, nil +} + +func (ec *executionContext) _Mutation_addUserMonitoredCountry(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Mutation_addUserMonitoredCountry(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Mutation().AddUserMonitoredCountry(rctx, fc.Args["userID"].(string), fc.Args["countryID"].(string)) + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(*model.User) + fc.Result = res + return ec.marshalNUser2ᚖcovidᚋgraphᚋmodelᚐUser(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_Mutation_addUserMonitoredCountry(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Mutation", + Field: field, + IsMethod: true, + IsResolver: true, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "id": + return ec.fieldContext_User_id(ctx, field) + case "username": + return ec.fieldContext_User_username(ctx, field) + case "email": + return ec.fieldContext_User_email(ctx, field) + case "password": + return ec.fieldContext_User_password(ctx, field) + case "monitoredCountries": + return ec.fieldContext_User_monitoredCountries(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type User", field.Name) + }, + } + defer func() { + if r := recover(); r != nil { + err = ec.Recover(ctx, r) + ec.Error(ctx, err) + } + }() + ctx = graphql.WithFieldContext(ctx, fc) + if fc.Args, err = ec.field_Mutation_addUserMonitoredCountry_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { + ec.Error(ctx, err) + return + } + return fc, nil +} + +func (ec *executionContext) _Mutation_removeUserMonitoredCountry(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Mutation_removeUserMonitoredCountry(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Mutation().RemoveUserMonitoredCountry(rctx, fc.Args["userID"].(string), fc.Args["countryID"].(string)) + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(*model.User) + fc.Result = res + return ec.marshalNUser2ᚖcovidᚋgraphᚋmodelᚐUser(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_Mutation_removeUserMonitoredCountry(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Mutation", + Field: field, + IsMethod: true, + IsResolver: true, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "id": + return ec.fieldContext_User_id(ctx, field) + case "username": + return ec.fieldContext_User_username(ctx, field) + case "email": + return ec.fieldContext_User_email(ctx, field) + case "password": + return ec.fieldContext_User_password(ctx, field) + case "monitoredCountries": + return ec.fieldContext_User_monitoredCountries(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type User", field.Name) + }, + } + defer func() { + if r := recover(); r != nil { + err = ec.Recover(ctx, r) + ec.Error(ctx, err) + } + }() + ctx = graphql.WithFieldContext(ctx, fc) + if fc.Args, err = ec.field_Mutation_removeUserMonitoredCountry_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { + ec.Error(ctx, err) + return + } + return fc, nil +} + +func (ec *executionContext) _Mutation_refreshCovidDataForAllCountries(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Mutation_refreshCovidDataForAllCountries(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Mutation().RefreshCovidDataForAllCountries(rctx) + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(bool) + fc.Result = res + return ec.marshalNBoolean2bool(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_Mutation_refreshCovidDataForAllCountries(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Mutation", + Field: field, + IsMethod: true, + IsResolver: true, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type Boolean does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) _PageInfo_endCursor(ctx context.Context, field graphql.CollectedField, obj *model.PageInfo) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_PageInfo_endCursor(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.EndCursor, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*string) + fc.Result = res + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_PageInfo_endCursor(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "PageInfo", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type String does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) _PageInfo_hasNextPage(ctx context.Context, field graphql.CollectedField, obj *model.PageInfo) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_PageInfo_hasNextPage(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.HasNextPage, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(bool) + fc.Result = res + return ec.marshalNBoolean2bool(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_PageInfo_hasNextPage(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "PageInfo", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type Boolean does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) _Query_login(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Query_login(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Query().Login(rctx, fc.Args["username"].(string), fc.Args["password"].(string)) + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(*model.LoginResponse) + fc.Result = res + return ec.marshalNLoginResponse2ᚖcovidᚋgraphᚋmodelᚐLoginResponse(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_Query_login(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Query", + Field: field, + IsMethod: true, + IsResolver: true, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "token": + return ec.fieldContext_LoginResponse_token(ctx, field) + case "user": + return ec.fieldContext_LoginResponse_user(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type LoginResponse", field.Name) + }, + } + defer func() { + if r := recover(); r != nil { + err = ec.Recover(ctx, r) + ec.Error(ctx, err) + } + }() + ctx = graphql.WithFieldContext(ctx, fc) + if fc.Args, err = ec.field_Query_login_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { + ec.Error(ctx, err) + return + } + return fc, nil +} + +func (ec *executionContext) _Query_user(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Query_user(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Query().User(rctx, fc.Args["username"].(*string), fc.Args["email"].(*string)) + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*model.User) + fc.Result = res + return ec.marshalOUser2ᚖcovidᚋgraphᚋmodelᚐUser(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_Query_user(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Query", + Field: field, + IsMethod: true, + IsResolver: true, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "id": + return ec.fieldContext_User_id(ctx, field) + case "username": + return ec.fieldContext_User_username(ctx, field) + case "email": + return ec.fieldContext_User_email(ctx, field) + case "password": + return ec.fieldContext_User_password(ctx, field) + case "monitoredCountries": + return ec.fieldContext_User_monitoredCountries(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type User", field.Name) + }, + } + defer func() { + if r := recover(); r != nil { + err = ec.Recover(ctx, r) + ec.Error(ctx, err) + } + }() + ctx = graphql.WithFieldContext(ctx, fc) + if fc.Args, err = ec.field_Query_user_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { + ec.Error(ctx, err) + return + } + return fc, nil +} + +func (ec *executionContext) _Query_country(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Query_country(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Query().Country(rctx, fc.Args["id"].(string)) + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*model.Country) + fc.Result = res + return ec.marshalOCountry2ᚖcovidᚋgraphᚋmodelᚐCountry(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_Query_country(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Query", + Field: field, + IsMethod: true, + IsResolver: true, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "id": + return ec.fieldContext_Country_id(ctx, field) + case "name": + return ec.fieldContext_Country_name(ctx, field) + case "code": + return ec.fieldContext_Country_code(ctx, field) + case "covidStats": + return ec.fieldContext_Country_covidStats(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type Country", field.Name) + }, + } + defer func() { + if r := recover(); r != nil { + err = ec.Recover(ctx, r) + ec.Error(ctx, err) + } + }() + ctx = graphql.WithFieldContext(ctx, fc) + if fc.Args, err = ec.field_Query_country_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { + ec.Error(ctx, err) + return + } + return fc, nil +} + +func (ec *executionContext) _Query_countries(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Query_countries(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Query().Countries(rctx, fc.Args["first"].(*int), fc.Args["after"].(*string), fc.Args["filter"].(*model.CountryFilterInput)) + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(*model.CountriesConnection) + fc.Result = res + return ec.marshalNCountriesConnection2ᚖcovidᚋgraphᚋmodelᚐCountriesConnection(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_Query_countries(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Query", + Field: field, + IsMethod: true, + IsResolver: true, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "pageInfo": + return ec.fieldContext_CountriesConnection_pageInfo(ctx, field) + case "edges": + return ec.fieldContext_CountriesConnection_edges(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type CountriesConnection", field.Name) + }, + } + defer func() { + if r := recover(); r != nil { + err = ec.Recover(ctx, r) + ec.Error(ctx, err) + } + }() + ctx = graphql.WithFieldContext(ctx, fc) + if fc.Args, err = ec.field_Query_countries_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { + ec.Error(ctx, err) + return + } + return fc, nil +} + +func (ec *executionContext) _Query_monitoredCountries(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Query_monitoredCountries(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Query().MonitoredCountries(rctx, fc.Args["userID"].(string)) + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.([]*model.Country) + fc.Result = res + return ec.marshalNCountry2ᚕᚖcovidᚋgraphᚋmodelᚐCountryᚄ(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_Query_monitoredCountries(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Query", + Field: field, + IsMethod: true, + IsResolver: true, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "id": + return ec.fieldContext_Country_id(ctx, field) + case "name": + return ec.fieldContext_Country_name(ctx, field) + case "code": + return ec.fieldContext_Country_code(ctx, field) + case "covidStats": + return ec.fieldContext_Country_covidStats(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type Country", field.Name) + }, + } + defer func() { + if r := recover(); r != nil { + err = ec.Recover(ctx, r) + ec.Error(ctx, err) + } + }() + ctx = graphql.WithFieldContext(ctx, fc) + if fc.Args, err = ec.field_Query_monitoredCountries_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { + ec.Error(ctx, err) + return + } + return fc, nil +} + +func (ec *executionContext) _Query_covidStatistics(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Query_covidStatistics(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Query().CovidStatistics(rctx, fc.Args["countryID"].(string), fc.Args["after"].(*string), fc.Args["first"].(*int)) + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(*model.CovidStatisticConnection) + fc.Result = res + return ec.marshalNCovidStatisticConnection2ᚖcovidᚋgraphᚋmodelᚐCovidStatisticConnection(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_Query_covidStatistics(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Query", + Field: field, + IsMethod: true, + IsResolver: true, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "pageInfo": + return ec.fieldContext_CovidStatisticConnection_pageInfo(ctx, field) + case "edges": + return ec.fieldContext_CovidStatisticConnection_edges(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type CovidStatisticConnection", field.Name) + }, + } + defer func() { + if r := recover(); r != nil { + err = ec.Recover(ctx, r) + ec.Error(ctx, err) + } + }() + ctx = graphql.WithFieldContext(ctx, fc) + if fc.Args, err = ec.field_Query_covidStatistics_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { + ec.Error(ctx, err) + return + } + return fc, nil +} + +func (ec *executionContext) _Query_covidStatistic(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Query_covidStatistic(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Query().CovidStatistic(rctx, fc.Args["id"].(string)) + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*model.CovidStatistic) + fc.Result = res + return ec.marshalOCovidStatistic2ᚖcovidᚋgraphᚋmodelᚐCovidStatistic(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_Query_covidStatistic(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Query", + Field: field, + IsMethod: true, + IsResolver: true, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "id": + return ec.fieldContext_CovidStatistic_id(ctx, field) + case "country": + return ec.fieldContext_CovidStatistic_country(ctx, field) + case "date": + return ec.fieldContext_CovidStatistic_date(ctx, field) + case "confirmed": + return ec.fieldContext_CovidStatistic_confirmed(ctx, field) + case "recovered": + return ec.fieldContext_CovidStatistic_recovered(ctx, field) + case "deaths": + return ec.fieldContext_CovidStatistic_deaths(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type CovidStatistic", field.Name) + }, + } + defer func() { + if r := recover(); r != nil { + err = ec.Recover(ctx, r) + ec.Error(ctx, err) + } + }() + ctx = graphql.WithFieldContext(ctx, fc) + if fc.Args, err = ec.field_Query_covidStatistic_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { + ec.Error(ctx, err) + return + } + return fc, nil +} + +func (ec *executionContext) _Query_deathPercentage(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Query_deathPercentage(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Query().DeathPercentage(rctx, fc.Args["countryID"].(string)) + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(float64) + fc.Result = res + return ec.marshalNFloat2float64(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_Query_deathPercentage(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Query", + Field: field, + IsMethod: true, + IsResolver: true, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type Float does not have child fields") + }, + } + defer func() { + if r := recover(); r != nil { + err = ec.Recover(ctx, r) + ec.Error(ctx, err) + } + }() + ctx = graphql.WithFieldContext(ctx, fc) + if fc.Args, err = ec.field_Query_deathPercentage_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { + ec.Error(ctx, err) + return + } + return fc, nil +} + +func (ec *executionContext) _Query_topCountriesByCaseTypeForUser(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Query_topCountriesByCaseTypeForUser(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Query().TopCountriesByCaseTypeForUser(rctx, fc.Args["caseType"].(model.CaseType), fc.Args["limit"].(int), fc.Args["userId"].(string)) + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.([]*model.Country) + fc.Result = res + return ec.marshalNCountry2ᚕᚖcovidᚋgraphᚋmodelᚐCountry(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_Query_topCountriesByCaseTypeForUser(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Query", + Field: field, + IsMethod: true, + IsResolver: true, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "id": + return ec.fieldContext_Country_id(ctx, field) + case "name": + return ec.fieldContext_Country_name(ctx, field) + case "code": + return ec.fieldContext_Country_code(ctx, field) + case "covidStats": + return ec.fieldContext_Country_covidStats(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type Country", field.Name) + }, + } + defer func() { + if r := recover(); r != nil { + err = ec.Recover(ctx, r) + ec.Error(ctx, err) + } + }() + ctx = graphql.WithFieldContext(ctx, fc) + if fc.Args, err = ec.field_Query_topCountriesByCaseTypeForUser_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { + ec.Error(ctx, err) + return + } + return fc, nil +} + +func (ec *executionContext) _Query___type(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Query___type(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.introspectType(fc.Args["name"].(string)) + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*introspection.Type) + fc.Result = res + return ec.marshalO__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_Query___type(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Query", + Field: field, + IsMethod: true, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "kind": + return ec.fieldContext___Type_kind(ctx, field) + case "name": + return ec.fieldContext___Type_name(ctx, field) + case "description": + return ec.fieldContext___Type_description(ctx, field) + case "fields": + return ec.fieldContext___Type_fields(ctx, field) + case "interfaces": + return ec.fieldContext___Type_interfaces(ctx, field) + case "possibleTypes": + return ec.fieldContext___Type_possibleTypes(ctx, field) + case "enumValues": + return ec.fieldContext___Type_enumValues(ctx, field) + case "inputFields": + return ec.fieldContext___Type_inputFields(ctx, field) + case "ofType": + return ec.fieldContext___Type_ofType(ctx, field) + case "specifiedByURL": + return ec.fieldContext___Type_specifiedByURL(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type __Type", field.Name) + }, + } + defer func() { + if r := recover(); r != nil { + err = ec.Recover(ctx, r) + ec.Error(ctx, err) + } + }() + ctx = graphql.WithFieldContext(ctx, fc) + if fc.Args, err = ec.field_Query___type_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { + ec.Error(ctx, err) + return + } + return fc, nil +} + +func (ec *executionContext) _Query___schema(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_Query___schema(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.introspectSchema() + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*introspection.Schema) + fc.Result = res + return ec.marshalO__Schema2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐSchema(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_Query___schema(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Query", + Field: field, + IsMethod: true, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "description": + return ec.fieldContext___Schema_description(ctx, field) + case "types": + return ec.fieldContext___Schema_types(ctx, field) + case "queryType": + return ec.fieldContext___Schema_queryType(ctx, field) + case "mutationType": + return ec.fieldContext___Schema_mutationType(ctx, field) + case "subscriptionType": + return ec.fieldContext___Schema_subscriptionType(ctx, field) + case "directives": + return ec.fieldContext___Schema_directives(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type __Schema", field.Name) + }, + } + return fc, nil +} + +func (ec *executionContext) _Subscription_covidStatisticUpdated(ctx context.Context, field graphql.CollectedField) (ret func(ctx context.Context) graphql.Marshaler) { + fc, err := ec.fieldContext_Subscription_covidStatisticUpdated(ctx, field) + if err != nil { + return nil + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Subscription().CovidStatisticUpdated(rctx, fc.Args["countryIDs"].([]string)) + }) + if err != nil { + ec.Error(ctx, err) + return nil + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return nil + } + return func(ctx context.Context) graphql.Marshaler { + select { + case res, ok := <-resTmp.(<-chan []*model.CovidStatistic): + if !ok { + return nil + } + return graphql.WriterFunc(func(w io.Writer) { + w.Write([]byte{'{'}) + graphql.MarshalString(field.Alias).MarshalGQL(w) + w.Write([]byte{':'}) + ec.marshalNCovidStatistic2ᚕᚖcovidᚋgraphᚋmodelᚐCovidStatisticᚄ(ctx, field.Selections, res).MarshalGQL(w) + w.Write([]byte{'}'}) + }) + case <-ctx.Done(): + return nil + } + } +} + +func (ec *executionContext) fieldContext_Subscription_covidStatisticUpdated(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Subscription", + Field: field, + IsMethod: true, + IsResolver: true, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "id": + return ec.fieldContext_CovidStatistic_id(ctx, field) + case "country": + return ec.fieldContext_CovidStatistic_country(ctx, field) + case "date": + return ec.fieldContext_CovidStatistic_date(ctx, field) + case "confirmed": + return ec.fieldContext_CovidStatistic_confirmed(ctx, field) + case "recovered": + return ec.fieldContext_CovidStatistic_recovered(ctx, field) + case "deaths": + return ec.fieldContext_CovidStatistic_deaths(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type CovidStatistic", field.Name) + }, + } + defer func() { + if r := recover(); r != nil { + err = ec.Recover(ctx, r) + ec.Error(ctx, err) + } + }() + ctx = graphql.WithFieldContext(ctx, fc) + if fc.Args, err = ec.field_Subscription_covidStatisticUpdated_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { + ec.Error(ctx, err) + return + } + return fc, nil +} + +func (ec *executionContext) _User_id(ctx context.Context, field graphql.CollectedField, obj *model.User) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_User_id(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.ID, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + fc.Result = res + return ec.marshalNID2string(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_User_id(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "User", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type ID does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) _User_username(ctx context.Context, field graphql.CollectedField, obj *model.User) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_User_username(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Username, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + fc.Result = res + return ec.marshalNString2string(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_User_username(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "User", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type String does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) _User_email(ctx context.Context, field graphql.CollectedField, obj *model.User) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_User_email(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Email, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + fc.Result = res + return ec.marshalNString2string(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_User_email(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "User", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type String does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) _User_password(ctx context.Context, field graphql.CollectedField, obj *model.User) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_User_password(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Password, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + fc.Result = res + return ec.marshalNString2string(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_User_password(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "User", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type String does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) _User_monitoredCountries(ctx context.Context, field graphql.CollectedField, obj *model.User) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_User_monitoredCountries(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.MonitoredCountries, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.([]*model.Country) + fc.Result = res + return ec.marshalNCountry2ᚕᚖcovidᚋgraphᚋmodelᚐCountryᚄ(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_User_monitoredCountries(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "User", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "id": + return ec.fieldContext_Country_id(ctx, field) + case "name": + return ec.fieldContext_Country_name(ctx, field) + case "code": + return ec.fieldContext_Country_code(ctx, field) + case "covidStats": + return ec.fieldContext_Country_covidStats(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type Country", field.Name) + }, + } + return fc, nil +} + +func (ec *executionContext) ___Directive_name(ctx context.Context, field graphql.CollectedField, obj *introspection.Directive) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___Directive_name(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Name, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + fc.Result = res + return ec.marshalNString2string(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___Directive_name(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__Directive", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type String does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) ___Directive_description(ctx context.Context, field graphql.CollectedField, obj *introspection.Directive) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___Directive_description(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Description(), nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*string) + fc.Result = res + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___Directive_description(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__Directive", + Field: field, + IsMethod: true, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type String does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) ___Directive_locations(ctx context.Context, field graphql.CollectedField, obj *introspection.Directive) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___Directive_locations(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Locations, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.([]string) + fc.Result = res + return ec.marshalN__DirectiveLocation2ᚕstringᚄ(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___Directive_locations(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__Directive", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type __DirectiveLocation does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) ___Directive_args(ctx context.Context, field graphql.CollectedField, obj *introspection.Directive) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___Directive_args(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Args, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.([]introspection.InputValue) + fc.Result = res + return ec.marshalN__InputValue2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValueᚄ(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___Directive_args(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__Directive", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "name": + return ec.fieldContext___InputValue_name(ctx, field) + case "description": + return ec.fieldContext___InputValue_description(ctx, field) + case "type": + return ec.fieldContext___InputValue_type(ctx, field) + case "defaultValue": + return ec.fieldContext___InputValue_defaultValue(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type __InputValue", field.Name) + }, + } + return fc, nil +} + +func (ec *executionContext) ___Directive_isRepeatable(ctx context.Context, field graphql.CollectedField, obj *introspection.Directive) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___Directive_isRepeatable(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.IsRepeatable, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(bool) + fc.Result = res + return ec.marshalNBoolean2bool(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___Directive_isRepeatable(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__Directive", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type Boolean does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) ___EnumValue_name(ctx context.Context, field graphql.CollectedField, obj *introspection.EnumValue) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___EnumValue_name(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Name, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + fc.Result = res + return ec.marshalNString2string(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___EnumValue_name(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__EnumValue", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type String does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) ___EnumValue_description(ctx context.Context, field graphql.CollectedField, obj *introspection.EnumValue) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___EnumValue_description(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Description(), nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*string) + fc.Result = res + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___EnumValue_description(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__EnumValue", + Field: field, + IsMethod: true, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type String does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) ___EnumValue_isDeprecated(ctx context.Context, field graphql.CollectedField, obj *introspection.EnumValue) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___EnumValue_isDeprecated(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.IsDeprecated(), nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(bool) + fc.Result = res + return ec.marshalNBoolean2bool(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___EnumValue_isDeprecated(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__EnumValue", + Field: field, + IsMethod: true, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type Boolean does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) ___EnumValue_deprecationReason(ctx context.Context, field graphql.CollectedField, obj *introspection.EnumValue) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___EnumValue_deprecationReason(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.DeprecationReason(), nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*string) + fc.Result = res + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___EnumValue_deprecationReason(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__EnumValue", + Field: field, + IsMethod: true, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type String does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) ___Field_name(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___Field_name(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Name, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + fc.Result = res + return ec.marshalNString2string(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___Field_name(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__Field", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type String does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) ___Field_description(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___Field_description(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Description(), nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*string) + fc.Result = res + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___Field_description(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__Field", + Field: field, + IsMethod: true, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type String does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) ___Field_args(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___Field_args(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Args, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.([]introspection.InputValue) + fc.Result = res + return ec.marshalN__InputValue2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValueᚄ(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___Field_args(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__Field", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "name": + return ec.fieldContext___InputValue_name(ctx, field) + case "description": + return ec.fieldContext___InputValue_description(ctx, field) + case "type": + return ec.fieldContext___InputValue_type(ctx, field) + case "defaultValue": + return ec.fieldContext___InputValue_defaultValue(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type __InputValue", field.Name) + }, + } + return fc, nil +} + +func (ec *executionContext) ___Field_type(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___Field_type(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Type, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(*introspection.Type) + fc.Result = res + return ec.marshalN__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___Field_type(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__Field", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "kind": + return ec.fieldContext___Type_kind(ctx, field) + case "name": + return ec.fieldContext___Type_name(ctx, field) + case "description": + return ec.fieldContext___Type_description(ctx, field) + case "fields": + return ec.fieldContext___Type_fields(ctx, field) + case "interfaces": + return ec.fieldContext___Type_interfaces(ctx, field) + case "possibleTypes": + return ec.fieldContext___Type_possibleTypes(ctx, field) + case "enumValues": + return ec.fieldContext___Type_enumValues(ctx, field) + case "inputFields": + return ec.fieldContext___Type_inputFields(ctx, field) + case "ofType": + return ec.fieldContext___Type_ofType(ctx, field) + case "specifiedByURL": + return ec.fieldContext___Type_specifiedByURL(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type __Type", field.Name) + }, + } + return fc, nil +} + +func (ec *executionContext) ___Field_isDeprecated(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___Field_isDeprecated(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.IsDeprecated(), nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(bool) + fc.Result = res + return ec.marshalNBoolean2bool(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___Field_isDeprecated(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__Field", + Field: field, + IsMethod: true, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type Boolean does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) ___Field_deprecationReason(ctx context.Context, field graphql.CollectedField, obj *introspection.Field) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___Field_deprecationReason(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.DeprecationReason(), nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*string) + fc.Result = res + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___Field_deprecationReason(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__Field", + Field: field, + IsMethod: true, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type String does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) ___InputValue_name(ctx context.Context, field graphql.CollectedField, obj *introspection.InputValue) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___InputValue_name(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Name, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + fc.Result = res + return ec.marshalNString2string(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___InputValue_name(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__InputValue", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type String does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) ___InputValue_description(ctx context.Context, field graphql.CollectedField, obj *introspection.InputValue) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___InputValue_description(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Description(), nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*string) + fc.Result = res + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___InputValue_description(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__InputValue", + Field: field, + IsMethod: true, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type String does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) ___InputValue_type(ctx context.Context, field graphql.CollectedField, obj *introspection.InputValue) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___InputValue_type(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Type, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(*introspection.Type) + fc.Result = res + return ec.marshalN__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___InputValue_type(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__InputValue", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "kind": + return ec.fieldContext___Type_kind(ctx, field) + case "name": + return ec.fieldContext___Type_name(ctx, field) + case "description": + return ec.fieldContext___Type_description(ctx, field) + case "fields": + return ec.fieldContext___Type_fields(ctx, field) + case "interfaces": + return ec.fieldContext___Type_interfaces(ctx, field) + case "possibleTypes": + return ec.fieldContext___Type_possibleTypes(ctx, field) + case "enumValues": + return ec.fieldContext___Type_enumValues(ctx, field) + case "inputFields": + return ec.fieldContext___Type_inputFields(ctx, field) + case "ofType": + return ec.fieldContext___Type_ofType(ctx, field) + case "specifiedByURL": + return ec.fieldContext___Type_specifiedByURL(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type __Type", field.Name) + }, + } + return fc, nil +} + +func (ec *executionContext) ___InputValue_defaultValue(ctx context.Context, field graphql.CollectedField, obj *introspection.InputValue) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___InputValue_defaultValue(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.DefaultValue, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*string) + fc.Result = res + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___InputValue_defaultValue(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__InputValue", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type String does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) ___Schema_description(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___Schema_description(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Description(), nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*string) + fc.Result = res + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___Schema_description(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__Schema", + Field: field, + IsMethod: true, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type String does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) ___Schema_types(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___Schema_types(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Types(), nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.([]introspection.Type) + fc.Result = res + return ec.marshalN__Type2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐTypeᚄ(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___Schema_types(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__Schema", + Field: field, + IsMethod: true, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "kind": + return ec.fieldContext___Type_kind(ctx, field) + case "name": + return ec.fieldContext___Type_name(ctx, field) + case "description": + return ec.fieldContext___Type_description(ctx, field) + case "fields": + return ec.fieldContext___Type_fields(ctx, field) + case "interfaces": + return ec.fieldContext___Type_interfaces(ctx, field) + case "possibleTypes": + return ec.fieldContext___Type_possibleTypes(ctx, field) + case "enumValues": + return ec.fieldContext___Type_enumValues(ctx, field) + case "inputFields": + return ec.fieldContext___Type_inputFields(ctx, field) + case "ofType": + return ec.fieldContext___Type_ofType(ctx, field) + case "specifiedByURL": + return ec.fieldContext___Type_specifiedByURL(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type __Type", field.Name) + }, + } + return fc, nil +} + +func (ec *executionContext) ___Schema_queryType(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___Schema_queryType(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.QueryType(), nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(*introspection.Type) + fc.Result = res + return ec.marshalN__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___Schema_queryType(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__Schema", + Field: field, + IsMethod: true, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "kind": + return ec.fieldContext___Type_kind(ctx, field) + case "name": + return ec.fieldContext___Type_name(ctx, field) + case "description": + return ec.fieldContext___Type_description(ctx, field) + case "fields": + return ec.fieldContext___Type_fields(ctx, field) + case "interfaces": + return ec.fieldContext___Type_interfaces(ctx, field) + case "possibleTypes": + return ec.fieldContext___Type_possibleTypes(ctx, field) + case "enumValues": + return ec.fieldContext___Type_enumValues(ctx, field) + case "inputFields": + return ec.fieldContext___Type_inputFields(ctx, field) + case "ofType": + return ec.fieldContext___Type_ofType(ctx, field) + case "specifiedByURL": + return ec.fieldContext___Type_specifiedByURL(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type __Type", field.Name) + }, + } + return fc, nil +} + +func (ec *executionContext) ___Schema_mutationType(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___Schema_mutationType(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.MutationType(), nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*introspection.Type) + fc.Result = res + return ec.marshalO__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___Schema_mutationType(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__Schema", + Field: field, + IsMethod: true, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "kind": + return ec.fieldContext___Type_kind(ctx, field) + case "name": + return ec.fieldContext___Type_name(ctx, field) + case "description": + return ec.fieldContext___Type_description(ctx, field) + case "fields": + return ec.fieldContext___Type_fields(ctx, field) + case "interfaces": + return ec.fieldContext___Type_interfaces(ctx, field) + case "possibleTypes": + return ec.fieldContext___Type_possibleTypes(ctx, field) + case "enumValues": + return ec.fieldContext___Type_enumValues(ctx, field) + case "inputFields": + return ec.fieldContext___Type_inputFields(ctx, field) + case "ofType": + return ec.fieldContext___Type_ofType(ctx, field) + case "specifiedByURL": + return ec.fieldContext___Type_specifiedByURL(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type __Type", field.Name) + }, + } + return fc, nil +} + +func (ec *executionContext) ___Schema_subscriptionType(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___Schema_subscriptionType(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.SubscriptionType(), nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*introspection.Type) + fc.Result = res + return ec.marshalO__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___Schema_subscriptionType(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__Schema", + Field: field, + IsMethod: true, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "kind": + return ec.fieldContext___Type_kind(ctx, field) + case "name": + return ec.fieldContext___Type_name(ctx, field) + case "description": + return ec.fieldContext___Type_description(ctx, field) + case "fields": + return ec.fieldContext___Type_fields(ctx, field) + case "interfaces": + return ec.fieldContext___Type_interfaces(ctx, field) + case "possibleTypes": + return ec.fieldContext___Type_possibleTypes(ctx, field) + case "enumValues": + return ec.fieldContext___Type_enumValues(ctx, field) + case "inputFields": + return ec.fieldContext___Type_inputFields(ctx, field) + case "ofType": + return ec.fieldContext___Type_ofType(ctx, field) + case "specifiedByURL": + return ec.fieldContext___Type_specifiedByURL(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type __Type", field.Name) + }, + } + return fc, nil +} + +func (ec *executionContext) ___Schema_directives(ctx context.Context, field graphql.CollectedField, obj *introspection.Schema) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___Schema_directives(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Directives(), nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.([]introspection.Directive) + fc.Result = res + return ec.marshalN__Directive2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐDirectiveᚄ(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___Schema_directives(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__Schema", + Field: field, + IsMethod: true, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "name": + return ec.fieldContext___Directive_name(ctx, field) + case "description": + return ec.fieldContext___Directive_description(ctx, field) + case "locations": + return ec.fieldContext___Directive_locations(ctx, field) + case "args": + return ec.fieldContext___Directive_args(ctx, field) + case "isRepeatable": + return ec.fieldContext___Directive_isRepeatable(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type __Directive", field.Name) + }, + } + return fc, nil +} + +func (ec *executionContext) ___Type_kind(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___Type_kind(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Kind(), nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + fc.Result = res + return ec.marshalN__TypeKind2string(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___Type_kind(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__Type", + Field: field, + IsMethod: true, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type __TypeKind does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) ___Type_name(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___Type_name(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Name(), nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*string) + fc.Result = res + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___Type_name(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__Type", + Field: field, + IsMethod: true, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type String does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) ___Type_description(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___Type_description(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Description(), nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*string) + fc.Result = res + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___Type_description(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__Type", + Field: field, + IsMethod: true, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type String does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) ___Type_fields(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___Type_fields(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Fields(fc.Args["includeDeprecated"].(bool)), nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.([]introspection.Field) + fc.Result = res + return ec.marshalO__Field2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐFieldᚄ(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___Type_fields(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__Type", + Field: field, + IsMethod: true, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "name": + return ec.fieldContext___Field_name(ctx, field) + case "description": + return ec.fieldContext___Field_description(ctx, field) + case "args": + return ec.fieldContext___Field_args(ctx, field) + case "type": + return ec.fieldContext___Field_type(ctx, field) + case "isDeprecated": + return ec.fieldContext___Field_isDeprecated(ctx, field) + case "deprecationReason": + return ec.fieldContext___Field_deprecationReason(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type __Field", field.Name) + }, + } + defer func() { + if r := recover(); r != nil { + err = ec.Recover(ctx, r) + ec.Error(ctx, err) + } + }() + ctx = graphql.WithFieldContext(ctx, fc) + if fc.Args, err = ec.field___Type_fields_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { + ec.Error(ctx, err) + return + } + return fc, nil +} + +func (ec *executionContext) ___Type_interfaces(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___Type_interfaces(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Interfaces(), nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.([]introspection.Type) + fc.Result = res + return ec.marshalO__Type2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐTypeᚄ(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___Type_interfaces(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__Type", + Field: field, + IsMethod: true, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "kind": + return ec.fieldContext___Type_kind(ctx, field) + case "name": + return ec.fieldContext___Type_name(ctx, field) + case "description": + return ec.fieldContext___Type_description(ctx, field) + case "fields": + return ec.fieldContext___Type_fields(ctx, field) + case "interfaces": + return ec.fieldContext___Type_interfaces(ctx, field) + case "possibleTypes": + return ec.fieldContext___Type_possibleTypes(ctx, field) + case "enumValues": + return ec.fieldContext___Type_enumValues(ctx, field) + case "inputFields": + return ec.fieldContext___Type_inputFields(ctx, field) + case "ofType": + return ec.fieldContext___Type_ofType(ctx, field) + case "specifiedByURL": + return ec.fieldContext___Type_specifiedByURL(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type __Type", field.Name) + }, + } + return fc, nil +} + +func (ec *executionContext) ___Type_possibleTypes(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___Type_possibleTypes(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.PossibleTypes(), nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.([]introspection.Type) + fc.Result = res + return ec.marshalO__Type2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐTypeᚄ(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___Type_possibleTypes(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__Type", + Field: field, + IsMethod: true, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "kind": + return ec.fieldContext___Type_kind(ctx, field) + case "name": + return ec.fieldContext___Type_name(ctx, field) + case "description": + return ec.fieldContext___Type_description(ctx, field) + case "fields": + return ec.fieldContext___Type_fields(ctx, field) + case "interfaces": + return ec.fieldContext___Type_interfaces(ctx, field) + case "possibleTypes": + return ec.fieldContext___Type_possibleTypes(ctx, field) + case "enumValues": + return ec.fieldContext___Type_enumValues(ctx, field) + case "inputFields": + return ec.fieldContext___Type_inputFields(ctx, field) + case "ofType": + return ec.fieldContext___Type_ofType(ctx, field) + case "specifiedByURL": + return ec.fieldContext___Type_specifiedByURL(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type __Type", field.Name) + }, + } + return fc, nil +} + +func (ec *executionContext) ___Type_enumValues(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___Type_enumValues(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.EnumValues(fc.Args["includeDeprecated"].(bool)), nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.([]introspection.EnumValue) + fc.Result = res + return ec.marshalO__EnumValue2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐEnumValueᚄ(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___Type_enumValues(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__Type", + Field: field, + IsMethod: true, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "name": + return ec.fieldContext___EnumValue_name(ctx, field) + case "description": + return ec.fieldContext___EnumValue_description(ctx, field) + case "isDeprecated": + return ec.fieldContext___EnumValue_isDeprecated(ctx, field) + case "deprecationReason": + return ec.fieldContext___EnumValue_deprecationReason(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type __EnumValue", field.Name) + }, + } + defer func() { + if r := recover(); r != nil { + err = ec.Recover(ctx, r) + ec.Error(ctx, err) + } + }() + ctx = graphql.WithFieldContext(ctx, fc) + if fc.Args, err = ec.field___Type_enumValues_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { + ec.Error(ctx, err) + return + } + return fc, nil +} + +func (ec *executionContext) ___Type_inputFields(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___Type_inputFields(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.InputFields(), nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.([]introspection.InputValue) + fc.Result = res + return ec.marshalO__InputValue2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValueᚄ(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___Type_inputFields(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__Type", + Field: field, + IsMethod: true, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "name": + return ec.fieldContext___InputValue_name(ctx, field) + case "description": + return ec.fieldContext___InputValue_description(ctx, field) + case "type": + return ec.fieldContext___InputValue_type(ctx, field) + case "defaultValue": + return ec.fieldContext___InputValue_defaultValue(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type __InputValue", field.Name) + }, + } + return fc, nil +} + +func (ec *executionContext) ___Type_ofType(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___Type_ofType(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.OfType(), nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*introspection.Type) + fc.Result = res + return ec.marshalO__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___Type_ofType(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__Type", + Field: field, + IsMethod: true, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "kind": + return ec.fieldContext___Type_kind(ctx, field) + case "name": + return ec.fieldContext___Type_name(ctx, field) + case "description": + return ec.fieldContext___Type_description(ctx, field) + case "fields": + return ec.fieldContext___Type_fields(ctx, field) + case "interfaces": + return ec.fieldContext___Type_interfaces(ctx, field) + case "possibleTypes": + return ec.fieldContext___Type_possibleTypes(ctx, field) + case "enumValues": + return ec.fieldContext___Type_enumValues(ctx, field) + case "inputFields": + return ec.fieldContext___Type_inputFields(ctx, field) + case "ofType": + return ec.fieldContext___Type_ofType(ctx, field) + case "specifiedByURL": + return ec.fieldContext___Type_specifiedByURL(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type __Type", field.Name) + }, + } + return fc, nil +} + +func (ec *executionContext) ___Type_specifiedByURL(ctx context.Context, field graphql.CollectedField, obj *introspection.Type) (ret graphql.Marshaler) { + fc, err := ec.fieldContext___Type_specifiedByURL(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.SpecifiedByURL(), nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*string) + fc.Result = res + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext___Type_specifiedByURL(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "__Type", + Field: field, + IsMethod: true, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type String does not have child fields") + }, + } + return fc, nil +} + +// endregion **************************** field.gotpl ***************************** + +// region **************************** input.gotpl ***************************** + +func (ec *executionContext) unmarshalInputCountryFilterInput(ctx context.Context, obj interface{}) (model.CountryFilterInput, error) { + var it model.CountryFilterInput + asMap := map[string]interface{}{} + for k, v := range obj.(map[string]interface{}) { + asMap[k] = v + } + + fieldsInOrder := [...]string{"nameContains", "codeEquals"} + for _, k := range fieldsInOrder { + v, ok := asMap[k] + if !ok { + continue + } + switch k { + case "nameContains": + var err error + + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("nameContains")) + it.NameContains, err = ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + case "codeEquals": + var err error + + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("codeEquals")) + it.CodeEquals, err = ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + } + } + + return it, nil +} + +func (ec *executionContext) unmarshalInputCountryInput(ctx context.Context, obj interface{}) (model.CountryInput, error) { + var it model.CountryInput + asMap := map[string]interface{}{} + for k, v := range obj.(map[string]interface{}) { + asMap[k] = v + } + + fieldsInOrder := [...]string{"name", "code"} + for _, k := range fieldsInOrder { + v, ok := asMap[k] + if !ok { + continue + } + switch k { + case "name": + var err error + + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("name")) + it.Name, err = ec.unmarshalNString2string(ctx, v) + if err != nil { + return it, err + } + case "code": + var err error + + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("code")) + it.Code, err = ec.unmarshalNString2string(ctx, v) + if err != nil { + return it, err + } + } + } + + return it, nil +} + +func (ec *executionContext) unmarshalInputCovidStatisticInput(ctx context.Context, obj interface{}) (model.CovidStatisticInput, error) { + var it model.CovidStatisticInput + asMap := map[string]interface{}{} + for k, v := range obj.(map[string]interface{}) { + asMap[k] = v + } + + fieldsInOrder := [...]string{"countryID", "date", "confirmed", "recovered", "deaths"} + for _, k := range fieldsInOrder { + v, ok := asMap[k] + if !ok { + continue + } + switch k { + case "countryID": + var err error + + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("countryID")) + it.CountryID, err = ec.unmarshalNID2string(ctx, v) + if err != nil { + return it, err + } + case "date": + var err error + + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("date")) + it.Date, err = ec.unmarshalNString2string(ctx, v) + if err != nil { + return it, err + } + case "confirmed": + var err error + + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("confirmed")) + it.Confirmed, err = ec.unmarshalNInt2int(ctx, v) + if err != nil { + return it, err + } + case "recovered": + var err error + + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("recovered")) + it.Recovered, err = ec.unmarshalNInt2int(ctx, v) + if err != nil { + return it, err + } + case "deaths": + var err error + + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("deaths")) + it.Deaths, err = ec.unmarshalNInt2int(ctx, v) + if err != nil { + return it, err + } + } + } + + return it, nil +} + +// endregion **************************** input.gotpl ***************************** + +// region ************************** interface.gotpl *************************** + +// endregion ************************** interface.gotpl *************************** + +// region **************************** object.gotpl **************************** + +var countriesConnectionImplementors = []string{"CountriesConnection"} + +func (ec *executionContext) _CountriesConnection(ctx context.Context, sel ast.SelectionSet, obj *model.CountriesConnection) graphql.Marshaler { + fields := graphql.CollectFields(ec.OperationContext, sel, countriesConnectionImplementors) + out := graphql.NewFieldSet(fields) + var invalids uint32 + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("CountriesConnection") + case "pageInfo": + + out.Values[i] = ec._CountriesConnection_pageInfo(ctx, field, obj) + + if out.Values[i] == graphql.Null { + invalids++ + } + case "edges": + + out.Values[i] = ec._CountriesConnection_edges(ctx, field, obj) + + if out.Values[i] == graphql.Null { + invalids++ + } + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch() + if invalids > 0 { + return graphql.Null + } + return out +} + +var countryImplementors = []string{"Country"} + +func (ec *executionContext) _Country(ctx context.Context, sel ast.SelectionSet, obj *model.Country) graphql.Marshaler { + fields := graphql.CollectFields(ec.OperationContext, sel, countryImplementors) + out := graphql.NewFieldSet(fields) + var invalids uint32 + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("Country") + case "id": + + out.Values[i] = ec._Country_id(ctx, field, obj) + + if out.Values[i] == graphql.Null { + invalids++ + } + case "name": + + out.Values[i] = ec._Country_name(ctx, field, obj) + + if out.Values[i] == graphql.Null { + invalids++ + } + case "code": + + out.Values[i] = ec._Country_code(ctx, field, obj) + + if out.Values[i] == graphql.Null { + invalids++ + } + case "covidStats": + + out.Values[i] = ec._Country_covidStats(ctx, field, obj) + + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch() + if invalids > 0 { + return graphql.Null + } + return out +} + +var countryEdgeImplementors = []string{"CountryEdge"} + +func (ec *executionContext) _CountryEdge(ctx context.Context, sel ast.SelectionSet, obj *model.CountryEdge) graphql.Marshaler { + fields := graphql.CollectFields(ec.OperationContext, sel, countryEdgeImplementors) + out := graphql.NewFieldSet(fields) + var invalids uint32 + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("CountryEdge") + case "cursor": + + out.Values[i] = ec._CountryEdge_cursor(ctx, field, obj) + + if out.Values[i] == graphql.Null { + invalids++ + } + case "node": + + out.Values[i] = ec._CountryEdge_node(ctx, field, obj) + + if out.Values[i] == graphql.Null { + invalids++ + } + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch() + if invalids > 0 { + return graphql.Null + } + return out +} + +var covidStatisticImplementors = []string{"CovidStatistic"} + +func (ec *executionContext) _CovidStatistic(ctx context.Context, sel ast.SelectionSet, obj *model.CovidStatistic) graphql.Marshaler { + fields := graphql.CollectFields(ec.OperationContext, sel, covidStatisticImplementors) + out := graphql.NewFieldSet(fields) + var invalids uint32 + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("CovidStatistic") + case "id": + + out.Values[i] = ec._CovidStatistic_id(ctx, field, obj) + + if out.Values[i] == graphql.Null { + invalids++ + } + case "country": + + out.Values[i] = ec._CovidStatistic_country(ctx, field, obj) + + if out.Values[i] == graphql.Null { + invalids++ + } + case "date": + + out.Values[i] = ec._CovidStatistic_date(ctx, field, obj) + + if out.Values[i] == graphql.Null { + invalids++ + } + case "confirmed": + + out.Values[i] = ec._CovidStatistic_confirmed(ctx, field, obj) + + if out.Values[i] == graphql.Null { + invalids++ + } + case "recovered": + + out.Values[i] = ec._CovidStatistic_recovered(ctx, field, obj) + + if out.Values[i] == graphql.Null { + invalids++ + } + case "deaths": + + out.Values[i] = ec._CovidStatistic_deaths(ctx, field, obj) + + if out.Values[i] == graphql.Null { + invalids++ + } + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch() + if invalids > 0 { + return graphql.Null + } + return out +} + +var covidStatisticConnectionImplementors = []string{"CovidStatisticConnection"} + +func (ec *executionContext) _CovidStatisticConnection(ctx context.Context, sel ast.SelectionSet, obj *model.CovidStatisticConnection) graphql.Marshaler { + fields := graphql.CollectFields(ec.OperationContext, sel, covidStatisticConnectionImplementors) + out := graphql.NewFieldSet(fields) + var invalids uint32 + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("CovidStatisticConnection") + case "pageInfo": + + out.Values[i] = ec._CovidStatisticConnection_pageInfo(ctx, field, obj) + + if out.Values[i] == graphql.Null { + invalids++ + } + case "edges": + + out.Values[i] = ec._CovidStatisticConnection_edges(ctx, field, obj) + + if out.Values[i] == graphql.Null { + invalids++ + } + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch() + if invalids > 0 { + return graphql.Null + } + return out +} + +var covidStatisticEdgeImplementors = []string{"CovidStatisticEdge"} + +func (ec *executionContext) _CovidStatisticEdge(ctx context.Context, sel ast.SelectionSet, obj *model.CovidStatisticEdge) graphql.Marshaler { + fields := graphql.CollectFields(ec.OperationContext, sel, covidStatisticEdgeImplementors) + out := graphql.NewFieldSet(fields) + var invalids uint32 + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("CovidStatisticEdge") + case "cursor": + + out.Values[i] = ec._CovidStatisticEdge_cursor(ctx, field, obj) + + if out.Values[i] == graphql.Null { + invalids++ + } + case "node": + + out.Values[i] = ec._CovidStatisticEdge_node(ctx, field, obj) + + if out.Values[i] == graphql.Null { + invalids++ + } + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch() + if invalids > 0 { + return graphql.Null + } + return out +} + +var loginResponseImplementors = []string{"LoginResponse"} + +func (ec *executionContext) _LoginResponse(ctx context.Context, sel ast.SelectionSet, obj *model.LoginResponse) graphql.Marshaler { + fields := graphql.CollectFields(ec.OperationContext, sel, loginResponseImplementors) + out := graphql.NewFieldSet(fields) + var invalids uint32 + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("LoginResponse") + case "token": + + out.Values[i] = ec._LoginResponse_token(ctx, field, obj) + + if out.Values[i] == graphql.Null { + invalids++ + } + case "user": + + out.Values[i] = ec._LoginResponse_user(ctx, field, obj) + + if out.Values[i] == graphql.Null { + invalids++ + } + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch() + if invalids > 0 { + return graphql.Null + } + return out +} + +var mutationImplementors = []string{"Mutation"} + +func (ec *executionContext) _Mutation(ctx context.Context, sel ast.SelectionSet) graphql.Marshaler { + fields := graphql.CollectFields(ec.OperationContext, sel, mutationImplementors) + ctx = graphql.WithFieldContext(ctx, &graphql.FieldContext{ + Object: "Mutation", + }) + + out := graphql.NewFieldSet(fields) + var invalids uint32 + for i, field := range fields { + innerCtx := graphql.WithRootFieldContext(ctx, &graphql.RootFieldContext{ + Object: field.Name, + Field: field, + }) + + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("Mutation") + case "register": + + out.Values[i] = ec.OperationContext.RootResolverMiddleware(innerCtx, func(ctx context.Context) (res graphql.Marshaler) { + return ec._Mutation_register(ctx, field) + }) + + if out.Values[i] == graphql.Null { + invalids++ + } + case "deleteUser": + + out.Values[i] = ec.OperationContext.RootResolverMiddleware(innerCtx, func(ctx context.Context) (res graphql.Marshaler) { + return ec._Mutation_deleteUser(ctx, field) + }) + + if out.Values[i] == graphql.Null { + invalids++ + } + case "addCountry": + + out.Values[i] = ec.OperationContext.RootResolverMiddleware(innerCtx, func(ctx context.Context) (res graphql.Marshaler) { + return ec._Mutation_addCountry(ctx, field) + }) + + if out.Values[i] == graphql.Null { + invalids++ + } + case "updateCountry": + + out.Values[i] = ec.OperationContext.RootResolverMiddleware(innerCtx, func(ctx context.Context) (res graphql.Marshaler) { + return ec._Mutation_updateCountry(ctx, field) + }) + + if out.Values[i] == graphql.Null { + invalids++ + } + case "deleteCountry": + + out.Values[i] = ec.OperationContext.RootResolverMiddleware(innerCtx, func(ctx context.Context) (res graphql.Marshaler) { + return ec._Mutation_deleteCountry(ctx, field) + }) + + if out.Values[i] == graphql.Null { + invalids++ + } + case "addCovidStatistic": + + out.Values[i] = ec.OperationContext.RootResolverMiddleware(innerCtx, func(ctx context.Context) (res graphql.Marshaler) { + return ec._Mutation_addCovidStatistic(ctx, field) + }) + + if out.Values[i] == graphql.Null { + invalids++ + } + case "deleteCovidStatistic": + + out.Values[i] = ec.OperationContext.RootResolverMiddleware(innerCtx, func(ctx context.Context) (res graphql.Marshaler) { + return ec._Mutation_deleteCovidStatistic(ctx, field) + }) + + if out.Values[i] == graphql.Null { + invalids++ + } + case "updateCovidStatistic": + + out.Values[i] = ec.OperationContext.RootResolverMiddleware(innerCtx, func(ctx context.Context) (res graphql.Marshaler) { + return ec._Mutation_updateCovidStatistic(ctx, field) + }) + + if out.Values[i] == graphql.Null { + invalids++ + } + case "addUserMonitoredCountry": + + out.Values[i] = ec.OperationContext.RootResolverMiddleware(innerCtx, func(ctx context.Context) (res graphql.Marshaler) { + return ec._Mutation_addUserMonitoredCountry(ctx, field) + }) + + if out.Values[i] == graphql.Null { + invalids++ + } + case "removeUserMonitoredCountry": + + out.Values[i] = ec.OperationContext.RootResolverMiddleware(innerCtx, func(ctx context.Context) (res graphql.Marshaler) { + return ec._Mutation_removeUserMonitoredCountry(ctx, field) + }) + + if out.Values[i] == graphql.Null { + invalids++ + } + case "refreshCovidDataForAllCountries": + + out.Values[i] = ec.OperationContext.RootResolverMiddleware(innerCtx, func(ctx context.Context) (res graphql.Marshaler) { + return ec._Mutation_refreshCovidDataForAllCountries(ctx, field) + }) + + if out.Values[i] == graphql.Null { + invalids++ + } + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch() + if invalids > 0 { + return graphql.Null + } + return out +} + +var pageInfoImplementors = []string{"PageInfo"} + +func (ec *executionContext) _PageInfo(ctx context.Context, sel ast.SelectionSet, obj *model.PageInfo) graphql.Marshaler { + fields := graphql.CollectFields(ec.OperationContext, sel, pageInfoImplementors) + out := graphql.NewFieldSet(fields) + var invalids uint32 + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("PageInfo") + case "endCursor": + + out.Values[i] = ec._PageInfo_endCursor(ctx, field, obj) + + case "hasNextPage": + + out.Values[i] = ec._PageInfo_hasNextPage(ctx, field, obj) + + if out.Values[i] == graphql.Null { + invalids++ + } + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch() + if invalids > 0 { + return graphql.Null + } + return out +} + +var queryImplementors = []string{"Query"} + +func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) graphql.Marshaler { + fields := graphql.CollectFields(ec.OperationContext, sel, queryImplementors) + ctx = graphql.WithFieldContext(ctx, &graphql.FieldContext{ + Object: "Query", + }) + + out := graphql.NewFieldSet(fields) + var invalids uint32 + for i, field := range fields { + innerCtx := graphql.WithRootFieldContext(ctx, &graphql.RootFieldContext{ + Object: field.Name, + Field: field, + }) + + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("Query") + case "login": + field := field + + innerFunc := func(ctx context.Context) (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Query_login(ctx, field) + if res == graphql.Null { + atomic.AddUint32(&invalids, 1) + } + return res + } + + rrm := func(ctx context.Context) graphql.Marshaler { + return ec.OperationContext.RootResolverMiddleware(ctx, innerFunc) + } + + out.Concurrently(i, func() graphql.Marshaler { + return rrm(innerCtx) + }) + case "user": + field := field + + innerFunc := func(ctx context.Context) (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Query_user(ctx, field) + return res + } + + rrm := func(ctx context.Context) graphql.Marshaler { + return ec.OperationContext.RootResolverMiddleware(ctx, innerFunc) + } + + out.Concurrently(i, func() graphql.Marshaler { + return rrm(innerCtx) + }) + case "country": + field := field + + innerFunc := func(ctx context.Context) (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Query_country(ctx, field) + return res + } + + rrm := func(ctx context.Context) graphql.Marshaler { + return ec.OperationContext.RootResolverMiddleware(ctx, innerFunc) + } + + out.Concurrently(i, func() graphql.Marshaler { + return rrm(innerCtx) + }) + case "countries": + field := field + + innerFunc := func(ctx context.Context) (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Query_countries(ctx, field) + if res == graphql.Null { + atomic.AddUint32(&invalids, 1) + } + return res + } + + rrm := func(ctx context.Context) graphql.Marshaler { + return ec.OperationContext.RootResolverMiddleware(ctx, innerFunc) + } + + out.Concurrently(i, func() graphql.Marshaler { + return rrm(innerCtx) + }) + case "monitoredCountries": + field := field + + innerFunc := func(ctx context.Context) (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Query_monitoredCountries(ctx, field) + if res == graphql.Null { + atomic.AddUint32(&invalids, 1) + } + return res + } + + rrm := func(ctx context.Context) graphql.Marshaler { + return ec.OperationContext.RootResolverMiddleware(ctx, innerFunc) + } + + out.Concurrently(i, func() graphql.Marshaler { + return rrm(innerCtx) + }) + case "covidStatistics": + field := field + + innerFunc := func(ctx context.Context) (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Query_covidStatistics(ctx, field) + if res == graphql.Null { + atomic.AddUint32(&invalids, 1) + } + return res + } + + rrm := func(ctx context.Context) graphql.Marshaler { + return ec.OperationContext.RootResolverMiddleware(ctx, innerFunc) + } + + out.Concurrently(i, func() graphql.Marshaler { + return rrm(innerCtx) + }) + case "covidStatistic": + field := field + + innerFunc := func(ctx context.Context) (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Query_covidStatistic(ctx, field) + return res + } + + rrm := func(ctx context.Context) graphql.Marshaler { + return ec.OperationContext.RootResolverMiddleware(ctx, innerFunc) + } + + out.Concurrently(i, func() graphql.Marshaler { + return rrm(innerCtx) + }) + case "deathPercentage": + field := field + + innerFunc := func(ctx context.Context) (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Query_deathPercentage(ctx, field) + if res == graphql.Null { + atomic.AddUint32(&invalids, 1) + } + return res + } + + rrm := func(ctx context.Context) graphql.Marshaler { + return ec.OperationContext.RootResolverMiddleware(ctx, innerFunc) + } + + out.Concurrently(i, func() graphql.Marshaler { + return rrm(innerCtx) + }) + case "topCountriesByCaseTypeForUser": + field := field + + innerFunc := func(ctx context.Context) (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Query_topCountriesByCaseTypeForUser(ctx, field) + if res == graphql.Null { + atomic.AddUint32(&invalids, 1) + } + return res + } + + rrm := func(ctx context.Context) graphql.Marshaler { + return ec.OperationContext.RootResolverMiddleware(ctx, innerFunc) + } + + out.Concurrently(i, func() graphql.Marshaler { + return rrm(innerCtx) + }) + case "__type": + + out.Values[i] = ec.OperationContext.RootResolverMiddleware(innerCtx, func(ctx context.Context) (res graphql.Marshaler) { + return ec._Query___type(ctx, field) + }) + + case "__schema": + + out.Values[i] = ec.OperationContext.RootResolverMiddleware(innerCtx, func(ctx context.Context) (res graphql.Marshaler) { + return ec._Query___schema(ctx, field) + }) + + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch() + if invalids > 0 { + return graphql.Null + } + return out +} + +var subscriptionImplementors = []string{"Subscription"} + +func (ec *executionContext) _Subscription(ctx context.Context, sel ast.SelectionSet) func(ctx context.Context) graphql.Marshaler { + fields := graphql.CollectFields(ec.OperationContext, sel, subscriptionImplementors) + ctx = graphql.WithFieldContext(ctx, &graphql.FieldContext{ + Object: "Subscription", + }) + if len(fields) != 1 { + ec.Errorf(ctx, "must subscribe to exactly one stream") + return nil + } + + switch fields[0].Name { + case "covidStatisticUpdated": + return ec._Subscription_covidStatisticUpdated(ctx, fields[0]) + default: + panic("unknown field " + strconv.Quote(fields[0].Name)) + } +} + +var userImplementors = []string{"User"} + +func (ec *executionContext) _User(ctx context.Context, sel ast.SelectionSet, obj *model.User) graphql.Marshaler { + fields := graphql.CollectFields(ec.OperationContext, sel, userImplementors) + out := graphql.NewFieldSet(fields) + var invalids uint32 + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("User") + case "id": + + out.Values[i] = ec._User_id(ctx, field, obj) + + if out.Values[i] == graphql.Null { + invalids++ + } + case "username": + + out.Values[i] = ec._User_username(ctx, field, obj) + + if out.Values[i] == graphql.Null { + invalids++ + } + case "email": + + out.Values[i] = ec._User_email(ctx, field, obj) + + if out.Values[i] == graphql.Null { + invalids++ + } + case "password": + + out.Values[i] = ec._User_password(ctx, field, obj) + + if out.Values[i] == graphql.Null { + invalids++ + } + case "monitoredCountries": + + out.Values[i] = ec._User_monitoredCountries(ctx, field, obj) + + if out.Values[i] == graphql.Null { + invalids++ + } + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch() + if invalids > 0 { + return graphql.Null + } + return out +} + +var __DirectiveImplementors = []string{"__Directive"} + +func (ec *executionContext) ___Directive(ctx context.Context, sel ast.SelectionSet, obj *introspection.Directive) graphql.Marshaler { + fields := graphql.CollectFields(ec.OperationContext, sel, __DirectiveImplementors) + out := graphql.NewFieldSet(fields) + var invalids uint32 + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("__Directive") + case "name": + + out.Values[i] = ec.___Directive_name(ctx, field, obj) + + if out.Values[i] == graphql.Null { + invalids++ + } + case "description": + + out.Values[i] = ec.___Directive_description(ctx, field, obj) + + case "locations": + + out.Values[i] = ec.___Directive_locations(ctx, field, obj) + + if out.Values[i] == graphql.Null { + invalids++ + } + case "args": + + out.Values[i] = ec.___Directive_args(ctx, field, obj) + + if out.Values[i] == graphql.Null { + invalids++ + } + case "isRepeatable": + + out.Values[i] = ec.___Directive_isRepeatable(ctx, field, obj) + + if out.Values[i] == graphql.Null { + invalids++ + } + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch() + if invalids > 0 { + return graphql.Null + } + return out +} + +var __EnumValueImplementors = []string{"__EnumValue"} + +func (ec *executionContext) ___EnumValue(ctx context.Context, sel ast.SelectionSet, obj *introspection.EnumValue) graphql.Marshaler { + fields := graphql.CollectFields(ec.OperationContext, sel, __EnumValueImplementors) + out := graphql.NewFieldSet(fields) + var invalids uint32 + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("__EnumValue") + case "name": + + out.Values[i] = ec.___EnumValue_name(ctx, field, obj) + + if out.Values[i] == graphql.Null { + invalids++ + } + case "description": + + out.Values[i] = ec.___EnumValue_description(ctx, field, obj) + + case "isDeprecated": + + out.Values[i] = ec.___EnumValue_isDeprecated(ctx, field, obj) + + if out.Values[i] == graphql.Null { + invalids++ + } + case "deprecationReason": + + out.Values[i] = ec.___EnumValue_deprecationReason(ctx, field, obj) + + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch() + if invalids > 0 { + return graphql.Null + } + return out +} + +var __FieldImplementors = []string{"__Field"} + +func (ec *executionContext) ___Field(ctx context.Context, sel ast.SelectionSet, obj *introspection.Field) graphql.Marshaler { + fields := graphql.CollectFields(ec.OperationContext, sel, __FieldImplementors) + out := graphql.NewFieldSet(fields) + var invalids uint32 + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("__Field") + case "name": + + out.Values[i] = ec.___Field_name(ctx, field, obj) + + if out.Values[i] == graphql.Null { + invalids++ + } + case "description": + + out.Values[i] = ec.___Field_description(ctx, field, obj) + + case "args": + + out.Values[i] = ec.___Field_args(ctx, field, obj) + + if out.Values[i] == graphql.Null { + invalids++ + } + case "type": + + out.Values[i] = ec.___Field_type(ctx, field, obj) + + if out.Values[i] == graphql.Null { + invalids++ + } + case "isDeprecated": + + out.Values[i] = ec.___Field_isDeprecated(ctx, field, obj) + + if out.Values[i] == graphql.Null { + invalids++ + } + case "deprecationReason": + + out.Values[i] = ec.___Field_deprecationReason(ctx, field, obj) + + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch() + if invalids > 0 { + return graphql.Null + } + return out +} + +var __InputValueImplementors = []string{"__InputValue"} + +func (ec *executionContext) ___InputValue(ctx context.Context, sel ast.SelectionSet, obj *introspection.InputValue) graphql.Marshaler { + fields := graphql.CollectFields(ec.OperationContext, sel, __InputValueImplementors) + out := graphql.NewFieldSet(fields) + var invalids uint32 + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("__InputValue") + case "name": + + out.Values[i] = ec.___InputValue_name(ctx, field, obj) + + if out.Values[i] == graphql.Null { + invalids++ + } + case "description": + + out.Values[i] = ec.___InputValue_description(ctx, field, obj) + + case "type": + + out.Values[i] = ec.___InputValue_type(ctx, field, obj) + + if out.Values[i] == graphql.Null { + invalids++ + } + case "defaultValue": + + out.Values[i] = ec.___InputValue_defaultValue(ctx, field, obj) + + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch() + if invalids > 0 { + return graphql.Null + } + return out +} + +var __SchemaImplementors = []string{"__Schema"} + +func (ec *executionContext) ___Schema(ctx context.Context, sel ast.SelectionSet, obj *introspection.Schema) graphql.Marshaler { + fields := graphql.CollectFields(ec.OperationContext, sel, __SchemaImplementors) + out := graphql.NewFieldSet(fields) + var invalids uint32 + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("__Schema") + case "description": + + out.Values[i] = ec.___Schema_description(ctx, field, obj) + + case "types": + + out.Values[i] = ec.___Schema_types(ctx, field, obj) + + if out.Values[i] == graphql.Null { + invalids++ + } + case "queryType": + + out.Values[i] = ec.___Schema_queryType(ctx, field, obj) + + if out.Values[i] == graphql.Null { + invalids++ + } + case "mutationType": + + out.Values[i] = ec.___Schema_mutationType(ctx, field, obj) + + case "subscriptionType": + + out.Values[i] = ec.___Schema_subscriptionType(ctx, field, obj) + + case "directives": + + out.Values[i] = ec.___Schema_directives(ctx, field, obj) + + if out.Values[i] == graphql.Null { + invalids++ + } + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch() + if invalids > 0 { + return graphql.Null + } + return out +} + +var __TypeImplementors = []string{"__Type"} + +func (ec *executionContext) ___Type(ctx context.Context, sel ast.SelectionSet, obj *introspection.Type) graphql.Marshaler { + fields := graphql.CollectFields(ec.OperationContext, sel, __TypeImplementors) + out := graphql.NewFieldSet(fields) + var invalids uint32 + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("__Type") + case "kind": + + out.Values[i] = ec.___Type_kind(ctx, field, obj) + + if out.Values[i] == graphql.Null { + invalids++ + } + case "name": + + out.Values[i] = ec.___Type_name(ctx, field, obj) + + case "description": + + out.Values[i] = ec.___Type_description(ctx, field, obj) + + case "fields": + + out.Values[i] = ec.___Type_fields(ctx, field, obj) + + case "interfaces": + + out.Values[i] = ec.___Type_interfaces(ctx, field, obj) + + case "possibleTypes": + + out.Values[i] = ec.___Type_possibleTypes(ctx, field, obj) + + case "enumValues": + + out.Values[i] = ec.___Type_enumValues(ctx, field, obj) + + case "inputFields": + + out.Values[i] = ec.___Type_inputFields(ctx, field, obj) + + case "ofType": + + out.Values[i] = ec.___Type_ofType(ctx, field, obj) + + case "specifiedByURL": + + out.Values[i] = ec.___Type_specifiedByURL(ctx, field, obj) + + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch() + if invalids > 0 { + return graphql.Null + } + return out +} + +// endregion **************************** object.gotpl **************************** + +// region ***************************** type.gotpl ***************************** + +func (ec *executionContext) unmarshalNBoolean2bool(ctx context.Context, v interface{}) (bool, error) { + res, err := graphql.UnmarshalBoolean(v) + return res, graphql.ErrorOnPath(ctx, err) +} + +func (ec *executionContext) marshalNBoolean2bool(ctx context.Context, sel ast.SelectionSet, v bool) graphql.Marshaler { + res := graphql.MarshalBoolean(v) + if res == graphql.Null { + if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) { + ec.Errorf(ctx, "the requested element is null which the schema does not allow") + } + } + return res +} + +func (ec *executionContext) unmarshalNCaseType2covidᚋgraphᚋmodelᚐCaseType(ctx context.Context, v interface{}) (model.CaseType, error) { + var res model.CaseType + err := res.UnmarshalGQL(v) + return res, graphql.ErrorOnPath(ctx, err) +} + +func (ec *executionContext) marshalNCaseType2covidᚋgraphᚋmodelᚐCaseType(ctx context.Context, sel ast.SelectionSet, v model.CaseType) graphql.Marshaler { + return v +} + +func (ec *executionContext) marshalNCountriesConnection2covidᚋgraphᚋmodelᚐCountriesConnection(ctx context.Context, sel ast.SelectionSet, v model.CountriesConnection) graphql.Marshaler { + return ec._CountriesConnection(ctx, sel, &v) +} + +func (ec *executionContext) marshalNCountriesConnection2ᚖcovidᚋgraphᚋmodelᚐCountriesConnection(ctx context.Context, sel ast.SelectionSet, v *model.CountriesConnection) graphql.Marshaler { + if v == nil { + if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) { + ec.Errorf(ctx, "the requested element is null which the schema does not allow") + } + return graphql.Null + } + return ec._CountriesConnection(ctx, sel, v) +} + +func (ec *executionContext) marshalNCountry2covidᚋgraphᚋmodelᚐCountry(ctx context.Context, sel ast.SelectionSet, v model.Country) graphql.Marshaler { + return ec._Country(ctx, sel, &v) +} + +func (ec *executionContext) marshalNCountry2ᚕᚖcovidᚋgraphᚋmodelᚐCountry(ctx context.Context, sel ast.SelectionSet, v []*model.Country) graphql.Marshaler { + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + fc := &graphql.FieldContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithFieldContext(ctx, fc) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalOCountry2ᚖcovidᚋgraphᚋmodelᚐCountry(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + + return ret +} + +func (ec *executionContext) marshalNCountry2ᚕᚖcovidᚋgraphᚋmodelᚐCountryᚄ(ctx context.Context, sel ast.SelectionSet, v []*model.Country) graphql.Marshaler { + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + fc := &graphql.FieldContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithFieldContext(ctx, fc) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalNCountry2ᚖcovidᚋgraphᚋmodelᚐCountry(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + + for _, e := range ret { + if e == graphql.Null { + return graphql.Null + } + } + + return ret +} + +func (ec *executionContext) marshalNCountry2ᚖcovidᚋgraphᚋmodelᚐCountry(ctx context.Context, sel ast.SelectionSet, v *model.Country) graphql.Marshaler { + if v == nil { + if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) { + ec.Errorf(ctx, "the requested element is null which the schema does not allow") + } + return graphql.Null + } + return ec._Country(ctx, sel, v) +} + +func (ec *executionContext) marshalNCountryEdge2ᚕᚖcovidᚋgraphᚋmodelᚐCountryEdgeᚄ(ctx context.Context, sel ast.SelectionSet, v []*model.CountryEdge) graphql.Marshaler { + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + fc := &graphql.FieldContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithFieldContext(ctx, fc) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalNCountryEdge2ᚖcovidᚋgraphᚋmodelᚐCountryEdge(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + + for _, e := range ret { + if e == graphql.Null { + return graphql.Null + } + } + + return ret +} + +func (ec *executionContext) marshalNCountryEdge2ᚖcovidᚋgraphᚋmodelᚐCountryEdge(ctx context.Context, sel ast.SelectionSet, v *model.CountryEdge) graphql.Marshaler { + if v == nil { + if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) { + ec.Errorf(ctx, "the requested element is null which the schema does not allow") + } + return graphql.Null + } + return ec._CountryEdge(ctx, sel, v) +} + +func (ec *executionContext) unmarshalNCountryInput2covidᚋgraphᚋmodelᚐCountryInput(ctx context.Context, v interface{}) (model.CountryInput, error) { + res, err := ec.unmarshalInputCountryInput(ctx, v) + return res, graphql.ErrorOnPath(ctx, err) +} + +func (ec *executionContext) marshalNCovidStatistic2covidᚋgraphᚋmodelᚐCovidStatistic(ctx context.Context, sel ast.SelectionSet, v model.CovidStatistic) graphql.Marshaler { + return ec._CovidStatistic(ctx, sel, &v) +} + +func (ec *executionContext) marshalNCovidStatistic2ᚕᚖcovidᚋgraphᚋmodelᚐCovidStatisticᚄ(ctx context.Context, sel ast.SelectionSet, v []*model.CovidStatistic) graphql.Marshaler { + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + fc := &graphql.FieldContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithFieldContext(ctx, fc) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalNCovidStatistic2ᚖcovidᚋgraphᚋmodelᚐCovidStatistic(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + + for _, e := range ret { + if e == graphql.Null { + return graphql.Null + } + } + + return ret +} + +func (ec *executionContext) marshalNCovidStatistic2ᚖcovidᚋgraphᚋmodelᚐCovidStatistic(ctx context.Context, sel ast.SelectionSet, v *model.CovidStatistic) graphql.Marshaler { + if v == nil { + if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) { + ec.Errorf(ctx, "the requested element is null which the schema does not allow") + } + return graphql.Null + } + return ec._CovidStatistic(ctx, sel, v) +} + +func (ec *executionContext) marshalNCovidStatisticConnection2covidᚋgraphᚋmodelᚐCovidStatisticConnection(ctx context.Context, sel ast.SelectionSet, v model.CovidStatisticConnection) graphql.Marshaler { + return ec._CovidStatisticConnection(ctx, sel, &v) +} + +func (ec *executionContext) marshalNCovidStatisticConnection2ᚖcovidᚋgraphᚋmodelᚐCovidStatisticConnection(ctx context.Context, sel ast.SelectionSet, v *model.CovidStatisticConnection) graphql.Marshaler { + if v == nil { + if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) { + ec.Errorf(ctx, "the requested element is null which the schema does not allow") + } + return graphql.Null + } + return ec._CovidStatisticConnection(ctx, sel, v) +} + +func (ec *executionContext) marshalNCovidStatisticEdge2ᚕᚖcovidᚋgraphᚋmodelᚐCovidStatisticEdgeᚄ(ctx context.Context, sel ast.SelectionSet, v []*model.CovidStatisticEdge) graphql.Marshaler { + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + fc := &graphql.FieldContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithFieldContext(ctx, fc) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalNCovidStatisticEdge2ᚖcovidᚋgraphᚋmodelᚐCovidStatisticEdge(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + + for _, e := range ret { + if e == graphql.Null { + return graphql.Null + } + } + + return ret +} + +func (ec *executionContext) marshalNCovidStatisticEdge2ᚖcovidᚋgraphᚋmodelᚐCovidStatisticEdge(ctx context.Context, sel ast.SelectionSet, v *model.CovidStatisticEdge) graphql.Marshaler { + if v == nil { + if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) { + ec.Errorf(ctx, "the requested element is null which the schema does not allow") + } + return graphql.Null + } + return ec._CovidStatisticEdge(ctx, sel, v) +} + +func (ec *executionContext) unmarshalNCovidStatisticInput2covidᚋgraphᚋmodelᚐCovidStatisticInput(ctx context.Context, v interface{}) (model.CovidStatisticInput, error) { + res, err := ec.unmarshalInputCovidStatisticInput(ctx, v) + return res, graphql.ErrorOnPath(ctx, err) +} + +func (ec *executionContext) unmarshalNFloat2float64(ctx context.Context, v interface{}) (float64, error) { + res, err := graphql.UnmarshalFloatContext(ctx, v) + return res, graphql.ErrorOnPath(ctx, err) +} + +func (ec *executionContext) marshalNFloat2float64(ctx context.Context, sel ast.SelectionSet, v float64) graphql.Marshaler { + res := graphql.MarshalFloatContext(v) + if res == graphql.Null { + if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) { + ec.Errorf(ctx, "the requested element is null which the schema does not allow") + } + } + return graphql.WrapContextMarshaler(ctx, res) +} + +func (ec *executionContext) unmarshalNID2string(ctx context.Context, v interface{}) (string, error) { + res, err := graphql.UnmarshalID(v) + return res, graphql.ErrorOnPath(ctx, err) +} + +func (ec *executionContext) marshalNID2string(ctx context.Context, sel ast.SelectionSet, v string) graphql.Marshaler { + res := graphql.MarshalID(v) + if res == graphql.Null { + if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) { + ec.Errorf(ctx, "the requested element is null which the schema does not allow") + } + } + return res +} + +func (ec *executionContext) unmarshalNID2ᚕstringᚄ(ctx context.Context, v interface{}) ([]string, error) { + var vSlice []interface{} + if v != nil { + vSlice = graphql.CoerceList(v) + } + var err error + res := make([]string, len(vSlice)) + for i := range vSlice { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithIndex(i)) + res[i], err = ec.unmarshalNID2string(ctx, vSlice[i]) + if err != nil { + return nil, err + } + } + return res, nil +} + +func (ec *executionContext) marshalNID2ᚕstringᚄ(ctx context.Context, sel ast.SelectionSet, v []string) graphql.Marshaler { + ret := make(graphql.Array, len(v)) + for i := range v { + ret[i] = ec.marshalNID2string(ctx, sel, v[i]) + } + + for _, e := range ret { + if e == graphql.Null { + return graphql.Null + } + } + + return ret +} + +func (ec *executionContext) unmarshalNInt2int(ctx context.Context, v interface{}) (int, error) { + res, err := graphql.UnmarshalInt(v) + return res, graphql.ErrorOnPath(ctx, err) +} + +func (ec *executionContext) marshalNInt2int(ctx context.Context, sel ast.SelectionSet, v int) graphql.Marshaler { + res := graphql.MarshalInt(v) + if res == graphql.Null { + if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) { + ec.Errorf(ctx, "the requested element is null which the schema does not allow") + } + } + return res +} + +func (ec *executionContext) marshalNLoginResponse2covidᚋgraphᚋmodelᚐLoginResponse(ctx context.Context, sel ast.SelectionSet, v model.LoginResponse) graphql.Marshaler { + return ec._LoginResponse(ctx, sel, &v) +} + +func (ec *executionContext) marshalNLoginResponse2ᚖcovidᚋgraphᚋmodelᚐLoginResponse(ctx context.Context, sel ast.SelectionSet, v *model.LoginResponse) graphql.Marshaler { + if v == nil { + if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) { + ec.Errorf(ctx, "the requested element is null which the schema does not allow") + } + return graphql.Null + } + return ec._LoginResponse(ctx, sel, v) +} + +func (ec *executionContext) marshalNPageInfo2ᚖcovidᚋgraphᚋmodelᚐPageInfo(ctx context.Context, sel ast.SelectionSet, v *model.PageInfo) graphql.Marshaler { + if v == nil { + if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) { + ec.Errorf(ctx, "the requested element is null which the schema does not allow") + } + return graphql.Null + } + return ec._PageInfo(ctx, sel, v) +} + +func (ec *executionContext) unmarshalNString2string(ctx context.Context, v interface{}) (string, error) { + res, err := graphql.UnmarshalString(v) + return res, graphql.ErrorOnPath(ctx, err) +} + +func (ec *executionContext) marshalNString2string(ctx context.Context, sel ast.SelectionSet, v string) graphql.Marshaler { + res := graphql.MarshalString(v) + if res == graphql.Null { + if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) { + ec.Errorf(ctx, "the requested element is null which the schema does not allow") + } + } + return res +} + +func (ec *executionContext) marshalNUser2covidᚋgraphᚋmodelᚐUser(ctx context.Context, sel ast.SelectionSet, v model.User) graphql.Marshaler { + return ec._User(ctx, sel, &v) +} + +func (ec *executionContext) marshalNUser2ᚖcovidᚋgraphᚋmodelᚐUser(ctx context.Context, sel ast.SelectionSet, v *model.User) graphql.Marshaler { + if v == nil { + if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) { + ec.Errorf(ctx, "the requested element is null which the schema does not allow") + } + return graphql.Null + } + return ec._User(ctx, sel, v) +} + +func (ec *executionContext) marshalN__Directive2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐDirective(ctx context.Context, sel ast.SelectionSet, v introspection.Directive) graphql.Marshaler { + return ec.___Directive(ctx, sel, &v) +} + +func (ec *executionContext) marshalN__Directive2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐDirectiveᚄ(ctx context.Context, sel ast.SelectionSet, v []introspection.Directive) graphql.Marshaler { + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + fc := &graphql.FieldContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithFieldContext(ctx, fc) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalN__Directive2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐDirective(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + + for _, e := range ret { + if e == graphql.Null { + return graphql.Null + } + } + + return ret +} + +func (ec *executionContext) unmarshalN__DirectiveLocation2string(ctx context.Context, v interface{}) (string, error) { + res, err := graphql.UnmarshalString(v) + return res, graphql.ErrorOnPath(ctx, err) +} + +func (ec *executionContext) marshalN__DirectiveLocation2string(ctx context.Context, sel ast.SelectionSet, v string) graphql.Marshaler { + res := graphql.MarshalString(v) + if res == graphql.Null { + if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) { + ec.Errorf(ctx, "the requested element is null which the schema does not allow") + } + } + return res +} + +func (ec *executionContext) unmarshalN__DirectiveLocation2ᚕstringᚄ(ctx context.Context, v interface{}) ([]string, error) { + var vSlice []interface{} + if v != nil { + vSlice = graphql.CoerceList(v) + } + var err error + res := make([]string, len(vSlice)) + for i := range vSlice { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithIndex(i)) + res[i], err = ec.unmarshalN__DirectiveLocation2string(ctx, vSlice[i]) + if err != nil { + return nil, err + } + } + return res, nil +} + +func (ec *executionContext) marshalN__DirectiveLocation2ᚕstringᚄ(ctx context.Context, sel ast.SelectionSet, v []string) graphql.Marshaler { + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + fc := &graphql.FieldContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithFieldContext(ctx, fc) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalN__DirectiveLocation2string(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + + for _, e := range ret { + if e == graphql.Null { + return graphql.Null + } + } + + return ret +} + +func (ec *executionContext) marshalN__EnumValue2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐEnumValue(ctx context.Context, sel ast.SelectionSet, v introspection.EnumValue) graphql.Marshaler { + return ec.___EnumValue(ctx, sel, &v) +} + +func (ec *executionContext) marshalN__Field2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐField(ctx context.Context, sel ast.SelectionSet, v introspection.Field) graphql.Marshaler { + return ec.___Field(ctx, sel, &v) +} + +func (ec *executionContext) marshalN__InputValue2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValue(ctx context.Context, sel ast.SelectionSet, v introspection.InputValue) graphql.Marshaler { + return ec.___InputValue(ctx, sel, &v) +} + +func (ec *executionContext) marshalN__InputValue2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValueᚄ(ctx context.Context, sel ast.SelectionSet, v []introspection.InputValue) graphql.Marshaler { + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + fc := &graphql.FieldContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithFieldContext(ctx, fc) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalN__InputValue2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValue(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + + for _, e := range ret { + if e == graphql.Null { + return graphql.Null + } + } + + return ret +} + +func (ec *executionContext) marshalN__Type2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx context.Context, sel ast.SelectionSet, v introspection.Type) graphql.Marshaler { + return ec.___Type(ctx, sel, &v) +} + +func (ec *executionContext) marshalN__Type2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐTypeᚄ(ctx context.Context, sel ast.SelectionSet, v []introspection.Type) graphql.Marshaler { + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + fc := &graphql.FieldContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithFieldContext(ctx, fc) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalN__Type2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + + for _, e := range ret { + if e == graphql.Null { + return graphql.Null + } + } + + return ret +} + +func (ec *executionContext) marshalN__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx context.Context, sel ast.SelectionSet, v *introspection.Type) graphql.Marshaler { + if v == nil { + if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) { + ec.Errorf(ctx, "the requested element is null which the schema does not allow") + } + return graphql.Null + } + return ec.___Type(ctx, sel, v) +} + +func (ec *executionContext) unmarshalN__TypeKind2string(ctx context.Context, v interface{}) (string, error) { + res, err := graphql.UnmarshalString(v) + return res, graphql.ErrorOnPath(ctx, err) +} + +func (ec *executionContext) marshalN__TypeKind2string(ctx context.Context, sel ast.SelectionSet, v string) graphql.Marshaler { + res := graphql.MarshalString(v) + if res == graphql.Null { + if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) { + ec.Errorf(ctx, "the requested element is null which the schema does not allow") + } + } + return res +} + +func (ec *executionContext) unmarshalOBoolean2bool(ctx context.Context, v interface{}) (bool, error) { + res, err := graphql.UnmarshalBoolean(v) + return res, graphql.ErrorOnPath(ctx, err) +} + +func (ec *executionContext) marshalOBoolean2bool(ctx context.Context, sel ast.SelectionSet, v bool) graphql.Marshaler { + res := graphql.MarshalBoolean(v) + return res +} + +func (ec *executionContext) unmarshalOBoolean2ᚖbool(ctx context.Context, v interface{}) (*bool, error) { + if v == nil { + return nil, nil + } + res, err := graphql.UnmarshalBoolean(v) + return &res, graphql.ErrorOnPath(ctx, err) +} + +func (ec *executionContext) marshalOBoolean2ᚖbool(ctx context.Context, sel ast.SelectionSet, v *bool) graphql.Marshaler { + if v == nil { + return graphql.Null + } + res := graphql.MarshalBoolean(*v) + return res +} + +func (ec *executionContext) marshalOCountry2ᚖcovidᚋgraphᚋmodelᚐCountry(ctx context.Context, sel ast.SelectionSet, v *model.Country) graphql.Marshaler { + if v == nil { + return graphql.Null + } + return ec._Country(ctx, sel, v) +} + +func (ec *executionContext) unmarshalOCountryFilterInput2ᚖcovidᚋgraphᚋmodelᚐCountryFilterInput(ctx context.Context, v interface{}) (*model.CountryFilterInput, error) { + if v == nil { + return nil, nil + } + res, err := ec.unmarshalInputCountryFilterInput(ctx, v) + return &res, graphql.ErrorOnPath(ctx, err) +} + +func (ec *executionContext) marshalOCovidStatistic2ᚖcovidᚋgraphᚋmodelᚐCovidStatistic(ctx context.Context, sel ast.SelectionSet, v *model.CovidStatistic) graphql.Marshaler { + if v == nil { + return graphql.Null + } + return ec._CovidStatistic(ctx, sel, v) +} + +func (ec *executionContext) marshalOCovidStatisticConnection2ᚖcovidᚋgraphᚋmodelᚐCovidStatisticConnection(ctx context.Context, sel ast.SelectionSet, v *model.CovidStatisticConnection) graphql.Marshaler { + if v == nil { + return graphql.Null + } + return ec._CovidStatisticConnection(ctx, sel, v) +} + +func (ec *executionContext) unmarshalOInt2ᚖint(ctx context.Context, v interface{}) (*int, error) { + if v == nil { + return nil, nil + } + res, err := graphql.UnmarshalInt(v) + return &res, graphql.ErrorOnPath(ctx, err) +} + +func (ec *executionContext) marshalOInt2ᚖint(ctx context.Context, sel ast.SelectionSet, v *int) graphql.Marshaler { + if v == nil { + return graphql.Null + } + res := graphql.MarshalInt(*v) + return res +} + +func (ec *executionContext) unmarshalOString2ᚖstring(ctx context.Context, v interface{}) (*string, error) { + if v == nil { + return nil, nil + } + res, err := graphql.UnmarshalString(v) + return &res, graphql.ErrorOnPath(ctx, err) +} + +func (ec *executionContext) marshalOString2ᚖstring(ctx context.Context, sel ast.SelectionSet, v *string) graphql.Marshaler { + if v == nil { + return graphql.Null + } + res := graphql.MarshalString(*v) + return res +} + +func (ec *executionContext) marshalOUser2ᚖcovidᚋgraphᚋmodelᚐUser(ctx context.Context, sel ast.SelectionSet, v *model.User) graphql.Marshaler { + if v == nil { + return graphql.Null + } + return ec._User(ctx, sel, v) +} + +func (ec *executionContext) marshalO__EnumValue2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐEnumValueᚄ(ctx context.Context, sel ast.SelectionSet, v []introspection.EnumValue) graphql.Marshaler { + if v == nil { + return graphql.Null + } + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + fc := &graphql.FieldContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithFieldContext(ctx, fc) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalN__EnumValue2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐEnumValue(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + + for _, e := range ret { + if e == graphql.Null { + return graphql.Null + } + } + + return ret +} + +func (ec *executionContext) marshalO__Field2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐFieldᚄ(ctx context.Context, sel ast.SelectionSet, v []introspection.Field) graphql.Marshaler { + if v == nil { + return graphql.Null + } + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + fc := &graphql.FieldContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithFieldContext(ctx, fc) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalN__Field2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐField(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + + for _, e := range ret { + if e == graphql.Null { + return graphql.Null + } + } + + return ret +} + +func (ec *executionContext) marshalO__InputValue2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValueᚄ(ctx context.Context, sel ast.SelectionSet, v []introspection.InputValue) graphql.Marshaler { + if v == nil { + return graphql.Null + } + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + fc := &graphql.FieldContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithFieldContext(ctx, fc) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalN__InputValue2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValue(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + + for _, e := range ret { + if e == graphql.Null { + return graphql.Null + } + } + + return ret +} + +func (ec *executionContext) marshalO__Schema2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐSchema(ctx context.Context, sel ast.SelectionSet, v *introspection.Schema) graphql.Marshaler { + if v == nil { + return graphql.Null + } + return ec.___Schema(ctx, sel, v) +} + +func (ec *executionContext) marshalO__Type2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐTypeᚄ(ctx context.Context, sel ast.SelectionSet, v []introspection.Type) graphql.Marshaler { + if v == nil { + return graphql.Null + } + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + fc := &graphql.FieldContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithFieldContext(ctx, fc) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalN__Type2githubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + + for _, e := range ret { + if e == graphql.Null { + return graphql.Null + } + } + + return ret +} + +func (ec *executionContext) marshalO__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx context.Context, sel ast.SelectionSet, v *introspection.Type) graphql.Marshaler { + if v == nil { + return graphql.Null + } + return ec.___Type(ctx, sel, v) +} + +// endregion ***************************** type.gotpl ***************************** diff --git a/graph/helpers.go b/graph/helpers.go new file mode 100644 index 0000000..a2787f9 --- /dev/null +++ b/graph/helpers.go @@ -0,0 +1,148 @@ +package graph + +import ( + "covid/database" + "covid/graph/model" + "crypto/rand" + "database/sql" + "errors" + "log" + "regexp" + "time" + + "golang.org/x/crypto/bcrypt" +) + +var pageSize int = 2 + +type Resolver struct { + db *sql.DB +} + +func NewResolver(db *sql.DB) *Resolver { + return &Resolver{db: db} +} + +type PageInfo struct { + HasNextPage bool `json:"hasNextPage"` + EndCursor *string `json:"endCursor,omitempty"` +} + +type CountryEdge struct { + Cursor string `json:"cursor"` + Node database.Country `json:"node"` +} + +type CountryConnection struct { + PageInfo *PageInfo `json:"pageInfo"` + Edges []*CountryEdge `json:"edges"` +} + +func ValidateUserRegistration(username string, email string, password string, r *mutationResolver) error { + if err := ValidateUsername(username); err != nil { + return err + } + + if err := ValidateEmail(email); err != nil { + return err + } + + if err := ValidatePassword(password); err != nil { + return err + } + d := database.NewDB(r.db) + + if err := d.CheckIfUserExists(username); err != nil { + return err + } + + if err := d.CheckIfEmailExists(email); err != nil { + return err + } + + return nil +} + +func ValidateUsername(username string) error { + const minUsernameLength = 3 + var usernameRegex = regexp.MustCompile(`^[a-z]+(-[a-z]+)*$`) + + if len(username) < minUsernameLength { + return errors.New("username must be at least 3 characters long") + } + + if !usernameRegex.MatchString(username) { + return errors.New("username must be lowercase and can only contain hyphens") + } + + return nil +} + +func ValidateEmail(email string) error { + var emailRegex = regexp.MustCompile(`^[a-zA-Z0-9._%+\-]+@[a-zA-Z0-9.\-]+\.[a-zA-Z]{2,}$`) + + if !emailRegex.MatchString(email) { + return errors.New("invalid email address") + } + + return nil +} + +func ValidatePassword(password string) error { + const minPasswordLength = 8 + + // As Go doesn't have lookbehind or lookahead, we need to break the validation + // into separate checks: + var lowerRegex = regexp.MustCompile(`[a-z]`) + var upperRegex = regexp.MustCompile(`[A-Z]`) + var digitRegex = regexp.MustCompile(`\d`) + var specialRegex = regexp.MustCompile(`[@$!%*#?&]`) + + if len(password) < minPasswordLength { + return errors.New("password must be at least 8 characters long") + } + + if !lowerRegex.MatchString(password) || !upperRegex.MatchString(password) || !digitRegex.MatchString(password) || !specialRegex.MatchString(password) { + return errors.New("password must be strong and contain at least 1 uppercase, 1 lowercase, 1 number, and 1 special character") + } + + return nil +} + +func HashPassword(password string) ([]byte, []byte, error) { + salt := make([]byte, 16) + // fill the salt byte slice with random bytes + _, err := rand.Read(salt) + if err != nil { + return nil, nil, err + } + + // use blowfish algorithm to hash the password as it is fster than AES + hashedPassword, err := bcrypt.GenerateFromPassword([]byte(password+string(salt)), bcrypt.DefaultCost) + if err != nil { + return nil, nil, err + } + return hashedPassword, salt, nil +} + +func updateCovidStatsRoutine(d *database.DB, countryIDsInt []int, updatedCovidStats chan []*model.CovidStatistic) { + ticker := time.NewTicker(24 * time.Second) // Check for updates daily + for range ticker.C { + var newCovidStats []*database.CovidStatistic + for _, id := range countryIDsInt { + covidStat, err := d.GetLatestCovidStatisticsByCountryID(id) + if err != nil { + log.Printf("Error fetching latest Covid statistic for country %d: %v", id, err) + continue + } + country, err := d.GetCountryByID(covidStat.CountryID) + if err != nil { + log.Printf("Error fetching country %d: %v", covidStat.CountryID, err) + continue + } + covidStat.Country = country + newCovidStats = append(newCovidStats, &covidStat) + } + updatedCovidStats <- model.MapDatabaseCovidStatisticsToGQLModels(newCovidStats) + } +} diff --git a/graph/model/mapping.go b/graph/model/mapping.go new file mode 100644 index 0000000..8fbe2b4 --- /dev/null +++ b/graph/model/mapping.go @@ -0,0 +1,145 @@ +package model + +import ( + "covid/database" + "encoding/base64" + "fmt" + "strconv" +) + +func CreateMapDatabaseCovidStatsToConnection(covidStats []database.CovidStatistic, pageSize int) *CovidStatisticConnection { + var edges []*CovidStatisticEdge + // truncate first before anything to ensure the correct number of records are returned + if pageSize > 0 && len(covidStats) > pageSize { + covidStats = covidStats[:pageSize] // Truncate the extra records + } + + gqlModelsCovidStats := MapDatabaseCovidStatsToGQLModel(covidStats) + + for _, covidStat := range gqlModelsCovidStats { + edge := &CovidStatisticEdge{ + Cursor: base64.StdEncoding.EncodeToString([]byte(covidStat.ID)), + Node: covidStat, + } + edges = append(edges, edge) + } + + var endCursor *string + hasNextPage := false + if len(covidStats) == pageSize { + //because we have truncated one record, we can be sure that there are more records + hasNextPage = true + } + + if len(covidStats) > 0 { + endCursorValue := base64.StdEncoding.EncodeToString([]byte(strconv.Itoa(covidStats[len(covidStats)-1].ID))) + endCursor = &endCursorValue + } + + return &CovidStatisticConnection{ + PageInfo: &PageInfo{ + EndCursor: endCursor, + HasNextPage: hasNextPage, + }, + Edges: edges, + } +} + +func MapDatabaseCovidStatsToGQLModel(covidStats []database.CovidStatistic) []*CovidStatistic { + var gqlModels []*CovidStatistic + for _, covidStat := range covidStats { + gqlModels = append(gqlModels, MapDatabaseCovidStatisticToGQLModel(&covidStat)) + } + return gqlModels +} + +func MapDatabaseCovidStatisticToGQLModel(covidStatistic *database.CovidStatistic) *CovidStatistic { + return &CovidStatistic{ + ID: fmt.Sprint(covidStatistic.ID), + Country: MapDatabaseCountryToGQLModel(&covidStatistic.Country, nil), + Date: covidStatistic.Date, + Confirmed: covidStatistic.Confirmed, + Recovered: covidStatistic.Recovered, + Deaths: covidStatistic.Deaths, + } +} + +func MapDatabaseCountryToGQLModel(country *database.Country, pageSize *int) *Country { + // If pageSize is nil or 0, do not paginate + if pageSize == nil || *pageSize == 0 { + return &Country{ + ID: fmt.Sprint(country.ID), + Name: country.Name, + Code: country.Code, + CovidStats: CreateMapDatabaseCovidStatsToConnection(country.CovidStatistics, 0), + } + } + + return &Country{ + ID: fmt.Sprint(country.ID), + Name: country.Name, + Code: country.Code, + CovidStats: CreateMapDatabaseCovidStatsToConnection(country.CovidStatistics, *pageSize), + } +} + +func MapDatabaseCovidStatisticsToGQLModels(covidStatistics []*database.CovidStatistic) []*CovidStatistic { + var gqlModels []*CovidStatistic + for _, cs := range covidStatistics { + gqlModels = append(gqlModels, MapDatabaseCovidStatisticToGQLModel(cs)) + } + return gqlModels +} + +func MapDatabaseUserToGQLModel(user *database.User) *User { + return &User{ + ID: fmt.Sprint(user.ID), + Email: user.Email, + Username: user.Username, + MonitoredCountries: MapDatabaseCountriesToGQLModels(user.MonitoredCountries), + } +} + +func MapDatabaseCountriesToGQLModels(countries []database.Country) []*Country { + var gqlModels []*Country + for _, country := range countries { + gqlModels = append(gqlModels, MapDatabaseCountryToGQLModel(&country, nil)) + } + return gqlModels +} + +func CreateMapDatabaseCountriesToConnection(countries []database.Country, pageSize *int) *CountriesConnection { + var edges []*CountryEdge + if *pageSize > 0 && len(countries) > *pageSize { + countries = countries[:*pageSize] + } + + gqlModelsCountries := MapDatabaseCountriesToGQLModels(countries) + + for _, country := range gqlModelsCountries { + edge := &CountryEdge{ + Cursor: base64.StdEncoding.EncodeToString([]byte(country.ID)), + Node: country, + } + edges = append(edges, edge) + } + + var endCursor *string + hasNextPage := false + if len(countries) == *pageSize { + hasNextPage = true + } + + if len(countries) > 0 { + endCursorValue := base64.StdEncoding.EncodeToString([]byte(strconv.Itoa(countries[len(countries)-1].ID))) + endCursor = &endCursorValue + } + + return &CountriesConnection{ + PageInfo: &PageInfo{ + EndCursor: endCursor, + HasNextPage: hasNextPage, + }, + Edges: edges, + } +} diff --git a/graph/model/models_gen.go b/graph/model/models_gen.go new file mode 100644 index 0000000..7c2d67a --- /dev/null +++ b/graph/model/models_gen.go @@ -0,0 +1,122 @@ +// Code generated by github.com/99designs/gqlgen, DO NOT EDIT. + +package model + +import ( + "fmt" + "io" + "strconv" +) + +type CountriesConnection struct { + PageInfo *PageInfo `json:"pageInfo"` + Edges []*CountryEdge `json:"edges"` +} + +type Country struct { + ID string `json:"id"` + Name string `json:"name"` + Code string `json:"code"` + CovidStats *CovidStatisticConnection `json:"covidStats,omitempty"` +} + +type CountryEdge struct { + Cursor string `json:"cursor"` + Node *Country `json:"node"` +} + +type CountryFilterInput struct { + NameContains *string `json:"nameContains,omitempty"` + CodeEquals *string `json:"codeEquals,omitempty"` +} + +type CountryInput struct { + Name string `json:"name"` + Code string `json:"code"` +} + +type CovidStatistic struct { + ID string `json:"id"` + Country *Country `json:"country"` + Date string `json:"date"` + Confirmed int `json:"confirmed"` + Recovered int `json:"recovered"` + Deaths int `json:"deaths"` +} + +type CovidStatisticConnection struct { + PageInfo *PageInfo `json:"pageInfo"` + Edges []*CovidStatisticEdge `json:"edges"` +} + +type CovidStatisticEdge struct { + Cursor string `json:"cursor"` + Node *CovidStatistic `json:"node"` +} + +type CovidStatisticInput struct { + CountryID string `json:"countryID"` + Date string `json:"date"` + Confirmed int `json:"confirmed"` + Recovered int `json:"recovered"` + Deaths int `json:"deaths"` +} + +type LoginResponse struct { + Token string `json:"token"` + User *User `json:"user"` +} + +type PageInfo struct { + EndCursor *string `json:"endCursor,omitempty"` + HasNextPage bool `json:"hasNextPage"` +} + +type User struct { + ID string `json:"id"` + Username string `json:"username"` + Email string `json:"email"` + Password string `json:"password"` + MonitoredCountries []*Country `json:"monitoredCountries"` +} + +type CaseType string + +const ( + CaseTypeConfirmed CaseType = "CONFIRMED" + CaseTypeDeaths CaseType = "DEATHS" +) + +var AllCaseType = []CaseType{ + CaseTypeConfirmed, + CaseTypeDeaths, +} + +func (e CaseType) IsValid() bool { + switch e { + case CaseTypeConfirmed, CaseTypeDeaths: + return true + } + return false +} + +func (e CaseType) String() string { + return string(e) +} + +func (e *CaseType) UnmarshalGQL(v interface{}) error { + str, ok := v.(string) + if !ok { + return fmt.Errorf("enums must be strings") + } + + *e = CaseType(str) + if !e.IsValid() { + return fmt.Errorf("%s is not a valid CaseType", str) + } + return nil +} + +func (e CaseType) MarshalGQL(w io.Writer) { + fmt.Fprint(w, strconv.Quote(e.String())) +} diff --git a/graph/schema.graphqls b/graph/schema.graphqls new file mode 100644 index 0000000..243495c --- /dev/null +++ b/graph/schema.graphqls @@ -0,0 +1,130 @@ +schema { + query: Query + mutation: Mutation + subscription: Subscription +} + +type LoginResponse { + token: String! + user: User! +} + +type User { + id: ID! + username: String! + email: String! + password: String! + monitoredCountries: [Country!]! +} + +type Country { + id: ID! + name: String! + code: String! + covidStats(after: String, first: Int): CovidStatisticConnection +} + +type CovidStatisticConnection { + pageInfo: PageInfo! + edges: [CovidStatisticEdge!]! +} + +type PageInfo { + endCursor: String + hasNextPage: Boolean! +} + +type CovidStatisticEdge { + cursor: String! + node: CovidStatistic! +} + +type CovidStatistic { + id: ID! + country: Country! + date: String! + confirmed: Int! + recovered: Int! + deaths: Int! +} + +input CovidStatisticInput { + countryID: ID! + date: String! + confirmed: Int! + recovered: Int! + deaths: Int! +} + +input CountryInput { + name: String! + code: String! +} + +input CountryFilterInput { + nameContains: String + codeEquals: String +} + +type CountriesConnection { + pageInfo: PageInfo! + edges: [CountryEdge!]! +} + +type CountryEdge { + cursor: String! + node: Country! +} + +type Query { + login(username: String!, password: String!): LoginResponse! + user(username: String, email: String): User + country(id: ID!): Country + countries( + first: Int + after: String + filter: CountryFilterInput + ): CountriesConnection! + monitoredCountries(userID: ID!): [Country!]! + covidStatistics( + countryID: ID! + after: String + first: Int + ): CovidStatisticConnection! + covidStatistic(id: ID!): CovidStatistic + deathPercentage(countryID: ID!): Float! + topCountriesByCaseTypeForUser( + caseType: CaseType! + limit: Int! + userId: ID! + ): [Country]! +} + +type Mutation { + register(username: String!, email: String!, password: String!): LoginResponse! + deleteUser(userID: ID!): Boolean! + addCountry(input: CountryInput!): Country! + updateCountry(id: ID!, name: String!, code: String!): Country! + deleteCountry(countryID: ID!): Boolean! + addCovidStatistic(input: CovidStatisticInput!): CovidStatistic! + deleteCovidStatistic(id: ID!): Boolean! + updateCovidStatistic( + id: ID! + date: String! + confirmed: Int! + recovered: Int! + deaths: Int! + ): CovidStatistic! + addUserMonitoredCountry(userID: ID!, countryID: ID!): User! + removeUserMonitoredCountry(userID: ID!, countryID: ID!): User! + refreshCovidDataForAllCountries: Boolean! +} + +type Subscription { + covidStatisticUpdated(countryIDs: [ID!]!): [CovidStatistic!]! +} + +enum CaseType { + CONFIRMED + DEATHS +} diff --git a/graph/schema.resolvers.go b/graph/schema.resolvers.go new file mode 100644 index 0000000..924cfee --- /dev/null +++ b/graph/schema.resolvers.go @@ -0,0 +1,506 @@ +package graph + +// This file will be automatically regenerated based on the schema, any resolver implementations +// will be copied through when generating and any unknown code will be moved to the end. +// Code generated by github.com/99designs/gqlgen version v0.17.27 + +import ( + "context" + "covid/database" + "covid/fetcher" + "covid/graph/model" + "errors" + "fmt" + "strconv" + "time" + + "golang.org/x/crypto/bcrypt" +) + +// Register is the resolver for the register field. +func (r *mutationResolver) Register(ctx context.Context, username string, email string, password string) (*model.LoginResponse, error) { + err := ValidateUserRegistration(username, email, password, r) + if err != nil { + return nil, err + } + + hashedPassword, salt, err := HashPassword(password) + if err != nil { + return nil, err + } + + d := database.NewDB(r.db) + userID, err := d.RegisterUser(username, email, hashedPassword, salt) + if err != nil { + return nil, err + } + + token, err := GenerateToken(username) + if err != nil { + return nil, err + } + + return &model.LoginResponse{ + Token: token, + User: &model.User{ + ID: fmt.Sprint(userID), + Username: username, + Email: email, + }, + }, nil +} + +// DeleteUser is the resolver for the deleteUser field. +func (r *mutationResolver) DeleteUser(ctx context.Context, userID string) (bool, error) { + userIDInt, err := strconv.Atoi(userID) + if err != nil { + return false, fmt.Errorf("error converting user ID %s to int: %w", userID, err) + } + + d := database.NewDB(r.db) + + if err := d.DeleteUser(userIDInt); err != nil { + return false, err + } + return true, nil +} + +// AddCountry is the resolver for the addCountry field. +func (r *mutationResolver) AddCountry(ctx context.Context, input model.CountryInput) (*model.Country, error) { + if len(input.Code) != 2 { + return nil, errors.New("country code must be 2 characters long") + } + + d := database.NewDB(r.db) + country, ifExists, err := d.CreateCountry(input.Name, input.Code) + if err != nil { + return nil, fmt.Errorf("failed to insert new country: %w", err) + } + + if ifExists { + return nil, errors.New("country already exists") + } + + return model.MapDatabaseCountryToGQLModel(&country, &pageSize), nil +} + +// UpdateCountry is the resolver for the updateCountry field. +func (r *mutationResolver) UpdateCountry(ctx context.Context, id string, name string, code string) (*model.Country, error) { + countryID, err := strconv.Atoi(id) + if err != nil { + return nil, fmt.Errorf("error converting country ID %s to int: %w", id, err) + } + if len(code) != 2 { + return nil, errors.New("country code must be 2 characters long") + } + + d := database.NewDB(r.db) + country, err := d.UpdateCountry(countryID, name, code) + if err != nil { + return nil, fmt.Errorf("error updating country with ID %d: %w", countryID, err) + } + + covidStats, err := d.GetCovidStatistics(countryID, nil, nil) + if err != nil { + return nil, fmt.Errorf("error getting covid statistics for country with ID %d: %w", countryID, err) + } + country.CovidStatistics = covidStats + + return model.MapDatabaseCountryToGQLModel(&country, &pageSize), nil +} + +// DeleteCountry is the resolver for the deleteCountry field. +func (r *mutationResolver) DeleteCountry(ctx context.Context, countryID string) (bool, error) { + countryIDInt, err := strconv.Atoi(countryID) + if err != nil { + return false, fmt.Errorf("error converting country ID %s to int: %w", countryID, err) + } + + d := database.NewDB(r.db) + err = d.DeleteCountry(countryIDInt) + if err != nil { + return false, err + } + + return true, nil +} + +// AddCovidStatistic is the resolver for the addCovidStatistic field. +func (r *mutationResolver) AddCovidStatistic(ctx context.Context, input model.CovidStatisticInput) (*model.CovidStatistic, error) { + countryID, err := strconv.Atoi(input.CountryID) + if err != nil { + return nil, fmt.Errorf("invalid country ID: %w", err) + } + + date, err := time.Parse("2006-01-02", input.Date) + if err != nil { + return nil, fmt.Errorf("invalid date: %w", err) + } + + d := database.NewDB(r.db) + covidStatisticID, err := d.AddCovidStatistic(countryID, date.Format("2006-01-02"), input.Confirmed, input.Recovered, input.Deaths) + if err != nil { + return nil, err + } + + country, err := d.GetCountryByID(countryID) + if err != nil { + return nil, err + } + + return &model.CovidStatistic{ + ID: fmt.Sprint(covidStatisticID), + Country: model.MapDatabaseCountryToGQLModel(&country, nil), + Date: input.Date, + Confirmed: input.Confirmed, + Recovered: input.Recovered, + Deaths: input.Deaths, + }, nil +} + +// DeleteCovidStatistic is the resolver for the deleteCovidStatistic field. +func (r *mutationResolver) DeleteCovidStatistic(ctx context.Context, id string) (bool, error) { + covidStatisticID, err := strconv.Atoi(id) + if err != nil { + return false, fmt.Errorf("invalid covid statistic ID: %w", err) + } + + d := database.NewDB(r.db) + err = d.DeleteCovidStatistic(covidStatisticID) + if err != nil { + return false, err + } + + return true, nil +} + +// UpdateCovidStatistic is the resolver for the updateCovidStatistic field. +func (r *mutationResolver) UpdateCovidStatistic(ctx context.Context, id string, date string, confirmed int, recovered int, deaths int) (*model.CovidStatistic, error) { + covidStatisticID, err := strconv.Atoi(id) + if err != nil { + return nil, fmt.Errorf("invalid covid statistic ID: %w", err) + } + + dateTime, err := time.Parse("2006-01-02", date) + if err != nil { + return nil, fmt.Errorf("invalid date: %w", err) + } + + d := database.NewDB(r.db) + covidStatistic, err := d.UpdateCovidStatistic(covidStatisticID, dateTime.Format("2006-01-02"), confirmed, recovered, deaths) + if err != nil { + return nil, err + } + + country, err := d.GetCountryByID(covidStatistic.CountryID) + if err != nil { + return nil, err + } + + return &model.CovidStatistic{ + ID: fmt.Sprint(covidStatistic.ID), + Country: model.MapDatabaseCountryToGQLModel(&country, nil), + Date: date, + Confirmed: confirmed, + Recovered: recovered, + Deaths: deaths, + }, nil +} + +// AddUserMonitoredCountry is the resolver for the addUserMonitoredCountry field. +func (r *mutationResolver) AddUserMonitoredCountry(ctx context.Context, userID string, countryID string) (*model.User, error) { + userIDInt, err := strconv.Atoi(userID) + if err != nil { + return nil, fmt.Errorf("invalid user ID: %w", err) + } + countryIDInt, err := strconv.Atoi(countryID) + if err != nil { + return nil, fmt.Errorf("invalid country ID: %w", err) + } + + d := database.NewDB(r.db) + if err := d.AddUserMonitoredCountry(userIDInt, countryIDInt); err != nil { + return nil, err + } + + var user database.User + user, err = d.GetUserByID(userIDInt) + if err != nil { + return nil, err + } + + user.MonitoredCountries, err = d.GetUserMonitoredCountries(userIDInt) + if err != nil { + return nil, err + } + + return model.MapDatabaseUserToGQLModel(&user), nil +} + +// RemoveUserMonitoredCountry is the resolver for the removeUserMonitoredCountry field. +func (r *mutationResolver) RemoveUserMonitoredCountry(ctx context.Context, userID string, countryID string) (*model.User, error) { + userIDInt, err := strconv.Atoi(userID) + if err != nil { + return nil, fmt.Errorf("invalid user ID: %w", err) + } + countryIDInt, err := strconv.Atoi(countryID) + if err != nil { + return nil, fmt.Errorf("invalid country ID: %w", err) + } + + d := database.NewDB(r.db) + if err := d.RemoveUserMonitoredCountry(userIDInt, countryIDInt); err != nil { + return nil, err + } + + var user database.User + user, err = d.GetUserByID(userIDInt) + if err != nil { + return nil, err + } + + user.MonitoredCountries, err = d.GetUserMonitoredCountries(userIDInt) + if err != nil { + return nil, err + } + + return model.MapDatabaseUserToGQLModel(&user), nil +} + +// RefreshCovidDataForAllCountries is the resolver for the refreshCovidDataForAllCountries field. +func (r *mutationResolver) RefreshCovidDataForAllCountries(ctx context.Context) (bool, error) { + if err := fetcher.FetchAndUpdateData(r.db); err != nil { + return false, err + } + return true, nil +} + +// Login is the resolver for the login field. +func (r *queryResolver) Login(ctx context.Context, username string, password string) (*model.LoginResponse, error) { + d := database.NewDB(r.db) + user, err := d.GetUserByUsername(username) + if err != nil { + return nil, fmt.Errorf("failed to get user: %w", err) + } + + user.MonitoredCountries, err = d.GetUserMonitoredCountries(user.ID) + if err != nil { + return nil, err + } + + err = bcrypt.CompareHashAndPassword([]byte(user.Password), []byte(password+user.Salt)) + if err != nil { + return nil, errors.New("invalid username or password") + } + + token, err := GenerateToken(username) + if err != nil { + return nil, err + } + + return &model.LoginResponse{ + Token: token, + User: model.MapDatabaseUserToGQLModel(&user), + }, nil +} + +// User is the resolver for the user field. +func (r *queryResolver) User(ctx context.Context, username *string, email *string) (*model.User, error) { + if username == nil && email == nil { + return nil, errors.New("username or email must be provided") + } + + var user database.User + var err error + d := database.NewDB(r.db) + if username != nil { + user, err = d.GetUserByUsername(*username) + } else if email != nil { + user, err = d.GetUserByEmail(*email) + } + + if err != nil { + return nil, err + } + user.Salt = "" + user.Password = "" + + user.MonitoredCountries, err = d.GetUserMonitoredCountries(user.ID) + if err != nil { + return nil, err + } + + return model.MapDatabaseUserToGQLModel(&user), nil +} + +// Country is the resolver for the country field. +func (r *queryResolver) Country(ctx context.Context, id string) (*model.Country, error) { + countryIDInt, err := strconv.Atoi(id) + if err != nil { + return nil, fmt.Errorf("invalid country ID: %w", err) + } + + d := database.NewDB(r.db) + country, err := d.GetCountryByID(countryIDInt) + if err != nil { + return nil, err + } + + return model.MapDatabaseCountryToGQLModel(&country, &pageSize), nil +} + +// Countries is the resolver for the countries field. +func (r *queryResolver) Countries(ctx context.Context, first *int, after *string, filter *model.CountryFilterInput) (*model.CountriesConnection, error) { + var codeEquals, nameContains *string + if filter != nil { + codeEquals = filter.CodeEquals + nameContains = filter.NameContains + } + + d := database.NewDB(r.db) + countries, err := d.GetCountries(first, after, codeEquals, nameContains) + if err != nil { + return nil, err + } + + //loop over each country and get the covid stats + for i := range countries { + covidStats, err := d.GetCovidStatistics(countries[i].ID, nil, nil) + if err != nil { + return nil, err + } + countries[i].CovidStatistics = covidStats + } + + return model.CreateMapDatabaseCountriesToConnection(countries, &pageSize), nil +} + +// MonitoredCountries is the resolver for the monitoredCountries field. +func (r *queryResolver) MonitoredCountries(ctx context.Context, userID string) ([]*model.Country, error) { + userIDInt, err := strconv.Atoi(userID) + if err != nil { + return nil, fmt.Errorf("invalid user ID: %w", err) + } + + d := database.NewDB(r.db) + countries, err := d.GetUserMonitoredCountries(userIDInt) + if err != nil { + return nil, err + } + + //loop over each country and get the covid stats + for i := range countries { + covidStats, err := d.GetCovidStatistics(countries[i].ID, nil, nil) + if err != nil { + return nil, err + } + countries[i].CovidStatistics = covidStats + } + + return model.MapDatabaseCountriesToGQLModels(countries), nil +} + +// CovidStatistics is the resolver for the covidStatistics field. +func (r *queryResolver) CovidStatistics(ctx context.Context, countryID string, after *string, first *int) (*model.CovidStatisticConnection, error) { + countryIDInt, err := strconv.Atoi(countryID) + if err != nil { + return nil, fmt.Errorf("invalid country ID %w", err) + } + + d := database.NewDB(r.db) + covidStats, err := d.GetCovidStatistics(countryIDInt, first, after) + if err != nil { + return nil, err + } + + return model.CreateMapDatabaseCovidStatsToConnection(covidStats, pageSize), nil +} + +// CovidStatistic is the resolver for the covidStatistic field. +func (r *queryResolver) CovidStatistic(ctx context.Context, id string) (*model.CovidStatistic, error) { + + IDInt, err := strconv.Atoi(id) + if err != nil { + return nil, fmt.Errorf("invalid covid statistic ID: %w", err) + } + d := database.NewDB(r.db) + covidStat, err := d.GetCovidStatistic(IDInt) + if err != nil { + return nil, err + } + + //get the country for the covid stat + country, err := d.GetCountryByID(covidStat.CountryID) + if err != nil { + return nil, err + } + covidStat.Country = country + + return model.MapDatabaseCovidStatisticToGQLModel(&covidStat), nil +} + +// DeathPercentage is the resolver for the deathPercentage field. +func (r *queryResolver) DeathPercentage(ctx context.Context, countryID string) (float64, error) { + countryIDInt, err := strconv.Atoi(countryID) + if err != nil { + return 0, fmt.Errorf("invalid country ID: %w", err) + } + + d := database.NewDB(r.db) + return d.GetDeathPercentage(countryIDInt) +} + +// TopCountriesByCaseTypeForUser is the resolver for the topCountriesByCaseTypeForUser field. +func (r *queryResolver) TopCountriesByCaseTypeForUser(ctx context.Context, caseType model.CaseType, limit int, userID string) ([]*model.Country, error) { + userIDInt, err := strconv.Atoi(userID) + if err != nil { + return nil, fmt.Errorf("invalid user ID: %w", err) + } + + d := database.NewDB(r.db) + countries, err := d.GetTopCountriesByCaseTypeForUser(userIDInt, caseType.String(), limit) + if err != nil { + return nil, err + } + + //loop over each country and get the covid stats + for i := range countries { + covidStats, err := d.GetCovidStatistics(countries[i].ID, nil, nil) + if err != nil { + return nil, err + } + countries[i].CovidStatistics = covidStats + } + + return model.MapDatabaseCountriesToGQLModels(countries), nil +} + +// CovidStatisticUpdated is the resolver for the covidStatisticUpdated field. +func (r *subscriptionResolver) CovidStatisticUpdated(ctx context.Context, countryIDs []string) (<-chan []*model.CovidStatistic, error) { + var countryIDsInt []int + for _, id := range countryIDs { + countryIDInt, err := strconv.Atoi(id) + if err != nil { + return nil, fmt.Errorf("invalid country ID: %w", err) + } + countryIDsInt = append(countryIDsInt, countryIDInt) + } + + updatedCovidStats := make(chan []*model.CovidStatistic) + d := database.NewDB(r.db) + go updateCovidStatsRoutine(d, countryIDsInt, updatedCovidStats) + return updatedCovidStats, nil +} + +// Mutation returns MutationResolver implementation. +func (r *Resolver) Mutation() MutationResolver { return &mutationResolver{r} } + +// Query returns QueryResolver implementation. +func (r *Resolver) Query() QueryResolver { return &queryResolver{r} } + +// Subscription returns SubscriptionResolver implementation. +func (r *Resolver) Subscription() SubscriptionResolver { return &subscriptionResolver{r} } + +type mutationResolver struct{ *Resolver } +type queryResolver struct{ *Resolver } +type subscriptionResolver struct{ *Resolver } diff --git a/server.go b/server.go new file mode 100644 index 0000000..e6dd5df --- /dev/null +++ b/server.go @@ -0,0 +1,98 @@ +package main + +import ( + "covid/api" + "covid/database" + "covid/fetcher" + "covid/graph" + "log" + "net/http" + "os" + "strings" + "time" + + "github.com/go-chi/chi/v5" + "github.com/go-chi/chi/v5/middleware" + + "github.com/99designs/gqlgen/graphql/handler" + "github.com/99designs/gqlgen/graphql/playground" +) + +const defaultPort = "8080" + +func authenticationMiddleware(next http.Handler) http.Handler { + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + // Bypass the middleware for the login request + if r.URL.Path == "/login" { + next.ServeHTTP(w, r) + return + } + + authorizationHeader := r.Header.Get("Authorization") + if authorizationHeader == "" { + http.Error(w, "Missing authorization header", http.StatusUnauthorized) + return + } + + token := strings.TrimPrefix(authorizationHeader, "Bearer ") + _, err := graph.ValidateToken(token) + if err != nil { + http.Error(w, "Invalid token", http.StatusForbidden) + return + } + + next.ServeHTTP(w, r) + }) +} + +func main() { + db, err := database.ConnectDB() + if err != nil { + log.Fatalf("Error connecting to database: %v", err) + } + + fetcher.StartFetchingRoutine(db, 24*time.Hour) + + port := os.Getenv("PORT") + if port == "" { + port = defaultPort + } + + r := graph.NewResolver(db) + srv := handler.NewDefaultServer(graph.NewExecutableSchema(graph.Config{Resolvers: r})) + + router := chi.NewRouter() + router.Use(middleware.Logger) + + router.Handle("/", playground.Handler("GraphQL playground", "/login")) + router.Handle("/login", srv) + + router.Group(func(r chi.Router) { + r.Use(authenticationMiddleware) + r.Handle("/query", srv) + r.HandleFunc("/api/user", api.UserHandler(db)) + r.HandleFunc("/api/countries", api.CountriesHandler(db)) + r.HandleFunc("/api/countries/create", api.AddCountryHandler(db)) + r.HandleFunc("/api/countries/{id}/update", api.UpdateCountryHandler(db)) + r.HandleFunc("/api/countries/{id}/delete", api.DeleteCountryHandler(db)) + r.HandleFunc("/api/countries/{id}", api.CountryByIDHandler(db)) + r.HandleFunc("/api/covid-stats/{id}", api.CovidStatisticByIDHandler(db)) + r.HandleFunc("/api/covid-stats", api.CovidStatisticsHandler(db)) + r.HandleFunc("/api/covid-stats/create", api.AddCovidStatisticHandler(db)) + r.HandleFunc("/api/covid-stats/{id}", api.UpdateCovidStatisticHandler(db)) + r.HandleFunc("/api/covid-stats/{id}", api.DeleteCovidStatisticHandler(db)) + r.HandleFunc("/api/users/{userid}/monitored-countries", api.GetMonitoredCountriesHandler(db)) + r.HandleFunc("/api/users/{userid}/monitored-countries", api.AddUserMonitoredCountryHandler(db)) + r.HandleFunc("/api/users/{userid}/monitored-countries/{countryid}", api.DeleteUserMonitoredCountryHandler(db)) + r.HandleFunc("/api/countries/top-by-case-type/{caseType}/{limit}/{userid}", api.GetTopCountriesByCaseTypeForUserHandler(db)) + r.HandleFunc("/api/countries/{countryId}/death-percentage", api.GetDeathPercentageHandler(db)) + r.HandleFunc("/api/register-api", api.RegisterHandler(db)) + r.HandleFunc("/api/login-api", api.LoginHandler(db)) + r.HandleFunc("/api/users/{userid}", api.DeleteUserHandler(db)) + r.HandleFunc("/api/refresh-covid-data", api.RefreshCovidDataForAllCountriesHandler(db)) + + }) + + log.Printf("connect to http://localhost:%s/ for GraphQL playground", port) + log.Fatal(http.ListenAndServe(":"+port, router)) +} diff --git a/tools.go b/tools.go new file mode 100644 index 0000000..6bc46d4 --- /dev/null +++ b/tools.go @@ -0,0 +1,9 @@ +//go:build tools +// +build tools + +package tools + +import ( + _ "github.com/99designs/gqlgen" + _ "github.com/99designs/gqlgen/graphql/introspection" +)