Skip to content

Instantly share code, notes, and snippets.

@harigopal
Last active November 10, 2019 09:50
Show Gist options
  • Save harigopal/d6a8c4e27e1df99c7ef84db39b9b5e5e to your computer and use it in GitHub Desktop.
Save harigopal/d6a8c4e27e1df99c7ef84db39b9b5e5e to your computer and use it in GitHub Desktop.
Conventions for setting up a GraphQL Server on Rails - Schema & QueryType
# app/graphql/my_rails_app_schema.rb
class MyRailsAppSchema < GraphQL::Schema
mutation(Types::MutationType)
query(Types::QueryType)
end
# app/graphql/types/query_type.rb
module Types
class QueryType < Types::BaseObject
# Add root-level fields here. They will be entry points for queries on your schema.
field :test_field, String, null: false, description: "An example field added by the generator"
# A method with the same name as the field will be called when that field is asked for in a query.
def test_field
"Hello World!"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment