Skip to content

Instantly share code, notes, and snippets.

View efueyo's full-sized avatar

Enrique Fueyo efueyo

View GitHub Profile
@efueyo
efueyo / NewBooksServer.go
Created November 2, 2019 19:34
MockedServer
const books string = `
[
{ "id": 1, "title": "Pedro Páramo", author: "Juan Rulfo" },
{ "id": 2, "title": "Meditations", author: "Marcus Aurelius" },
{ "id": 3, "title": "Walden", author: "Henry David Thoreau" }
]
`
const book1 string = `
{ "id": 1, "title": "Pedro Páramo", author: "Juan Rulfo" }
`
@efueyo
efueyo / Context.ts
Last active April 24, 2021 01:32
Apollo-Sentry-Context
import { Transaction } from "@sentry/types"
export interface Context {
// ... other context fields for your context
transaction: Transaction
}
export async function createContext(): Promise<Context> { {
// ... create other context fields
const transaction = Sentry.startTransaction({
@efueyo
efueyo / sentry-plugin.ts
Last active April 26, 2021 21:31
Apollo-Sentry-Plugin
import { ApolloServerPlugin } from "apollo-server-plugin-base"
import { Context } from "./context"
const plugin: ApolloServerPlugin<Context> = {
requestDidStart({ request, context }) {
if (!!request.operationName) { // set the transaction Name if we have named queries
context.transaction.setName(request.operationName!)
}
return {
willSendResponse({ context }) { // hook for transaction finished
@efueyo
efueyo / server.ts
Created April 24, 2021 01:38
Apollo-Sentry-Server
import { ApolloServer } from "apollo-server-micro"
import { createContext } from "./context"
import SentryPlugin from "./sentry-plugin"
const apolloServer = new ApolloServer({
// ... your ApolloServer options
// Create context function
context: ({ req, connection }) => createContext({ req, connection }),
// Add our sentry plugin