Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jeantessier/martian-library
A sample Ruby on Rails application with a GraphQL API (from a tutorial)
https://github.com/jeantessier/martian-library
Last synced: about 1 month ago
JSON representation
A sample Ruby on Rails application with a GraphQL API (from a tutorial)
- Host: GitHub
- URL: https://github.com/jeantessier/martian-library
- Owner: jeantessier
- Created: 2019-11-28T02:48:49.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2024-04-25T22:55:11.000Z (8 months ago)
- Last Synced: 2024-04-26T00:13:31.639Z (8 months ago)
- Language: Ruby
- Homepage: https://evilmartians.com/chronicles/graphql-on-rails-1-from-zero-to-the-first-query
- Size: 1.03 MB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Martian Library
Following [this tutorial](https://evilmartians.com/chronicles/graphql-on-rails-1-from-zero-to-the-first-query).
* Ruby version: `2.7.2`
* Rails version: `6.0.3.4`## MySQL
This command will create a new database named
`martian_library_development` and populate it with seed data.```bash
$ bin/rails db:setup
```## Running the Tests
You can run all the tests with:
```bash
$ bundle exec rspec
```## Running the Server
You can start the application with:
```bash
$ bin/rails server
```And use the base URL http://localhost:3000.
You can issue GraphQL queries with http://localhost:3000/graphiql.
## Sample Queries
### See All Users
```graphql
query GetUsers {
users {
id
fullName
}
}
```Or just:
```graphql
{
users {
id
fullName
}
}
```### See A Specific User
```graphql
query GetUserById($userId: ID) {
users(userId: $userId) {
id
fullName
}
}
```with variables:
```json
{"userId": 1}
```### See All Items
```graphql
query GetItems {
items {
title
description
user {
fullName
}
}
}
```Or just:
```graphql
{
items {
title
description
user {
fullName
}
}
}
```### See Items Belonging To A User
```graphql
query GetItemsForUser($forUser: ID) {
items(forUser: $forUser) {
title
description
user {
fullName
}
}
}
```with variables:
```json
{"forUser": 1}
```## Extracting the Schema
This will write the schema as
GraphQL Schema Language to `app/graphql/martian_library_schema.graphql`.```bash
$ bin/rails graphql:schema:idl
```This will write the schema as
GraphQL Schema Language to `app/graphql/martian_library_schema.graphql`
and as
JSON to `app/graphql/martian_library_schema.json`.```bash
$ bin/rails graphql:schema:dump
```