relay-rails-blog icon indicating copy to clipboard operation
relay-rails-blog copied to clipboard

generate schema.json

Open yumikohey opened this issue 8 years ago • 3 comments

If I remove schema.json, what command should I run to generate a new schema.json file?

yumikohey avatar Mar 20 '17 03:03 yumikohey

@yumikohey Sure, please checkout this file - https://github.com/gauravtiwari/relay-rails-blog/blob/master/app/api/relay_schema.rb#L54

At the moment, whenever you load your rails server the schema will be auto-generated using a middleware - https://github.com/gauravtiwari/relay-rails-blog/blob/master/lib/graphql_reloader.rb, which is added to application.rb https://github.com/gauravtiwari/relay-rails-blog/blob/master/config/application.rb#L14

However, if you manually want to generate a schema or want to see how things works, then please run this command in the rails c or in your code -

RelaySchema.execute GraphQL::Introspection::INTROSPECTION_QUERY

where Schema is the name of your graphql Schema, for example in this demo app I have used Relay Schema https://github.com/gauravtiwari/relay-rails-blog/blob/master/app/api/relay_schema.rb#L1

On client side there is a babel plugin for loading schema without any extra code - https://github.com/gauravtiwari/relay-rails-blog/blob/master/client/package.json#L68 https://github.com/gauravtiwari/relay-rails-blog/blob/master/client/package.json#L47

gauravtiwari avatar Mar 20 '17 04:03 gauravtiwari

@gauravtiwari Thank you so much for your instant response. I am playing around with your project for couple days. Besides devise, I didn't see many features are building with Rails. Could you tell me the upsides to develop a project with Rails and Relay?

Thanks

yumikohey avatar Mar 20 '17 04:03 yumikohey

@yumikohey No problem 👍 Great, no you got it right for this type of small'ish project there isn't many benefits, given the work involved. However, if you intend to build a large API project where you have multiple client using the API then you can build the API in graphql (with or without Rails) and build multiples clients - web(relay or apollo), mobile (react-native or apollo-ios wrapper) etc.

Also, Relay or Apollo works pretty good for SPA where you have many features on a single page. For ex - A mailbox - where you got messages, conversations, replies and various types of mailbox folders etc. You can have multiple single page like features in an app too. For ex - in an e-commerce app where you have orders, billing, payments etc.

Official docs here - https://facebook.github.io/relay/

Just build something and see how that feels to you 👍

gauravtiwari avatar Mar 20 '17 11:03 gauravtiwari