Skip to content

Instantly share code, notes, and snippets.

View javierfernandes's full-sized avatar

Javier Fernandes javierfernandes

  • Buenos Aires, Argentina
View GitHub Profile
@javierfernandes
javierfernandes / package.json
Last active August 29, 2015 14:17
PdeS -NodeJs - Hola Mundo
{
"name" : "pdes-nodejs-hola-mundo",
"version" : "0.0.1",
"main": "server.js",
"dependencies" : {
"express" : "~3.x"
}
}
@javierfernandes
javierfernandes / 0-kotlin-ext-methods.kt
Last active August 29, 2015 14:22
A demonstration of different usages of Xtend extension methods
fun main(args: Array<String>) {
val i = 1
i.doSomething() // FINE
val s = "string"
s.doSomething() // FINE
val col = linkedListOf(i, s)
col forEach { it.doSomething() } // COMPILATION ERROR
}
@javierfernandes
javierfernandes / Board.rb
Created September 3, 2017 15:12
O3 - Ayuda para TP "SinCity": cálculo de celdas vecinas
class Board
def initialize width, height
@width = width
@height = height
end
def find_neighboring x, y
xrange = neighboring_area(x, @width)
@javierfernandes
javierfernandes / testing-gql-subscriptions-schema.graphql
Last active October 9, 2017 11:15
Sample GraphQL Schema for testing subscriptions Mmedium article
type Object {
project: String
id: Int!
properties: JSON // kind of a mixed type
}
Mutation: {
updateObject(input: UpdateObjectInput) : Object
}
@javierfernandes
javierfernandes / graphql-test-mutation.js
Created October 9, 2017 11:17
Sample GraphQL test for a mutation
describeGQL('GRAPHQL API - Objects()', ({ expectQueryResult }) => {
beforeEach('setup objects in mongo', async () => {
await Object.insertMany([
{ project: 'game', id: 10, data: { name: 'Pato Bullrich' } }
])
})
it('objectUpdate() updates an Object', async () => {
@javierfernandes
javierfernandes / describe-graphql.js
Created October 9, 2017 11:20
describeGraphQL() util method for gql test
import { graphql } from 'graphql'
import mongoose from 'mongoose'
import { Mockgoose } from 'mockgoose'
import '../../src/models/all'
import { expect } from 'chai'
import { compileSchemas } from '../../src/graphql/utils/compileSchema'
const internalDescribeQL = (describeFn) => (title, body) => {
describeFn(title, () => {
import WebSocket from 'ws'
import { SubscriptionClient } from 'subscriptions-transport-ws';
import ApolloClient from 'apollo-client'
const GRAPHQL_ENDPOINT = 'ws://localhost:5000/subscriptions';
describeFn(title, () => {
// context
let schema
let apollo // <<< gets sets in the before()
let networkInterface // <<< same
before(async () => {
// .. old stuff here
// start server
await rtm.start() // << this depends on your server
it('objectUpdated receives an update from calling mutation updateObject() in the same project', async () => {
// SUBSCRIBE and make a promise
const subscriptionPromise = new Promise((resolve, reject) => {
client().subscribe({
query: gql`
subscription objectUpdated {
objectUpdated(project: "game") {
id
property
import { graphql } from 'graphql'
import mongoose from 'mongoose'
import { Mockgoose } from 'mockgoose'
import rtm from '../../src/features/rtm'
import '../../src/models/all'
import { expect } from 'chai'
import { compileSchemas } from '../../src/graphql/utils/compileSchema'
// subscriptiosn
import WebSocket from 'ws'