{"id":13878115,"url":"https://github.com/tenderlove/tinygql","last_synced_at":"2025-04-13T07:50:00.438Z","repository":{"id":187103268,"uuid":"676315436","full_name":"tenderlove/tinygql","owner":"tenderlove","description":"A tiny and experimental GraphQL parser in Ruby","archived":false,"fork":false,"pushed_at":"2024-10-14T00:20:47.000Z","size":128,"stargazers_count":87,"open_issues_count":0,"forks_count":7,"subscribers_count":6,"default_branch":"main","last_synced_at":"2025-04-13T07:49:54.680Z","etag":null,"topics":["graphql","ruby"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tenderlove.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-08-08T23:39:12.000Z","updated_at":"2025-02-25T21:19:33.000Z","dependencies_parsed_at":"2024-10-23T05:08:28.873Z","dependency_job_id":null,"html_url":"https://github.com/tenderlove/tinygql","commit_stats":null,"previous_names":["tenderlove/tinygql"],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tenderlove%2Ftinygql","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tenderlove%2Ftinygql/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tenderlove%2Ftinygql/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tenderlove%2Ftinygql/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tenderlove","download_url":"https://codeload.github.com/tenderlove/tinygql/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248681494,"owners_count":21144700,"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","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":["graphql","ruby"],"created_at":"2024-08-06T08:01:40.247Z","updated_at":"2025-04-13T07:50:00.416Z","avatar_url":"https://github.com/tenderlove.png","language":"Ruby","readme":"# TinyGQL\n\nVery experimental GraphQL parser.  It's mostly reusing the lexer from\n[GraphQL-Ruby](https://github.com/rmosolgo/graphql-ruby), but the parser is a\nhand-written recursive descent parser.\n\nI want to target this at server side applications, so the parser eliminates some nice stuff for humans (namely line / column information, and it throws away comments).\n\nRight now this code:\n\n1. Doesn't know how to execute anything.  It just gives you an AST\n2. Isn't used anywhere (except in your heart, *but hopefully in production someday!)\n\n## Usage\n\nYou can get an AST like this:\n\n```ruby\nast = TinyGQL.parse \"{ cool }\"\n```\n\nThe AST is iterable, so you can use the each method:\n\n```ruby\nast = TinyGQL.parse \"{ cool }\"\nast.each do |node|\n  p node.class\nend\n```\n\nNodes have predicate methods, so if you want to find particular nodes just use a predicate:\n\n```ruby\nast = TinyGQL.parse \"{ cool }\"\np ast.find_all(\u0026:field?).map(\u0026:name) # =\u003e [\"cool\"]\n```\n\nIf you need a more advanced way to iterate nodes, you can use a visitor:\n\n```ruby\nclass Viz\n  include TinyGQL::Visitors::Visitor\n\n  def handle_field obj\n    p obj.name # =\u003e cool\n    super\n  end\nend\n\nast = TinyGQL.parse \"{ cool }\"\nast.accept(Viz.new)\n```\n\nIf you would like a functional way to collect data from the tree, use the `Fold` module:\n\n```ruby\nmodule Fold\n  extend TinyGQL::Visitors::Fold\n\n  def self.handle_field obj, seed\n    super(obj, seed + [obj.name])\n  end\nend\n\nast = TinyGQL.parse \"{ neat { cool } }\"\np ast.fold(Fold, []) # =\u003e [\"neat\", \"cool\"]\n```\n\nNodes store their position in the source GraphQL document.\nIf you'd like to extract the line number of the node, you'll need to keep a reference to the document and pass it to the `line` method on the node:\n\n```ruby\ndoc = \u003c\u003c-eod\nmutation {\n  likeStory(sturyID: 12345) {\n    story {\n      likeCount\n    }\n  }\n}\n\neod\n\nparser = TinyGQL::Parser.new doc\nast = parser.parse\n\nast.find_all(\u0026:field?).each { |node|\n  p node.name =\u003e node.line(doc)\n}\n```\n\n## LICENSE:\n\nI've licensed this code as Apache 2.0, but the lexer is from [GraphQL-Ruby](https://github.com/rmosolgo/graphql-ruby/blob/772734dfcc7aa0513c867259912474ef0ba799c3/lib/graphql/language/lexer.rb) and is under the MIT license.\n","funding_links":[],"categories":["Ruby"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftenderlove%2Ftinygql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftenderlove%2Ftinygql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftenderlove%2Ftinygql/lists"}