Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/graphql-protocols/graphql-protocols-sinatra-sample
A ruby sample of GraphQL protocols on Sinatra
https://github.com/graphql-protocols/graphql-protocols-sinatra-sample
graphql-protocols ruby sdl sinatra
Last synced: about 1 month ago
JSON representation
A ruby sample of GraphQL protocols on Sinatra
- Host: GitHub
- URL: https://github.com/graphql-protocols/graphql-protocols-sinatra-sample
- Owner: graphql-protocols
- Created: 2019-05-29T16:47:08.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2022-12-01T01:27:58.000Z (about 2 years ago)
- Last Synced: 2023-03-10T07:44:20.152Z (almost 2 years ago)
- Topics: graphql-protocols, ruby, sdl, sinatra
- Language: Ruby
- Homepage: https://graphql-protocols.herokuapp.com/graphiql
- Size: 125 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# GraphQL protocols sinatra sample
> WARNING: We're working on this 💪. For discussion purposes only at this moment.
This is a very hacky sinatra example on how to implement [GraphQL protocols](https://github.com/graphql-protocols/graphql-protocols) in a sinatra ruby app.
![GraphiQL](https://raw.githubusercontent.com/graphql-protocols/graphql-protocols-sinatra-sample/master/images/graphiql.jpg)
To set this up:
```bash
bundle
bundle exec rackup
```Then navigate to `http://localhost:9292/graphiql` to check out your GraphQL endpoint.
Or you can deploy to heroku:
[![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy)
And go to your endpoint /graphiql to see your endpoint
## Concept
In this sample we're implementing a couple of protocols. This exists out of 2 parts. The protocols itself and the implementation.
### The vendored protocols
The 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.
```bash
graphql-protocols-sample-server (master) ∆ tree ./protocols
./protocols
├── contacts
│  └── schema.graphql
├── postbox
│  └── schema.graphql
└── tokens
└── schema.graphql7 directories, 7 files
```You just need to drop them in and extend your `schema.graphql` as done here.
```graphql
type User implements Postbox {
}type Query implements Postbox, Contacts {
messages: [Message!]
contacts: [Contact!]
viewer: User
}type Mutation implements PostboxMutatations, TokenRequestMutations {
sendMessage(message: String): Message
}
```### The implementation
This 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.
```ruby
module Messages
def messages
[{message: "You are all breathtaking!"}]
endmodule Mutations
def sendMessage
{message: "No! YOU are breathtaking!"}
end
end
endmodule Contacts
def contacts
[{name: "Keanu Reeves"}]
end
endclass Query
include Messages
include Contacts
endclass Mutation
include Messages::Mutations
end
```Next, hook them up in your resolver. Aaand done! You now have a GraphQL endpoint that adheres to the vendored protocols! 🙌