GRRR
Creating a GraphQL Rails, React, Relay application
Install / Use
/learn @Tonkpils/GRRRREADME
How to setup an app with GraphQL, Rails, React, Relay
Generate a new app
-
run
rails new APP_NAME --webpack=react --database=postgresql --skip-test --skip-coffee- --skip-test, --database, and --skip-coffee is optional
-
add
react-railsto Gemfile -
add
graphqlto Gemfile -
run
bundle install -
run
rails g graphql:install -
run
rails g react:install -
run
yarn add react-relay@^1.0.0 -
run
yarn add relay-compiler@^1.0.0 babel-plugin-relay@^1.0.1 --dev -
add
<%= javascript_pack_tag 'application' %>toapp/views/layouts/application.html.erb -
add
<%= stylesheet_pack_tag 'application' %>toapp/views/layouts/application.html.erb -
move
app/javascript/packs/hello_react.jsxtoapp/javascript/components/hello_react.jsx -
modify the generated GraphQL schema file which should be under
app/graphql/app_name_schema.rbAppNameSchema = GraphQL::Schema.define do query(Types::QueryType) end module RelaySchemaHelpers # Schema.json location SCHEMA_DIR = Rails.root.join('app/javascript/packs/') SCHEMA_PATH = File.join(SCHEMA_DIR, 'schema.json') def execute_introspection_query # Cache the query result Rails.cache.fetch checksum do AppNameSchema.execute GraphQL::Introspection::INTROSPECTION_QUERY end end def checksum files = Dir['app/graphql/**/*.rb'].reject { |f| File.directory?(f) } content = files.map { |f| File.read(f) }.join Digest::SHA256.hexdigest(content).to_s end def dump_schema # Generate the schema on start/reload FileUtils.mkdir_p SCHEMA_DIR result = JSON.pretty_generate(AppNameSchema.execute_introspection_query) unless File.exist?(SCHEMA_PATH) && File.read(SCHEMA_PATH) == result File.write(SCHEMA_PATH, result) end end end AppNameSchema.extend RelaySchemaHelpers -
Add the following to .babelrc
[ "relay", { "schema": "app/javascript/packs/schema.json", "debug": true } ], -
add
__generated__/to.gitignore -
create a
Procfilewith the following contentsweb: bundle exec puma -t 5:5 -p ${PORT:-3000} -e ${RACK_ENV:-development} relay: yarn run relay -- --watch webpacker: ./bin/webpack-dev-server -
add the following as a script in
package.json"relay": "relay-compiler --src ./app/javascript --schema ./app/javascript/packs/schema.json" -
create a controller action and in the view you can now render your
hello_reactcomponent<%= react_component 'hello_react' %>
Related Skills
bluebubbles
346.8kUse when you need to send or manage iMessages via BlueBubbles (recommended iMessage integration). Calls go through the generic message tool with channel="bluebubbles".
node-connect
346.8kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
slack
346.8kUse when you need to control Slack from OpenClaw via the slack tool, including reacting to messages or pinning/unpinning items in Slack channels or DMs.
frontend-design
107.6kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
Security Score
Audited on Dec 16, 2021
