Skip to content

Instantly share code, notes, and snippets.

@philsch
philsch / shopItems.spec.ts.snap
Created June 7, 2019 08:29
Blogpost: Easy integration testing of GraphQL with Jest
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`Getting shop items Retrieves the shop items in default order 1`] = `
Object {
"data": Object {
"shopItems": Array [
Object {
"category": "shoes",
"name": "Fancy Sneaker",
"size": "8",
@philsch
philsch / shopItems.spec.ts
Created June 7, 2019 08:19
Blogpost: Easy integration testing of GraphQL with Jest
import * as util from 'util';
import * as rp from 'request-promise';
import { exec } from 'child_process';
const pExec = util.promisify(exec);
const API = 'http://localhost:4466/';
const CMD_SEED_DATABASE = `${__dirname}/../seed.sh`;
describe('Getting shop items', () => {
@philsch
philsch / exampleResponse.json
Created June 7, 2019 07:59
Blogpost: Easy integration testing of GraphQL with Jest
{
"data": {
"shopItems": [
{
"name": "Fancy Sneakers",
"category": "shoes",
"size": "8"
},
{
"name": "Black shirt",
@philsch
philsch / exampleRequest.graphql
Created June 7, 2019 07:57
Blogpost: Easy integration testing of GraphQL with Jest
query {
shopItems {
name
category
size
}
}
@philsch
philsch / seed.sh
Created June 7, 2019 07:43
Blogpost: Easy integration testing of GraphQL with Jest
#!/usr/bin/env bash
# Truncate data in ShopItems collection
mongo shop --host localhost:27017 --username xxx --password xxx --authenticationDatabase admin \
--eval 'db.getCollection("ShopItems").remove({})'
# Import seed data into ShopItems collection
mongoimport --host localhost:27017 --username xxx --password xxx --authenticationDatabase admin \
--db shop --collection ShopItems --type JSON --file ShopItems.json
@philsch
philsch / mongoexport
Last active June 7, 2019 07:36
Blogpost: Easy integration testing of GraphQL with Jest
mongoexport
--host localhost:27017 \
--username xxx \
--authenticationDatabase admin \
--db shop \
--type JSON \
--out ~/project/seeds/ShopItems.json \
--collection ShopItems \
--query '{}'
@philsch
philsch / log2.txt
Last active February 10, 2019 16:05
Blogpost: GraphQL Apollo Server errors and the request context
{
textPayload: "[f85423] {"host":"api.example.org","content-length":"1014","accept":"*/*",
"origin":"https://api.example.org","user-agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_2)
AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36",
"content-type":"application/json","accept-encoding":"gzip, deflate, br",
"via":"1.1 google","x-forwarded-for":"***","x-forwarded-proto":"https",
"authorization":"***"}
timestamp: "2019-02-05T13:24:20Z"
}
{
@philsch
philsch / apollo2.js
Last active February 10, 2019 15:45
Blogpost: GraphQL Apollo Server errors and the request context
import {ApolloServer, SyntaxError, UserInputError, AuthenticationError, ForbiddenError} from 'apollo-server-express';
import {GraphQLErrorTrackingExtension} from 'graphql-error-tracking-extension';
import {ErrorReporting} from '@google-cloud/error-reporting';
const errorReporting = new ErrorReporting();
const server = new ApolloServer({
schema,
extensions: [() => new GraphQLErrorTrackingExtension({
maskHeaders: ['x-forwarded-for', 'authorization'],
@philsch
philsch / log.txt
Last active February 10, 2019 14:59
Blogpost: GraphQL Apollo Server errors and the request context
{
receiveTimestamp: "2019-02-05T11:53:31.329098822Z"
resource: {…}
textPayload: "{"message":"Syntax Error: Expected Name, found )",
"locations":[{"line":2,"column":22}],
"extensions":{"code":"GRAPHQL_PARSE_FAILED"}}"
timestamp: "2019-02-05T11:53:20Z"
}
@philsch
philsch / avro_transform.py
Last active February 3, 2019 18:50
Blogpost: How to update row keys in Google Big Table (main function)
def run():
pipeline_options = PipelineOptions()
pipeline = beam.Pipeline(options=pipeline_options)
options = pipeline_options.view_as(AvroTransformOptions)
steps = (
pipeline
| 'ReadData' >> beam.io.ReadFromAvro(options.input, use_fastavro=True)
| 'Transaform rowkey' >> beam.ParDo(CellTransformDoFn())
| 'WriteData' >> beam.io.WriteToAvro(options.output, BIG_TABLE_SCHEMA, use_fastavro=True))