{"id":23045143,"url":"https://github.com/graphql-protocols/graphql-protocols-sinatra-sample","last_synced_at":"2025-04-03T01:44:47.749Z","repository":{"id":40532446,"uuid":"189264029","full_name":"graphql-protocols/graphql-protocols-sinatra-sample","owner":"graphql-protocols","description":"A ruby sample of GraphQL protocols on Sinatra","archived":false,"fork":false,"pushed_at":"2022-12-01T01:27:58.000Z","size":128,"stargazers_count":1,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-08T16:13:39.470Z","etag":null,"topics":["graphql-protocols","ruby","sdl","sinatra"],"latest_commit_sha":null,"homepage":"https://graphql-protocols.herokuapp.com/graphiql","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/graphql-protocols.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-05-29T16:47:08.000Z","updated_at":"2019-06-27T17:23:36.000Z","dependencies_parsed_at":"2023-01-22T08:30:17.512Z","dependency_job_id":null,"html_url":"https://github.com/graphql-protocols/graphql-protocols-sinatra-sample","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/graphql-protocols%2Fgraphql-protocols-sinatra-sample","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/graphql-protocols%2Fgraphql-protocols-sinatra-sample/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/graphql-protocols%2Fgraphql-protocols-sinatra-sample/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/graphql-protocols%2Fgraphql-protocols-sinatra-sample/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/graphql-protocols","download_url":"https://codeload.github.com/graphql-protocols/graphql-protocols-sinatra-sample/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246922232,"owners_count":20855343,"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-protocols","ruby","sdl","sinatra"],"created_at":"2024-12-15T21:18:36.396Z","updated_at":"2025-04-03T01:44:47.726Z","avatar_url":"https://github.com/graphql-protocols.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# GraphQL protocols sinatra sample\n\n\u003e WARNING: We're working on this 💪. For discussion purposes only at this moment.\n\nThis is a very hacky sinatra example on how to implement [GraphQL protocols](https://github.com/graphql-protocols/graphql-protocols) in a sinatra ruby app.\n\n![GraphiQL](https://raw.githubusercontent.com/graphql-protocols/graphql-protocols-sinatra-sample/master/images/graphiql.jpg)\n\nTo set this up:\n\n```bash\nbundle\nbundle exec rackup\n```\n\nThen navigate to `http://localhost:9292/graphiql` to check out your GraphQL endpoint.\n\nOr you can deploy to heroku:\n\n[![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy)\n\nAnd go to your endpoint /graphiql to see your endpoint\n\n## Concept\n\nIn this sample we're implementing a couple of protocols. This exists out of 2 parts. The protocols itself and the implementation.\n\n### The vendored protocols\n\nThe files under protocols are vendored. They will be supplied by your protocol vendor. These protocols can also be installed via a gem or npm package.\n\n```bash\ngraphql-protocols-sample-server (master) ∆ tree ./protocols\n./protocols\n├── contacts\n│   └── schema.graphql\n├── postbox\n│   └── schema.graphql\n└── tokens\n    └── schema.graphql\n\n7 directories, 7 files\n```\n\nYou just need to drop them in and extend your `schema.graphql` as done here.\n\n```graphql\ntype User implements Postbox {\n}\n\ntype Query implements Postbox, Contacts {\n  messages: [Message!]\n  contacts: [Contact!]\n  viewer: User\n}\n\ntype Mutation implements PostboxMutatations, TokenRequestMutations {\n  sendMessage(message: String): Message\n}\n```\n\n### The implementation\n\nThis is where you come into the picture. After this is done. You need to write the implementation for those protocols. Some vendors supply a sample protocol implementation here. I've just wrote a sample implementation in ruby that returns some data.\n\n```ruby\nmodule Messages\n  def messages\n    [{message: \"You are all breathtaking!\"}]\n  end\n\n  module Mutations\n    def sendMessage\n      {message: \"No! YOU are breathtaking!\"}\n    end\n  end\nend\n\nmodule Contacts\n  def contacts\n    [{name: \"Keanu Reeves\"}]\n  end\nend\n\nclass Query\n  include Messages\n  include Contacts\nend\n\nclass Mutation\n  include Messages::Mutations\nend\n```\n\nNext, hook them up in your resolver. Aaand done! You now have a GraphQL endpoint that adheres to the vendored protocols! 🙌\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgraphql-protocols%2Fgraphql-protocols-sinatra-sample","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgraphql-protocols%2Fgraphql-protocols-sinatra-sample","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgraphql-protocols%2Fgraphql-protocols-sinatra-sample/lists"}