Skip to content

Instantly share code, notes, and snippets.

View warrenday's full-sized avatar

Warren Day warrenday

View GitHub Profile
function positionalProp<
N extends string, F extends boolean | string | number
>(name: N, fallback?: F): (
F extends false ?
string | number | false
: F extends string ? string : number
)
const x = positionalProp('foo', false) // string | number | false
{
"Print to console": {
"prefix": "rtc",
"body": [
"import React from 'react'",
"",
"interface I$1Props {",
"",
"}",
"",
@warrenday
warrenday / linked-list-iterator.js
Last active February 17, 2021 20:44
Loop over a linked list
class LinkedList {
head = null
tail = null;
insert(data) {
const newNode = { data };
if (!this.head) {
this.head = newNode
} else {
this.tail.next = newNode;
export const getIsQueryOrMutation = (queryString: string) => {
return queryString.replace(/\s/g, '').startsWith('query')
? 'query'
: 'mutate';
};
import { ApolloServer } from 'apollo-server';
import { schema } from './schema';
export const createServer = () => {
return new ApolloServer({
schema,
});
};
exports[`Bookings Integration Tests getBooking`] = `
Object {
"data": Object {
"getBooking": Object {
"id": 1,
"cartReference": "123-123-456",
"paymentAmount": 2000,
"cancelled": false,
"receiptNumber": "456464565",
},
import { createTestClient } from 'apollo-server-testing';
import { createServer } from './createServer';
export const runTestCases = (
groupName,
testCases,
) => {
const { query } = createTestClient(createServer());
describe(`${groupName} resolvers`, () => {
import { createTestClient } from 'apollo-server-testing';
const { query } = createTestClient();
const res = await query({
query: `
query listBookings {
id
}
`,
import { runTestCases } from './test-runner';
const testCases = [
{
id: 'getBooking',
query: `
query ($id: Int!) {
getBooking (id: $id) {
id
cartReference
name: Test App
on: [push]
jobs:
build:
timeout-minutes: 10
runs-on: ubuntu-latest
strategy: