Skip to content

Instantly share code, notes, and snippets.

import React, { Component, PropTypes } from 'react';
import $ from 'jquery';
const BUMP_URL = (id) => `/bump/${id}`;
export default class Avatar extends Component {
static props = {
userId: PropTypes.string.isRequired,
name: PropTypes.string.isRequired,
avatar_url: PropTypes.string.isRequired,
import initStoryshots from 'storyshots';
initStoryshots();
const resolvers = {
TypeName: {
resolver(doc, args, { user }) {
if (!user || !user.admin) {
throw new Error("Admin access required");
}
/* original implementation */
},
},
const onLogin = async function(serverUrl, email, password) {
const response = await fetch(`${serverUrl}/login`, {
method: 'POST',
body: JSON.stringify({ email, password }),
headers: { 'Content-Type': 'application/json' },
});
const data = await response.json();
token = data.token;
localStorage.setItem(KEY, token);
}
const resolvers = {
/* ... */
Query: {
/* ... */
me(root, args, { user }) {
return user;
},
},
extend type Query {
users(lastCreatedAt: Float, limit: Int): [User!]
user(id: ObjID!): User
me: User
}
@tmeasday
tmeasday / index.js
Last active September 27, 2019 02:28
// This is a hard-coded value obtained via cURL, but in a real app
// you would read this from local storage (with localStorage.getItem(..))
// and set it on the `onLogin` handler.
let token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VySWQiOiI1OGNlMThmNTAyMjZiODZlYmY4YTNjN2UifQ.94L8T58sxT4QHEduQnYVl_V3JrT0E6eGwrEJyu_0BDo";
const networkInterface = createNetworkInterface({
uri: `${REACT_APP_API_HOST}/graphql`,
});
networkInterface.use([
{
mutation {
createUser(input:{
email: "[email protected]",
password: "testpassword",
hasGitHubToken:false,
hasTrelloToken: false
}) {
id
}
}
import bcrypt from 'bcrypt';
const SALT_ROUNDS = 10;
export default class User {
/* ... */
async insert(doc) {
const { password, ...rest } = doc;
const hash = await bcrypt.hash(password, SALT_ROUNDS);
input CreateUserInput {
email: String!
password: String!
hasGitHubToken: Boolean!
hasTrelloToken: Boolean!
}