Skip to content

Instantly share code, notes, and snippets.

View xuorig's full-sized avatar

Marc-Andre Giroux xuorig

View GitHub Profile
class ExceptFilter
def self.call(schema_member, context)
if schema_member.name == "someField"
return context[:some_beta_feature]
end
if schema_member.name == "bankAccount"
return context[:current_user].hasAccessToBankAccount?
end
# Execute a query with an `except` or `only` argument
MySchema.execute(query_string, except: ExceptFilter)
# The except argument here takes any object that responds to call with two arguments:
# schema_member: a member from your schema. It may be a Field, ObjectType, Argument, etc.
# context: The Query Context
class ExceptFilter
def self.call(schema_member, context)
# true if field should be excluded, false if it should be included
module Graph
module Types
Query = GraphQL::ObjectType.define do
name "Query"
description "The query root of this schema"
field :film, Graph::Types::Film do
argument :id, !types.ID
resolve ->(_, args, _) { Film.find_by(id: args[:id]) }
end
module Graph
module Types
Film = GraphQL::ObjectType.define do
name "Film"
description "A single film."
field :title, !types.String, "The title of this film"
end
end
end
query {
firstFilm: film(id: "1") {
title
}
secondFilm: film(id: "2") {
title
}
}
@xuorig
xuorig / RPMNewRelic.markdown
Created October 7, 2016 18:18
RPM New Relic

NewRelic's RPM

Main classes/modules

  • NewRelic::Agent
  • NewRelic::Agent::Agent
  • NewRelic::Agent::EventListener
  • NewRelic::Agent::Harvester
  • NewRelic::Agent::EventLoop
  • NewRelic::Agent::Threading::AgentThread
@xuorig
xuorig / Puma.md
Last active August 15, 2016 01:41

puma/lib/rack/handler/puma.rb

  • Defines the handler (takes App and conf as args)
  • Sets up a new laucher with conf and events

puma/lib/puma/launcher.rb

  • Runs #run, starts the server

puma/lib/puma/single.rb < puma/lib/puma/runner.rb

  • Runs #run on the "runner"
  • Loads the App @launcher.config.app
// Sample ActionCable ES6 client
//
// To be used like:
//
// const myEventHandlerFunction = (event) => {
// console.log(event.message);
// }
//
// ActionCableClient.connect(
// 'ws://localhost:3000/cable',
// PROTOTYPAL INHERITANCE
// In prototypal languages you only have objects. No classes!
// ex nihilo
const object = Object.create(null);
console.log(object);
module Mutations
class MarkPullRequestAsReviewed < Graph::Relay::Mutation
class Resolver
class << self
def call(obj, args, ctx)
pr = PullRequest.find(args["pullRequestId"])
pr.update!(reviewed: true)
{ pullRequest: pr }
end
end