Skip to content

Instantly share code, notes, and snippets.

View tothandras's full-sized avatar

András Tóth tothandras

View GitHub Profile
@tothandras
tothandras / hooks.js
Last active November 16, 2015 08:51
hooks.js
const filter = new BadWordsFilter();
const hooks = {
mutation: {
pre: (next, todo, ...rest) => {
if (todo.text) {
todo.text = filter.clean(todo.text);
}
next(todo, ...rest);
}
@tothandras
tothandras / graffiti.js
Created November 10, 2015 10:19
Graffiti
import express from 'express';
import graffiti from '../';
import schema from './schema';
const app = express();
app.use(graffiti.express({
schema
}));
app.listen(3001, (err) => {
@tothandras
tothandras / schema.js
Created November 10, 2015 10:19
GraphQL schema
import mongoose from 'mongoose';
import User from './user';
import Pet from './pet';
import {getSchema} from '@risingstack/graffiti-mongoose';
mongoose.connect(process.env.MONGO_URI || 'mongodb://localhost/graphql');
export default getSchema([Pet, User]);
@tothandras
tothandras / Pet.js
Created November 10, 2015 10:18
Mongoose schema
import mongoose from 'mongoose';
const PetSchema = new mongoose.Schema({
name: {
type: String
},
type: {
type: String
},
age: {
@tothandras
tothandras / FixName
Created November 10, 2015 10:17
FixName
mutation FixName {
updateUser(input: {clientMutationId: "2", id: "VXNlcjo1NjQwYTJiNTU1MzBmOGFhNTBlM2NkNGQ=", name: "New User"}) {
changedUser {
name
}
}
}
@tothandras
tothandras / AddUser
Created November 10, 2015 10:17
AddUser
mutation AddUser {
addUser(input: {clientMutationId: "1", name: "New Usr"}) {
changedUserEdge {
node {
id
name
createdAt
}
}
}
@tothandras
tothandras / UsersPagination
Created November 10, 2015 10:16
UsersPagination
query UsersPagination {
viewer {
users(first: 2, after: "Y29ubmVjdGlvbi41NjQwOWMwZjU1MzBmOGFhNTBlM2NjZWE=") {
count
edges {
cursor
node {
name
}
}
@tothandras
tothandras / ConnectionTypeIntrospection
Created November 10, 2015 10:16
ConnectionTypeIntrospection
query ConnectionTypeIntrospection {
__type(name: "UserConnection") {
name
fields {
name
type {
kind
ofType {
name
kind
@tothandras
tothandras / ReFetch
Last active November 10, 2015 10:14
ReFetch
query ReFetch {
node(id: "VXNlcjo1NjQwOThlNTI3ZjUyYTg0NTBiNWE5NDQ=") {
__typename
... on User {
name
age
}
}
}
@tothandras
tothandras / user.js
Last active October 25, 2018 11:55
user.js
import mongoose from 'mongoose';
const UserSchema = new mongoose.Schema({
name: {
type: String
},
age: {
type: Number,
index: true
},