Permalink
Browse files

Added fields to User, Book, and Query type files

  • Loading branch information...
mattboldt committed Dec 27, 2018
1 parent 8253186 commit e062713d17f8fb65c9d0a4cb31a4014cf795376a
Showing with 23 additions and 8 deletions.
  1. +1 −0 app/graphql/types/book_type.rb
  2. +13 −8 app/graphql/types/query_type.rb
  3. +9 −0 app/graphql/types/user_type.rb
@@ -1,4 +1,5 @@
module Types
class BookType < Types::BaseObject
field :title, String, null: false
end
end
@@ -1,13 +1,18 @@
module Types
class QueryType < Types::BaseObject
# Add root-level fields here.
# They will be entry points for queries on your schema.

# TODO: remove me
field :test_field, String, null: false,
description: "An example field added by the generator"
def test_field
"Hello World!"

field :users, [Types::UserType], null: false

def users
User.all
end

field :user, Types::UserType, null: false do
argument :id, ID, required: true
end

def user(id:)
User.find(id)
end
end
end
@@ -1,4 +1,13 @@
module Types
class UserType < Types::BaseObject
field :id, ID, null: false
field :name, String, null: true
field :email, String, null: true
field :books, [Types::BookType], null: true
field :books_count, Integer, null: true

def books_count
books.size
end
end
end

0 comments on commit e062713

Please sign in to comment.