Skip to content

Instantly share code, notes, and snippets.

@bloo
bloo / Resilient Tech Blog - Building Forms with Formstack and React - foreach.ts
Created May 5, 2021 15:36
Resilient Tech Blog - Building Forms with Formstack and React - foreach.ts
export const nestFieldsInSections = (fields: FieldBase[]): FieldBase[] => {
const sections: FieldBase[] = []
fields.forEach((field) => {
if (field.type === 'section') {
field.subfields = []
sections.push(field)
} else if (field.type === 'embed') {
const metadata: Embed = JSON.parse(field.section_text)
sections[sections.length - 1].metadata = metadata
} else {
@bloo
bloo / Resilient Tech Blog - Building Forms with Formstack and React - axios.ts
Created May 5, 2021 15:36
Resilient Tech Blog - Building Forms with Formstack and React - axios.ts
const response = await axios({
method: 'GET',
url: `${formstackBaseUrl}/form/${formId}?oauth_token=${formstackToken}`,
})
@bloo
bloo / Resilient Tech Blog - Code-first GraphQL with Nexus - app.ts
Created April 7, 2021 15:05
Resilient Tech Blog - Code-first GraphQL with Nexus - app.ts
import { ApolloServer } from 'apollo-server'
import { PrismaClient } from '@prisma/client'
import { schema } from './schema'
const prismaClient = new PrismaClient()
const server = new ApolloServer({
schema,
// context is a function that is invoked on every GraphQL request.
context: () => ({
@bloo
bloo / Resilient Tech Blog - Code-first GraphQL with Nexus - budget objectType.ts
Created April 7, 2021 15:04
Resilient Tech Blog - Code-first GraphQL with Nexus - budget objectType.ts
// schema.ts
import { makeSchema, asNexusMethod } from 'nexus'
import { nexusPrisma } from 'nexus-plugin-prisma'
import { DateTimeResolver } from 'graphql-scalars'
import path from 'path'
// This is types we had created
import * as types from './typeDefs'
@bloo
bloo / Resilient Tech Blog - Code-first GraphQL with Nexus - budget objectType.ts
Created April 7, 2021 15:01
Resilient Tech Blog - Code-first GraphQL with Nexus - budget objectType.ts
export const budget = objectType({
name: BUDGET,
definition(t) {
t.model.id()
t.model.name()
t.model.amount()
t.model.fiscalYearStart()
t.model.fiscalYearEnd()
},
})
@bloo
bloo / Resilient Tech Blog - Code-first GraphQL with Nexus - typegen-nexus import example.ts
Last active April 7, 2021 15:01
Resilient Tech Blog - Code-first GraphQL with Nexus - typegen-nexus import example.ts
import type { NexusGenAllTypes, NexusGenFieldTypes } from 'typegen-nexus'
type Nonprofit = NexusGenAllTypes['Nonprofit']
type GetAllNonprofit = NexusGenFieldTypes['Query']['getAllNonprofit']
@bloo
bloo / Resilient Tech Blog - Code-first GraphQL with Nexus - typeDefs.ts
Last active April 7, 2021 15:01
Resilient Tech Blog - Code-first GraphQL with Nexus - typeDefs.ts
// typeDefs.ts
import { objectType, extendType, enumType } from 'nexus'
import { NonprofitType } from '@prisma/client'
const NONPROFIT = 'Nonprofit'
const BUDGET = 'Budget'
const NONPROFIT_TYPE = 'NonprofitType'
export const nonprofit = objectType({
@bloo
bloo / Resilient Tech Blog - Code-first GraphQL with Nexus - Prisma Import Example.ts
Last active April 7, 2021 15:02
Resilient Tech Blog - Code-first GraphQL with Nexus - Prisma Import Example.ts
// example.ts
// files you need to reference the type in your database
import type { Nonprofit, Budget, NonprofitType } from '@prisma/client'
@bloo
bloo / Resilient Tech Blog - Code-first GraphQL with Nexus - prisma.schema
Last active April 7, 2021 15:00
Resilient Tech Blog - Code-first GraphQL with Nexus - prisma.schema
// prisma.schema
generator prisma_client {
provider = "prisma-client-js"
binaryTargets = ["native"]
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
@bloo
bloo / update_cluster.sh
Last active March 20, 2018 21:13
Upgrade an entire Docker Swarm cluster's `docker.service` settings
#!/bin/sh
pem=${1}
shift
nodes="${@}"
if [ -z ${pem} ] || [ -z "${nodes}" ]; then
echo "Usage `basename ${0}` <pem-file> <ip1> <ip2> .."
exit 1
fi