Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Books
- belongs_to :user
- end
- class Users
- has_many :books
- end
- first_name
- last_name
- email
- author
- title
- description
- Types::BookType = GraphQL::ObjectType.define do
- name 'Book'
- field :id, !types.ID
- field :author, !types.String
- field :title, !types.String
- field :user, -> {Types::UserType}, property: :user
- end
- Types::UserType = GraphQL::ObjectType.define do
- name 'User'
- field :id, !types.ID
- field :first_name, !types.String
- field :last_name, !types.String
- field :email, !types.String
- end
- Types::MutationType = GraphQL::ObjectType.define do
- name 'Mutation'
- field :bookCreate, function: Resolvers::BookCreate.new
- end
- class Resolvers::BookCreate < GraphQL::Function
- argument :author, !types.String
- argument :title, !types.String
- argument :description, !types.String
- argument :user, !types.Int
- type Types::BookType
- def call(_obj, args, _ctx)
- Book.create!(
- author: args[:author],
- title: args[:title],
- description: args[:description],
- user: args[:user]
- )
- end
- end
- mutation book {
- bookCreate(
- author: "Test",
- title: "Book Test",
- description: "Book Description",
- user: 2) {
- id
- author
- title
- description
- }
- }
- <ActiveRecord::AssociationTypeMismatch: User(#69982231587660) expected, got 2 which is an instance of Integer(#11387600)>
Add Comment
Please, Sign In to add comment