Skip to content

Commit ba7cc96

Browse files
committed
Add Rails server
1 parent 39c8db8 commit ba7cc96

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+1558
-7
lines changed

README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
This is a copy of `urql`'s stream example, with the server ported to ruby (`server/server.rb`)
1+
This is a copy of `urql`'s stream example, with the server ported to Sinatra (`server/server.rb`) and Rails `stream_server/`
22

33
Install dependencies:
44

@@ -12,12 +12,20 @@ To start the javascript server:
1212
yarn run start
1313
```
1414

15-
Or, to start the Ruby server:
15+
Or, to start the Sinatra server:
1616

1717
```
1818
yarn run startruby
1919
```
2020

21+
Or, to start the Rails server:
22+
23+
```
24+
cd stream_server
25+
rails server
26+
# Run the JS client separately as described below
27+
```
28+
2129
Alternatively, start the client with `yarn run vite`, then start the JS server with `node server/index.js` or the Ruby server with `ruby server/server.rb`.
2230

2331
### Caveats

server/server.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
require "bundler/inline"
22

33
gemfile do
4-
gem "graphql", "1.13.6", path: "~/code/graphql-ruby"
5-
gem "graphql-pro", "1.21.1", path: "~/code/graphql-pro"
4+
gem "graphql", "1.13.6"
5+
gem "graphql-pro", "1.21.1"
66
gem "sinatra"
77
gem "sinatra-contrib"
88
gem "sinatra-cross_origin"
@@ -16,7 +16,7 @@ class Alphabet < GraphQL::Schema::Object
1616
field :char, String
1717

1818
def char
19-
sleep 0.5
19+
# sleep 0.5
2020
object[:char]
2121
end
2222
end
@@ -31,7 +31,7 @@ def first_verse
3131
field :second_verse, String
3232

3333
def second_verse
34-
sleep 5
34+
# sleep 5
3535
"Next time won't you sing with me"
3636
end
3737
end
@@ -120,6 +120,7 @@ class App < Sinatra::Base
120120
puts Time.now.to_i
121121
puts text.inspect
122122
out << text
123+
sleep 0.1
123124
end
124125
end
125126
else

src/Songs.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const LocationsList = () => {
3535
});
3636

3737
const { data } = result;
38-
console.log("now", Date.now())
38+
console.log("now", Date.now(), data && data.alphabet)
3939
return (
4040
<div>
4141
{data && (

stream_server/.gitattributes

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# See https://git-scm.com/docs/gitattributes for more about git attribute files.
2+
3+
# Mark the database schema as having been generated.
4+
db/schema.rb linguist-generated
5+
6+
# Mark any vendored files as having been vendored.
7+
vendor/* linguist-vendored

stream_server/.gitignore

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# See https://help.github.com/articles/ignoring-files for more about ignoring files.
2+
#
3+
# If you find yourself ignoring temporary files generated by your text editor
4+
# or operating system, you probably want to add a global ignore instead:
5+
# git config --global core.excludesfile '~/.gitignore_global'
6+
7+
# Ignore bundler config.
8+
/.bundle
9+
10+
# Ignore the default SQLite database.
11+
/db/*.sqlite3
12+
/db/*.sqlite3-*
13+
14+
# Ignore all logfiles and tempfiles.
15+
/log/*
16+
/tmp/*
17+
!/log/.keep
18+
!/tmp/.keep
19+
20+
# Ignore pidfiles, but keep the directory.
21+
/tmp/pids/*
22+
!/tmp/pids/
23+
!/tmp/pids/.keep
24+
25+
# Ignore uploaded files in development.
26+
/storage/*
27+
!/storage/.keep
28+
/tmp/storage/*
29+
!/tmp/storage/
30+
!/tmp/storage/.keep
31+
32+
/public/assets
33+
34+
# Ignore master key for decrypting credentials and more.
35+
/config/master.key

stream_server/.ruby-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.0.2

stream_server/Gemfile

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
source "https://rubygems.org"
2+
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
3+
4+
ruby "3.0.2"
5+
6+
# Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main"
7+
gem "rails", "~> 7.0.1"
8+
9+
# The original asset pipeline for Rails [https://github.com/rails/sprockets-rails]
10+
gem "sprockets-rails"
11+
12+
# Use sqlite3 as the database for Active Record
13+
gem "sqlite3", "~> 1.4"
14+
15+
# Use the Puma web server [https://github.com/puma/puma]
16+
gem "puma", "~> 5.0"
17+
18+
# Use JavaScript with ESM import maps [https://github.com/rails/importmap-rails]
19+
gem "importmap-rails"
20+
21+
# Hotwire's SPA-like page accelerator [https://turbo.hotwired.dev]
22+
gem "turbo-rails"
23+
24+
# Hotwire's modest JavaScript framework [https://stimulus.hotwired.dev]
25+
gem "stimulus-rails"
26+
27+
# Build JSON APIs with ease [https://github.com/rails/jbuilder]
28+
gem "jbuilder"
29+
30+
# Use Redis adapter to run Action Cable in production
31+
gem "redis", "~> 4.0"
32+
33+
# Use Kredis to get higher-level data types in Redis [https://github.com/rails/kredis]
34+
# gem "kredis"
35+
36+
# Use Active Model has_secure_password [https://guides.rubyonrails.org/active_model_basics.html#securepassword]
37+
# gem "bcrypt", "~> 3.1.7"
38+
39+
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
40+
gem "tzinfo-data", platforms: %i[ mingw mswin x64_mingw jruby ]
41+
42+
# Reduces boot times through caching; required in config/boot.rb
43+
gem "bootsnap", require: false
44+
45+
# Use Sass to process CSS
46+
# gem "sassc-rails"
47+
48+
# Use Active Storage variants [https://guides.rubyonrails.org/active_storage_overview.html#transforming-images]
49+
# gem "image_processing", "~> 1.2"
50+
51+
group :development, :test do
52+
# See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
53+
gem "debug", platforms: %i[ mri mingw x64_mingw ]
54+
end
55+
56+
group :development do
57+
# Use console on exceptions pages [https://github.com/rails/web-console]
58+
gem "web-console"
59+
60+
# Add speed badges [https://github.com/MiniProfiler/rack-mini-profiler]
61+
# gem "rack-mini-profiler"
62+
63+
# Speed up commands on slow machines / big apps [https://github.com/rails/spring]
64+
# gem "spring"
65+
end
66+
67+
group :test do
68+
# Use system testing [https://guides.rubyonrails.org/testing.html#system-testing]
69+
gem "capybara"
70+
gem "selenium-webdriver"
71+
gem "webdrivers"
72+
end
73+
74+
gem "graphql", "~> 1.13"
75+
gem "graphql-pro", "1.21.2", source: "https://gems.graphql.pro"
76+
gem "graphiql-rails", group: :development
77+
78+
gem "rack-cors", "~> 1.1"

0 commit comments

Comments
 (0)