Skip to content

Instantly share code, notes, and snippets.

View kirkness's full-sized avatar
😎

Henry kirkness

😎
View GitHub Profile
@kirkness
kirkness / auth-graph.js
Last active August 2, 2017 21:46
Authenticate a GraphQL Schema
// @flow
import { forEachField } from 'graphql-tools';
import { get } from 'lodash/fp';
export default (schema: Object) => {
forEachField(schema, (field: Object) => {
if (field.authenticate) {
// eslint-disable-next-line no-param-reassign
field.resolve = (...args) => {
const [,, context] = args;
@kirkness
kirkness / F*#!ng Gradle
Created November 15, 2017 16:57
Couple of tips for for debugging dependency conflicts.
### TIP 1
Get list of transitive dependencies.
NOTE: Make sure the second tip is not set if you want to see the full result of this.
```
$ cd android
$ ./gradlew :app:dependencies
```
### TIP 2
@kirkness
kirkness / example.js
Last active April 10, 2018 22:07
Example Expobook setup for Medium article
import React from 'react';
import createExpo from 'expobook';
import Button from './components/button';
const expobook = createExpo();
expobook.add('My button', () => <Button>Hello World</Button>);
expobook.add('My other button', () => <Button>Hello World, again</Button>);
export default expobook.build();
@kirkness
kirkness / csv-to-json.js
Created April 12, 2018 17:32
Convert CSV to JSON
const csvToJson = csv => {
const [firstLine, ...lines] = csv.split('\n');
return lines.map(line =>
firstLine.split(',').reduce(
(curr, next, index) => ({
...curr,
[next]: line.split(',')[index],
}),
{}
)
@kirkness
kirkness / buildWhenAffected.sh
Created September 2, 2018 13:53 — forked from naesheim/buildWhenAffected.sh
CircleCi - only build features that has changed
##################
### config.yml ###
##################
version: 2
jobs:
build:
docker:
- image: circleci/python:3.6
steps:
@kirkness
kirkness / apollo-engine-setup.ts
Created October 19, 2018 08:43
Example of problem where data is not reporting
const server = new ApolloServer({
formatError,
resolvers,
typeDefs: SCHEMA,
engine: false,
tracing: true,
cacheControl: true,
subscriptions: {
onConnect: authSubscription
@kirkness
kirkness / my-schema.graphql
Last active January 6, 2019 20:00
Example authorised schema
type Query {
getMyData: Data @authenticate
somePublicData: String
}
type Mutation {
updateAnItem(id: ID!, name: String!): Item @authenticate
}
const updateAnItem = (root, args) => {
return Item.update({ name: args.name }).where({ id: args.id });
};
const updateAnItem = (root, args, ctx) => {
return Item.update({ name: args.name }).where({ id: args.id, userId: ctx.userId });
};
import { createRateLimitDirective } from 'graphql-rate-limit';
const server = new ApolloServer({
typeDefs: gql`
type Mutation {
# Limit to 10 per minute
login(email: String!, password: String!): String! @rateLimit(max: 10, window: 60000)
}
`,
resolvers: {