Skip to content

Instantly share code, notes, and snippets.

Giovanni giovannibenussi

Block or report user

Report or block giovannibenussi

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@giovannibenussi
giovannibenussi / App.js
Created Feb 23, 2019
Chat app component
View App.js
import React, { Component } from 'react';
import logo from './logo.svg';
import './App.css';
import { ApolloLink } from 'apollo-link';
import { ApolloClient } from 'apollo-client';
import { ApolloProvider } from 'react-apollo'
import { HttpLink } from 'apollo-link-http';
import { InMemoryCache } from 'apollo-cache-inmemory';
import ActionCable from 'actioncable';
View test_not_null_database_foreign_keys_with_rspec_2.rb
it "can't be saved without an user" do
post = Post.new
post.user = nil
expect { post.save!(validate: false) }.to raise_error ActiveRecord::NotNullViolation
end
View test_not_null_database_foreign_keys_with_rspec_0.rb
class AddUserReferenceToPosts < ActiveRecord::Migration[5.1]
def change
add_reference :posts, :user, foreign_key: true
end
end
View validate-graphql-ruby-4.rb
module Validators
class Model
def self.validate!(args)
validate_presence('name', args[:name])
validate_presence('address', args[:address])
end
end
end
View validate-graphql-ruby-3.rb
module Validators
class GraphqlValidator
def self.validate_presence(attribute, value)
return if value.present?
raise GraphQL::ExecutionError, “You must provide a value for #{attribute}”
end
end
end
View validate-graphql-ruby-2.rb
module Validators
class Model
def self.validate!(args)
unless args[:name].present?
raise GraphQL::ExecutionError, 'You must provide a value for name'
end
unless args[:address].present?
raise GraphQL::ExecutionError, 'You must provide a value for address'
end
end
View validate-graphql-ruby-1.rb
resolve lambda { |_, args, _|
Validators::Model.validate!(args)
Model.find_by(address: args[:address], name: args[:name])
}
View validate-graphql-ruby-0.rb
resolve lambda { |_, args, _|
unless args[:name].present?
raise GraphQL::ExecutionError, 'You must provide a value for name'
end
unless args[:address].present?
raise GraphQL::ExecutionError, 'You must provide a value for address'
end
Model.find_by(address: args[:address], name: args[:name])
}
View data_between_2_collections_in_rails.rb
def index
items_with_images = news_items.each do |item|
item[:image] = UserScope::FetchNewsItem.call(id: params[:id]).news_item.image
end
respond_with items_with_images
end
You can’t perform that action at this time.