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.95 import ( "context" "adam-french.co.uk/backend/graph/model" "adam-french.co.uk/backend/services" ) // SteamStatus is the resolver for the steamStatus field. func (r *queryResolver) SteamStatus(ctx context.Context) (*model.SteamStatus, error) { if r.Store.SteamAPIKey == "" { return nil, nil } // Five-minute cache across both Steam calls, which are made together and // expire together. if games, online, ok := r.Store.CachedSteam(); ok { return &model.SteamStatus{ Online: online, RecentGames: mapSteamGames(games), }, nil } games, err := services.FetchRecentlyPlayedGames(r.Store.SteamAPIKey, r.Store.SteamID) if err != nil { return nil, err } summary, err := services.FetchPlayerSummary(r.Store.SteamAPIKey, r.Store.SteamID) if err != nil { return nil, err } // PersonaState 0 is offline; every higher value is some flavour of // online. A nil summary (private profile) reads as offline. online := false if summary != nil { online = summary.PersonaState > 0 } r.Store.SetSteam(games, online) return &model.SteamStatus{ Online: online, RecentGames: mapSteamGames(games), }, nil }