Skip to content

Instantly share code, notes, and snippets.

View colinfwren's full-sized avatar

Colin Wren colinfwren

View GitHub Profile
@colinfwren
colinfwren / package.json
Created January 22, 2022 20:12
Package.json for publshing schema and types
{
"name": "@your-org/graphql-schema",
"version": "0.0.1",
"description": "GraphQL Schemas for generating types",
"main": "schema.graphql",
"types": "types.d.ts",
"files": [
"schema.graphql",
"types.d.ts"
]
@colinfwren
colinfwren / codegen.yml
Created January 22, 2022 20:09
GraphQL code gen config
overwrite: true
schema: "schema.graphql"
generates:
./types.d.ts:
plugins:
- "typescript"
- "typescript-operations"
- "typescript-resolvers"
@colinfwren
colinfwren / loadingSchemaFromLib.js
Created January 22, 2022 20:04
Loading GraphQL schema from Library
import {loadTypedefsSync} from "@graphql-tools/load";
import {GraphQLFileLoader} from "@graphql-tools/graphql-file-loader";
const sources = loadTypedefsSync("node_modules/@your-org/graphql-schema/schema.graphql", {
loaders: [new GraphQLFileLoader()],
});
const typeDefs = sources.map((source) => source.document);
const resolvers = {}
@colinfwren
colinfwren / createTestDataForUser.js
Created January 16, 2022 04:49
A Firebase function that will create data and return a JWT for the userId to aid with testing
import * as admin from "firebase-admin";
import axios from "axios";
admin.initializeApp();
const auth = admin.auth();
const FIREBASE_TOKEN = 'This can be found in the firebase console under Web API Key on the settings page'
exports.createTestDataForUser = functions.https.onRequest(async (req, res) => {
const {uid} = req.body;
@colinfwren
colinfwren / FirebaseGraphQLContext.js
Created January 16, 2022 03:13
Using Apollo context within Firebase to get authentication
import * as functions from "firebase-functions";
import * as admin from "firebase-admin";
admin.initializeApp();
const db = admin.firestore();
async function getAuthToken(request) {
if (!request.headers.authorization) {
return null;
}
@colinfwren
colinfwren / apolloOnFirebaseFunctions.ts
Created January 9, 2022 00:09
Run a Apollo Server on Firebase Functions
/**
* Works with [email protected] [email protected] [email protected] [email protected]
* You'll need to add `skipLibCheck` for this to work as cors middleware types seems to have an issue in apollo-server-express
*/
import {ExpressContext, gql} from "apollo-server-express";
import {ApolloServer,Config} from "apollo-server-cloud-functions";
import * as functions from "firebase-functions";
const books = [
@colinfwren
colinfwren / mappingSDKStylestoAPIStyles.js
Created December 17, 2021 17:40
Mapping SDK styles to API Styles
export const colours =[
'#f5f6f8', // grey
'#fff9b1', // yellow
'#f5d128', // dark orange
'#d0e17a', // light green
'#d5f692', // lighter green
'#a6ccf5', // light blue
'#67c6c0', // torquise
'#23bfe7', // blue
'#ff9d48', // orange
@colinfwren
colinfwren / manageUIStateWithLocalStorage.js
Last active December 17, 2021 17:32
Managing UI State with LocalStorage
// In index.js where plugin is initilised
localStorage.setItem('BOTTOM_BAR', 'CLOSED')
localStorage.setItem('SIDEBAR', 'NONE')
miro.onReady(() => {
miro.initialize({
extensionPoints: {
toolbar: {
title: 'Plugin',
async onClick() {
@colinfwren
colinfwren / broadcastDataInMiro.js
Created December 17, 2021 17:17
Working with broadcastData in Miro to communicate between iframes
// createItem action
function createItem(name) {
return {
type: 'CREATE_ITEM',
data: {
name
}
}
}
@colinfwren
colinfwren / openMiroModalWithQueryStrings.js
Created December 17, 2021 17:07
Open Miro Modal with Query Strings
// List item to launch modal to add or edit items
function ListItem({ item }) {
function onEdit(event) {
event.preventDefault()
event.stopPropagation()
miro.board.ui.openModal(`./item-form.html?itemId=${item.id}&name=${item.name}`)
}
return (