# app/graphql/types/objects/document_type.rb module Mutations class CreateDocument < BaseMutation description "creates a document for the user in the system" argument :doc, ApolloUploadServer::Upload, required: true field :document, Types::Objects::DocumentType, null: false def resolve(doc:) authenticate_user user = context[:current_user] document = user.documents.build(doc: doc) if document.save return {document: document} else raise GraphQL::ExecutionError.new(document.errors.full_messages.join(', ')) end end end end