0.0
No release in over 3 years
Low commit activity in last 3 years
Automagically generate GraphQL types and queries
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

 Project Readme

AutoGraphQL

Automagically generate GraphQL types and queries for Active Record models

Usage

require 'autographql'


class User < ActiveRecord::Base
  # register this model with AutoGraphQL
  graphql
end

# or only show specific fields
class User < ActiveRecord::Base
  graphql fields: [ :name, :pic ]
end

# or via
AutoGraphQL.register User

# generate query schema
puts GraphQL::Schema::Printer.print_schema(
  GraphQL::Schema.define(query: AutoGraphQL::QueryType)
)

Full Example

require 'active_record'
require 'autographql'

# create in-memory database and connect
ActiveRecord::Base.establish_connection(
  adapter: 'sqlite3',
  database: ':memory:'
)

# set up database schema
ActiveRecord::Schema.define do
  create_table :people do |t|
    t.string :name
  end
end

class Person < ActiveRecord::Base
  # register this model with AutoGraphQL
  graphql
end

# create a person
Person.create(name: 'Daniel')


# use automatically generated query to create a GraphQL schema
class Schema < GraphQL::Schema
  query AutoGraphQL::QueryType
end

# double check your schema
puts GraphQL::Schema::Printer.print_schema(Schema)

# perform a query
query = "
{
  person(id: 1) {
    name
  }
}"

puts 'Daniel' == Schema.execute(query).values.first['person']['name']

Thanks To

Daniel O'Brien: https://github.com/dobs/autographql

Andy Kriger: rmosolgo/graphql-ruby#945