Skip to content

Instantly share code, notes, and snippets.

View colinfwren's full-sized avatar

Colin Wren colinfwren

View GitHub Profile
@colinfwren
colinfwren / createNodeMutation.graphql
Last active April 17, 2022 22:04
Mutation to create node
"""
Input looks like
{
"input": {
"name": "A new test"
}
}
"""
mutation Mutation($input: [TestCreateInput!]!) {
createTests(input: $input) {
@colinfwren
colinfwren / querySchemaWithConnections.graphql
Created April 17, 2022 21:49
Query schema with connections to get linked nodes
query Query {
products {
name
userStoriesConnection {
edges {
author
node {
name
}
}
@colinfwren
colinfwren / schemaWithConnections.graphql
Created April 17, 2022 21:33
Schema with connections
type Product {
id: ID! @id
name: String
userStories: [UserStory!]! @relationship(type: "DEFINES", properties: 'Defines', direction: IN)
}
type Mockup {
id: ID! @id
name: String
nodeId: String
userStories: [UserStory!]! @relationship(type: "VISUALISES", direction: OUT)
@colinfwren
colinfwren / basicSchemaQuery.graphql
Last active April 17, 2022 21:29
Query to return basic schema data
query Query {
products {
id
name
}
mockups {
id
name
}
userStories {
@colinfwren
colinfwren / basicSchema.graphql
Last active April 17, 2022 21:21
Basic schema for Test Data objects
type Product {
id: ID! @id
name: String
}
type Mockup {
id: ID! @id
name: String
nodeId: String
}
type UserStory {
@colinfwren
colinfwren / test-data.cypher
Last active April 17, 2022 23:07
Test data to add nodes and edges to Neo4J database
// Create Product
CREATE (ChocolateBox:Product {id: 'PRODUCT-1', name:'Chocolate Box'})
// Create Figma mockups
CREATE (LandingPage:Mockup {id: 'MOCKUP-1', name:'Landing Page', nodeId:'424:1224'})
CREATE (ChocolatePLP:Mockup {id: 'MOCKUP-2', name:'Chocolate PLP', nodeId:'424:1233'})
CREATE (FlowerPLP:Mockup {id: 'MOCKUP-4', name:'Flower PLP', nodeId:'424:1242'})
// Create User Stories
CREATE (ViewFlowersList:UserStory {id:'USER-STORY-1', name:'Customer Views Flowers Product List'})
@colinfwren
colinfwren / server.js
Created April 17, 2022 21:08
Setting up Neo4J GraphQL server
import { gql, ApolloServer } from 'apollo-server'
import { Neo4jGraphQL } from '@neo4j/graphql'
import neo4j from 'neo4j-driver'
const typeDef = gql``; // Type Defs for schema
const driver = neo4j.driver(
'http://localhost:7687', // Bolt URL for Neo4J
neo4j.auth.basic('neo4j', 's3cr3t') // Username & password for Neo4J
);
@colinfwren
colinfwren / PersistingPluginState.jsx
Created February 12, 2022 00:39
Persisting Figma Plugin State
// main.js
import {emit, on, once, showUI, loadSettingsAsync, saveSettingsAsync} from '@create-figma-plugin/utilities'
const defaultPluginState = {
foo: 'bar'
}
export default function () {
on('SAVE_PLUGIN_STATE', async (pluginState) => {
await saveSettingsAsync(pluginState, 'PLUGIN_STATE')
@colinfwren
colinfwren / FigmaPluginUIEventHandler.jsx
Created February 11, 2022 23:26
Handling events from Main context in UI context
// main.js
import {emit, showUI} from '@create-figma-plugin/utilities'
export default function () {
figma.on('selectionchange', () => {
// convert current selection to nodes (passing raw SceneNode would result in just node ID being passed)
const nodes = figma.currentPage.selection.map((node) => {
return {
id: node.id,
name: node.name
@colinfwren
colinfwren / FigmaPluginBasicEventHandler.jsx
Created February 11, 2022 23:15
Basic Handler Example for Figma Plugin
// main.js
import {on, showUI} from '@create-figma-plugin/utilities'
export default function () {
on('HIDE_ALL', (args) => {
const allNodes = figma.currentPage.children.slice()
allNodes.map((node) => {
node.visible = false
})
figma.closePlugin()