Skip to content

Instantly share code, notes, and snippets.

View daniloab's full-sized avatar
🎯
Focusing

Danilo Assis daniloab

🎯
Focusing
View GitHub Profile
@daniloab
daniloab / TeamModel.js
Last active June 12, 2019 17:52
Simple example team model
const teamSchema = new Schema({
name: {
type: String,
required: 'name is required',
},
tradeName: {
type: String,
required: 'trade name is required',
},
taxId: {
@daniloab
daniloab / UserModel.js
Last active June 12, 2019 18:23
Simple example user model
import mongoose from 'mongoose';
const { ObjectId } = mongoose.Schema.Types;
const Schema = mongoose.Schema;
const UserSchema = new Schema({
name: {
type: String,
required: 'name is required',
},
@daniloab
daniloab / PlayerModel.js
Created June 12, 2019 17:58
Simple example player model
const playerSchema = new Schema({
status: {
type: Number
},
name: {
type: String,
required: 'name is required',
},
lastname: {
type: String,
@daniloab
daniloab / App.js
Created June 12, 2019 18:11
Simple example app.js
const graphqlSettingsPerReq = async req => {
const { user } = await getUser(req.header.authorization);
return {
graphiql: process.env.NODE_ENV !== 'production',
schema,
context: {
user,
req,
dataloaders,
@daniloab
daniloab / getUser.js
Created June 12, 2019 18:20
getUser example
export async function getUser (token) {
if (!token) return { user: null }
try {
const decodedToken = jwt.verify(token.substring(4), jwtSecret)
const user = await User.findOne({ _id: decodedToken.id })
return {
user,
@daniloab
daniloab / QueryType.js
Last active March 30, 2021 14:18
Query Me resolver
export default new GraphQLObjectType({
name: 'Query',
description: 'The root of all queries',
fields: () => ({
me: {
type: UserType,
resolve: (root, args, context) => {
if (!context.user) {
return null;
}
if (isCalculating) {
const biggestText = getBiggerTextWidth();
return <span ref={measuredRef}>{biggestText}</span>;
}
const getBiggerTextWidth = () => {
return labels.reduce((acc, cur) => {
if (cur.length >= acc.length) {
return cur;
}
return acc;
}, '');
};
type Props = {
labels: string[];
}
const ScaleButtons = ({labels}:Props) => {
const [isCalculating, setIsCalculating] = useState<boolean>(true);
const [width, setWidth] = useState<number>(0);
const measuredRef = useCallback(node => {
if (node !== null) {
const measuredRef = useCallback(node => {
if (node !== null) {
setWidth(node.getBoundingClientRect().width);
}
return setIsCalculating(false);
}, []);