Skip to content

Instantly share code, notes, and snippets.

View RyanCCollins's full-sized avatar

Ryan Collins RyanCCollins

View GitHub Profile
@RyanCCollins
RyanCCollins / readme.md
Last active October 1, 2016 04:37
Maybe and other functors JavaScript
var _Maybe = function(val) {
  this.val = val;
}

var map = function(f, obj) {
  return obj.map(f);
}

var Maybe = function(x) {
class ApiController < ApplicationController
def create
query_string = params[:query]
query_variables = ensure_hash(params[:variables])
result = MeetupEventPlannerSchema.execute(
query_string,
variables: query_variables,
context: { }
)
render json: result
@RyanCCollins
RyanCCollins / routes.rb
Created October 11, 2016 23:51
GraphQL, Rails, React
Rails.application.routes.draw do
devise_for :users
mount GraphiQL::Rails::Engine, at: "/graphiql", graphql_path: "/api"
root to: redirect("/graphiql")
resources :api
end
AuthUserType = GraphQL::ObjectType.define do
name 'AuthUser'
description 'The authenticated user model type'
field :id, types.ID, 'The id of this user'
field :name, !types.String, 'The name of the user'
field :email, !types.String, 'The email of the user'
field :bio, types.String, 'The bio of the user'
field :created_at, types.String, 'The datetime string when the user was created'
field :events, types[EventType], 'The user events'
field :avatar, types.String, 'The user avatar'
field :authUser, AuthUserType do
argument :auth_token, !types.String
resolve -> (obj, args, ctx) do
User.find_by(auth_token: args[:auth_token])
end
end
// import dependencies here
class EventsContainer extends Component {
constructor() {
super();
this.handleMore = this.handleMore.bind(this);
}
handleMore() {
const {
actions,
refetch,
field :events, types[EventType] do
argument :first, types.Int
resolve -> (obj, args, ctx) {
events = Event.all.sort_by(&:start_date).reverse
if args[:first]
events = events.first(args[:first])
end
events
}
end
module EventMutations
Create = GraphQL::Relay::Mutation.define do
name 'CreateEvent'
input_field :event, EventInputType
input_field :auth_token, !types.String
return_field :event, EventType
resolve -> (inputs, ctx) do
event_inputs = inputs[:event]
start_date = Date.strptime(event_inputs[:start_date], '%m/%d/%Y').to_datetime
class CreateEvent extends Component {
// ...
handleSubmit() {
const {
actions,
mutate,
fields,
guestList,
user,
} = this.props;
@RyanCCollins
RyanCCollins / UserProfile.js
Last active October 12, 2016 01:51
User profile container, with mutations
class Profile extends Component {
// Removed for brevity. View the whole component
// here: https://github.com/RyanCCollins/meetup-event-planner/tree/master/client/app/src/containers/ProfileContainer
handleSaving() {
const {
updateProfile,
bioInput,
avatarInput,
employerInput,
actions,