Code Monkey home page Code Monkey logo

intro-graphql-talk-ruby's Introduction

intro-graphql-talk-ruby

A simple bare-bones Rails app that was demoed at the 2018-03-27 Ann Arbor Ruby meetup for the purposes of getting started with the GraphQL Ruby gem.

Slides

Getting Started

Going commit-by-commit demonstrates how to install dependencies and scaffold the GraphQL API for your own app. To run this app, having Docker is the easiest route (e.g., Docker for Mac). With docker-compose you can get the app running via:

git clone https://github.com/andrewsardone/intro-graphql-talk-ruby
cd intro-graphql-talk-ruby
docker-compose build web
docker-compose run web bin/setup
docker-compose up

Visit the GraphiQL API explorer at https://localhost:3000/graphiql.

Sample App

Inspired by How to GraphQL's Ruby tutorial, the app is intended to be a Pinboard-style bookmark manager. There isn't any browser user interface, but solely an exposed GraphQL API that's explorable via GraphiQL:

The model layer consists of bookmarks and tags:

shell> bin/rails console
pry(main)> show-models
ApplicationRecord
  Table doesn't exist
Bookmark
  id: integer
  name: string
  url: string
  created_at: datetime
  updated_at: datetime
  has_many :taggings
  has_many :tags (through :taggings)
Tag
  id: integer
  name: string
  created_at: datetime
  updated_at: datetime
  has_many :bookmarks (through :taggings)
  has_many :taggings
Tagging
  id: integer
  bookmark_id: integer
  tag_id: integer
  created_at: datetime
  updated_at: datetime
  belongs_to :bookmark
  belongs_to :tag

And our GraphQL API exposes those types:

# A pinnable bookmark, i.e., a named URL
type Bookmark {
  id: ID!
  name: String!
  tags: [Tag]
  url: String!
}

# Autogenerated input type of CreateBookmark
input CreateBookmarkInput {
  # A unique identifier for the client performing the mutation.
  clientMutationId: String
  name: String!
  url: String!
  tags: [String!]
}

# Autogenerated return type of CreateBookmark
type CreateBookmarkPayload {
  bookmark: Bookmark

  # A unique identifier for the client performing the mutation.
  clientMutationId: String
}

type Mutation {
  createBookmark(input: CreateBookmarkInput!): CreateBookmarkPayload

  # An example field added by the generator
  testField: String
}

type Query {
  # A root collection of all Bookmarks
  bookmarks: [Bookmark]!

  # An example field added by the generator
  testField: String
}

type Tag {
  bookmarks: [Bookmark]
  id: ID!
  name: String!
}

intro-graphql-talk-ruby's People

Contributors

andrewsardone avatar

Watchers

 avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.