Skip to content

Instantly share code, notes, and snippets.

View GavinRay97's full-sized avatar

Gavin Ray GavinRay97

View GitHub Profile
@GavinRay97
GavinRay97 / hasuraMetadataV2.ts
Created July 6, 2020 18:48
Hasura Metadata V2 Typescript Generated
// To parse this data:
//
// import { Convert, TableName, QualifiedTable, TableConfig, TableEntry, CustomRootFields, FunctionName, QualifiedFunction, Function, FunctionConfiguration, ObjectRelationship, ObjRelUsing, ObjRelUsingManualMapping, ArrayRelationship, ArrRelUsing, ArrRelUsingFKeyOn, ArrRelUsingManualMapping, InsertPermissionEntry, InsertPermission, SelectPermissionEntry, SelectPermission, UpdatePermissionEntry, UpdatePermission, DeletePermissionEntry, DeletePermission, ComputedField, ComputedFieldDefinition, EventTrigger, EventTriggerDefinition, EventTriggerColumns, OperationSpec, HeaderFromValue, HeaderFromEnv, RetryConf, CronTrigger, RetryConfST, RemoteSchema, RemoteSchemaDef, RemoteRelationship, RemoteRelationshipDef, QueryCollectionEntry, QueryCollection, AllowList, CustomTypes, InputObjectType, InputObjectField, ObjectType, ObjectField, CustomTypeObjectRelationship, ScalarType, EnumType, EnumValue, Action, ActionDefinition, InputArgument, HasuraMetadataV2 } from "./file";
//
// const pGColum
@GavinRay97
GavinRay97 / v-switch.vue
Last active July 13, 2020 15:09
v-switch component
<!-- File: `v-switch.vue` -->
<script>
export default {
functional: true,
props: {
value: { type: [String, Number], required: true }
},
render(h, { data, props, scopedSlots }) {
const { value } = props
const slotFn = value in scopedSlots ? scopedSlots[value] : scopedSlots.default
@GavinRay97
GavinRay97 / example.sh
Last active July 13, 2020 20:36
Bash Regex with capture groups
#! /bin/bash
# VERSION NAME SOURCE STATUS DATABASE STATUS
# 1594317652188 - Not Present Present
# 1594317688377 - Not Present Present
# 1594320512973 - Not Present Present
# 1594320556497 - Not Present Present
function scan_entries_for_not_present() {
# timestamp name source status database status
private async _runK6(metadata: RunK6Metadata, config: K6Options) {
const { queryName, outputFile } = metadata
// If "debug" true, log all HTTP responses
if (this.config.debug) config.httpDebug = 'full'
// Write the K6 configuration JSON to a temp file, to pass as CLI flag
const tmpConfig = path.join(__dirname, 'tmp', `${queryName}_config.json`)
await fs.outputJSON(tmpConfig, config)
@GavinRay97
GavinRay97 / index.js
Created August 4, 2020 17:13
GraphQL Tx over Websocket SDK
const WebSocket = require('ws')
const WebSocketAsPromised = require('websocket-as-promised')
// SDK Code
const socketFactory = (url) =>
new WebSocket(url, 'graphql-tx', {
headers: {
'X-Hasura-Tx-Isolation': 'serializable',
},
})
@GavinRay97
GavinRay97 / Makefile
Created August 24, 2020 00:42
Hasura SQL + Metadata models CLI script
.PHONY: generate_sql generate_tables_yaml generate_schema_and_tables_metadata
generate_sql: ## Generate single SQL file schema from all models
ruby ./generate-sql.rb \
--identifiers '/* TABLE */,/* FOREIGN KEYS */,/* TRIGGERS */' \
--out schema.sql \
./models/**/**.sql
generate_tables_yaml: ## Generate tables.yaml file from all models
ruby ./generate-tables-metadata.rb \
@GavinRay97
GavinRay97 / docker-compose.yaml
Created August 27, 2020 16:59
Hasura GraphQL Tx over Websockets client
version: '3.6'
services:
postgres:
image: postgres:12
restart: always
volumes:
- db_data:/var/lib/postgresql/data
environment:
POSTGRES_PASSWORD: postgrespassword
graphql-engine:
@GavinRay97
GavinRay97 / notes.md
Created September 1, 2020 17:23
Yarn 2 Berry notes - VS Code, Typescript, node_modules compatibility

Set yarn to use V2/Berry in project:

  • yarn set version berry

Add Typescript plugin for automatically fetching @types/<pkg> definition when package doesn't include them:

  • yarn plugin import typescript

To use the PnP setup with VS Code, and not retain node_modules compatibility, run:

  • yarn add @yarnpkg/pnpify --dev
  • yarn pnpify --sdk vscode
@GavinRay97
GavinRay97 / index.ts
Created September 4, 2020 01:44
GraphQL Zeus + Apollo Client typings integration
import {
ApolloProvider,
gql,
MutationHookOptions,
QueryHookOptions,
SubscriptionHookOptions,
useMutation,
useQuery,
useSubscription,
} from "@apollo/client";
@GavinRay97
GavinRay97 / README.md
Last active September 30, 2020 15:20
Hasura MySQL Test Setup

Put the docker-compose.yaml into a new folder, along with a folder called /migrations. Put the sample SQL in there at /migrations/any-name.sql. This will seed the MySQL DB on startup.

Run docker-compose up -d, and visit Hasura at http://localhost:8080

Note: If you would like to a connect to an existing MySQL DB running outside of Docker on localhost, you will need to edit the configuration for the Hasura service so that it uses host networking. Then use localhost for the --mysql-host argument. Also, in order for Hasura on localhost to connect to the Docker Postgres instance, you'll need to add 5432:5432 to the service port configurations for postgres so that it's exposed, then change the DB URL to postgres://postgres:postgrespassword@localhost:5432/postgres.

services:
  graphql-engine:
 # ...