{"id":37192943,"url":"https://github.com/landrade/gqlgen-cache-control-plugin","last_synced_at":"2026-01-14T22:23:35.392Z","repository":{"id":57696355,"uuid":"492341508","full_name":"landrade/gqlgen-cache-control-plugin","owner":"landrade","description":"cache-control plugin for Gqlgen","archived":false,"fork":false,"pushed_at":"2024-08-15T19:59:44.000Z","size":35,"stargazers_count":5,"open_issues_count":2,"forks_count":4,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-08-15T21:31:43.388Z","etag":null,"topics":["cache-control","golang","gqlgen","graphql"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/landrade.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-05-14T22:55:43.000Z","updated_at":"2024-08-15T19:32:24.000Z","dependencies_parsed_at":"2022-09-15T21:11:14.955Z","dependency_job_id":null,"html_url":"https://github.com/landrade/gqlgen-cache-control-plugin","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/landrade/gqlgen-cache-control-plugin","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/landrade%2Fgqlgen-cache-control-plugin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/landrade%2Fgqlgen-cache-control-plugin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/landrade%2Fgqlgen-cache-control-plugin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/landrade%2Fgqlgen-cache-control-plugin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/landrade","download_url":"https://codeload.github.com/landrade/gqlgen-cache-control-plugin/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/landrade%2Fgqlgen-cache-control-plugin/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28436296,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T21:32:52.117Z","status":"ssl_error","status_checked_at":"2026-01-14T21:32:33.442Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cache-control","golang","gqlgen","graphql"],"created_at":"2026-01-14T22:23:34.818Z","updated_at":"2026-01-14T22:23:35.369Z","avatar_url":"https://github.com/landrade.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Cache control plugin for GQLGEN\n\nPlugin for gqlgen (https://gqlgen.com/) to write cache-control directives. With this plugin, you can write a cache-control HTTP header and cache-control extension, following Apollo's rules. Refs:\n\n- https://www.apollographql.com/docs/apollo-server/performance/caching/\n- https://github.com/apollographql/apollo-server/tree/d5015f4ea00cadb2a74b09956344e6f65c084629/packages/apollo-cache-control\n\n\n### Installation\n\nInstall Go module:\n\n```bash\n$ go get github.com/landrade/gqlgen-cache-control-plugin\n```\n\n### Configuring the plugin\n\n```go\npackage main\nimport (\n\t\"github.com/landrade/gqlgen-cache-control-plugin/cache\"\n\t\"github.com/99designs/gqlgen/graphql/handler\"\n)\nfunc main() {\n\t// Building your server\n\tcfg := generated.Config{Resolvers: \u0026graph.Resolver{}}\n\tsrv := handler.NewDefaultServer(generated.NewExecutableSchema(cfg))\n\t// Enable cache extensions\n\tsrv.Use(cache.Extension{}) // \u003c----\n\t//...\n}\n```\n\n### Set cache hints\n\nAfter you enable `cache.Extension`, you can set cache hints using `cache.SetHint` function in your resolvers.\n\n```go\nimport (\n\t\"github.com/landrade/gqlgen-cache-control-plugin/cache\"\n\t// ...\n)\nfunc (r *commentResolver) Post(ctx context.Context, obj *model.Comment) (*model.Post, error) {\n    post, err := // getting post by comment\n    if err != nil {\n        return nil, err\n\t}\n\t// Set a CacheHint\n\tcache.SetHint(ctx, cache.ScopePublic, 10*time.Second)\n\treturn post, nil\n}\n```\n\n### CDN Caching\n\nIt's possible to enable the Gqlgen to provide a `Cache-Control` header based on your cache hints in `GET` or `POST` requests.\nTo do it you need wrap your server using `cache.Middleware` function. It will add `Cache-Control` header to all responses that have set cache.\n\n\n```go\nfunc main() {\n\t// ... setup server\n\tsrv = cache.Middleware(srv)\n\t// ... do more things\n}\n````\n\nDoing it, Gqlgen write the lowest max-age defined in cacheControl extensions.\n\nFor more informations, see `_example` folder.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flandrade%2Fgqlgen-cache-control-plugin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flandrade%2Fgqlgen-cache-control-plugin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flandrade%2Fgqlgen-cache-control-plugin/lists"}