Skip to content

Instantly share code, notes, and snippets.

@prop(
"user",
fragment on User {
id, firstName, lastName
comments: ...UserComments
}
)
function MyComponent({ user }) {
return <UserComments comments={user.comments}>
@vladar
vladar / bench.js
Created July 7, 2021 17:47
Sorting data with lmdb-store
console.time(`lmdb-init`)
const { open } = require("lmdb-store")
const store = open({
name: `store`,
path: process.cwd() + `/test`,
})
const db = store.openDB({
name: `db`,
})
@vladar
vladar / gc-test.js
Last active April 28, 2021 21:44
Testing garbage collection with `lmdb-store` using `cache` option
// node --expose-gc gc-test.js
// CACHE=1 node --expose-gc gc-test.js
const { open } = require("lmdb-store")
const ptop = require("process-top")()
let rootDb
function getRootDb() {
if (!rootDb) {
rootDb = open({
name: `root`,
@vladar
vladar / example.js
Last active April 3, 2021 12:36
Dynamic nested connections in GraphQL
const query = graphql`
{
allFoo(filter: { foo: { eq: "foo" }}) {
nodes {
id
foo
fooBars @connect(field: "allBar", filter: { fooId: { eq: this__id } }) {
nodes {
bar
}
@vladar
vladar / gatsby-node.js
Created September 7, 2020 14:52
onPreInit bug
exports.onPreInit = (gatsbyApi, pluginOptions) => {}
exports.sourceNodes = async (gatsbyApi) => {
const {cache, reporter} = gatsbyApi
reporter.info('Testing cache');
reporter.info(await cache.get('test'));
reporter.info('Setting cache');
await cache.set('test', 'someValue');
reporter.info('Checking if set succesfully');
reporter.info(await cache.get('test'));
query {
mapleton: allFile(filter: { sourceInstanceName: { eq: "mapleton" } }) {
...FilesWithFluid
}
belair: allFile(filter: { sourceInstanceName: { eq: "belair" } }) {
...FilesWithFluid
}
robertsonTower: allFile(
filter: { sourceInstanceName: { eq: "robertson-tower" } }
) {
function singularRootFieldName(queryFields, type) {
return Object.keys(queryFields).find(fieldName => queryFields[fieldName].type === type)
}
function pluralRootFieldName(queryFields, type) {
const expectedType = `[${type}!]!`
return Object.keys(queryFields).find(fieldName => String(queryFields[fieldName].type) === expectedType)
}
//////
const {
wrapQueryExecutorWithQueue,
loadSchema,
generateDefaultFragments,
compileNodeQueries,
buildNodeDefinitions,
createSchemaCustomization,
sourceAllNodes,
sourceNodeChanges,
} = require('gatsby-graphql-source-toolkit')
exports.sourceNodes = async (gatsbyAPI, pluginOptions) => {
const config = await createSourcingConfig(gatsbyApi)
const { webhookBody } = gatsbyAPI
if (webhookBody && Object.keys(webhookBody).length) {
const { isDelete, typeName, id } = webhookBody
const nodeEvent = isDelete
? {
eventName: "DELETE",
remoteTypeName: typeName,
exports.onCreateNode = async ({
node,
actions: { createNode },
createNodeId,
getCache,
}) => {
if (node.remoteTypeName === 'Asset' && node.mimeType.includes('image/')) {
const fileNode = await createRemoteFileNode({
url: node.url,
parentNodeId: node.id,