{"id":15512392,"url":"https://github.com/whitefusionhq/graphtown","last_synced_at":"2025-10-12T09:31:16.959Z","repository":{"id":54300431,"uuid":"283802316","full_name":"whitefusionhq/graphtown","owner":"whitefusionhq","description":"Easily consume GraphQL APIs for your Bridgetown website.","archived":true,"fork":false,"pushed_at":"2021-04-06T16:59:16.000Z","size":28,"stargazers_count":10,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-09-14T08:50:04.647Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Ruby","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/whitefusionhq.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":"jaredcwhite"}},"created_at":"2020-07-30T14:49:30.000Z","updated_at":"2024-12-02T15:45:02.000Z","dependencies_parsed_at":"2022-08-13T11:20:52.701Z","dependency_job_id":null,"html_url":"https://github.com/whitefusionhq/graphtown","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/whitefusionhq/graphtown","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/whitefusionhq%2Fgraphtown","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/whitefusionhq%2Fgraphtown/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/whitefusionhq%2Fgraphtown/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/whitefusionhq%2Fgraphtown/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/whitefusionhq","download_url":"https://codeload.github.com/whitefusionhq/graphtown/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/whitefusionhq%2Fgraphtown/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279001431,"owners_count":26083078,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-09T02:00:07.460Z","response_time":59,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["bridgetown","bridgetown-plugin","cms-client","graphql"],"created_at":"2024-10-02T09:53:37.340Z","updated_at":"2025-10-12T09:31:16.676Z","avatar_url":"https://github.com/whitefusionhq.png","language":"Ruby","funding_links":["https://github.com/sponsors/jaredcwhite"],"categories":["Ruby"],"sub_categories":[],"readme":"# Graphtown\n\nEasily consume GraphQL APIs for your [Bridgetown](https://www.bridgetownrb.com) website using a tidy Builder DSL on top of the [Graphlient](http://github.com/ashkan18/graphlient) gem.\n\n## Installation\n\nRun this command to add this plugin to your site's Gemfile:\n\n```shell\n$ bundle add graphtown -g bridgetown_plugins\n```\n\nAnd then add the Graphtown mixin to your site builder superclass:\n\n```ruby\n# plugins/site_builder.rb\n\nclass SiteBuilder \u003c Bridgetown::Builder\n  include Graphtown::QueryBuilder\nend\n```\n\nYou'll need to add your desired GraphQL API endpoint to the site config YAML:\n\n```yaml\n# bridgetown.config.yml\n\ngraphql_endpoint: http://localhost:1337/graphql\n```\n\nAlternatively, you can override the `graphql_endpoint` method in your site builder or a specific builder plugin:\n\n```ruby\ndef graphql_endpoint\n  \"https://some.other.domain/graphql\"\nend\n```\n\n## Usage\n\nYou'll start by creating a builder plugin which defines a GraphQL query using the DSL provided by the Graphlient gem. Then, in the `build` method of the plugin, you can execute the query and use that data to add content to your site.\n\nHere's an example of using the GraphQL API provided by [Strapi](https://strapi.io) (a headless CMS) to turn blog posts authored in the CMS into Bridgetown posts:\n\n```ruby\n# plugins/builders/strapi_posts.rb\n\nclass StrapiPosts \u003c SiteBuilder\n  graphql :posts do\n    query {\n      posts {\n        id\n        title\n        description\n        body\n        createdAt\n      }\n    }\n  end\n\n  def build\n    queries.posts.each do |post|\n      slug = Bridgetown::Utils.slugify(post.title)\n      doc \"#{slug}.md\" do\n        layout \"post\"\n        date post.created_at\n        front_matter post.to_h\n        content post.body\n      end\n    end\n  end\nend\n```\n\nThe `queries` object will contain the same graph names as what you define using the `graphql` class method. If the \"data root\" of the query is the same as the graph name, you don't have to access the root specifically. In other words, you don't have to write `queries.posts.posts.each do |post|`. However, if your data root is different, you'll need to access it specifically (see below where it's written as `queries.github.viewer…`).\n\nHere's an example of using an authenticated GitHub API to access a list of repositories owned by the user associated with the API key. It includes configuring the Graphlient client to provide the API key in the request header, as well as utilizing query variables which get resolved at runtime.\n\n```ruby\n# plugins/builders/github_graphql.rb\n\nclass GitHubGraphql \u003c SiteBuilder\n  graphql :github do\n    query(number_of_repos: :int) do\n      viewer do\n        repositories(first: :number_of_repos) do\n          edges do\n            node do\n              name\n              description\n              createdAt\n            end\n          end\n        end\n      end\n    end\n  end\n\n  def variables_for_github\n    {\n      # pull this out of the bridgetown.config.yaml, if present:\n      number_of_repos: config[:github_repo_limit] || 10\n    }\n  end\n\n  def build\n    queries.github.viewer.repositories.edges.each do |item|\n      repo = item.node\n      slug = Bridgetown::Utils.slugify(repo.name)\n\n      doc \"#{slug}.md\" do\n        layout \"repository\"\n        date repo.created_at\n        title repo.name\n        content repo.description\n      end\n    end\n  end\n\n  def graphql_endpoint\n    \"https://api.github.com/graphql\"\n  end\n\n  def configure_graphql_client(client)\n    client.options[:headers] = {\n      \"Authorization\" =\u003e \"bearer #{ENV[\"GITHUB_API_TOKEN\"]}\"\n    }\n  end\nend\n```\n\nNote that these examples show just one GraphQL query defined in the plugin, but you can call the `graphql` class method multiple times with different graph names/queries, and access any or all of them in the `build` method.\n\nIf you run into any issues or need further assistance using GraphQL in your Bridgetown project, [please reach out to the Bridgetown community](https://www.bridgetownrb.com/docs/community) via chat or other means. If you think you've encountered a bug, please file an issue here in the GitHub repo. \n\n## Testing\n\n* Run `bundle exec rspec` to run the test suite\n* Or run `script/cibuild` to validate with Rubocop and test with rspec together.\n\n## Contributing\n\n1. Fork it (https://github.com/whitefusionhq/graphtown/fork)\n2. Clone the fork using `git clone` to your local development machine.\n3. Create your feature branch (`git checkout -b my-new-feature`)\n4. Commit your changes (`git commit -am 'Add some feature'`)\n5. Push to the branch (`git push origin my-new-feature`)\n6. Create a new Pull Request\n\n## Releasing\n\nTo release a new version of the plugin, simply bump up the version number in\n`version.rb` and then run `script/release`.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwhitefusionhq%2Fgraphtown","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwhitefusionhq%2Fgraphtown","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwhitefusionhq%2Fgraphtown/lists"}