nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: vigetlabs/microcosm
Pull request #244 (2017-03-09 18:15:29)

Invoke should not run on removed repos
This commit fixes a bug where Microcosm would raise an exception if a
fork was removed from history as the result of a parent changing. It
also adds an assertion to make it clearer during testing.

Sorry, @dce :(


Patch:
diff --git a/src/history.js b/src/history.js
index 69d38e72..2dc78c55 100644
--- a/src/history.js
+++ b/src/history.js
@@ -45,7 +45,8 @@ History.prototype = {
   invoke (method, payload) {
     let repos = this.repos
 
-    for (var i = 0, len = repos.length; i < len; i++) {
+    for (var i = 0; i < repos.length; i++) {
+      console.assert(repos[i], `Missing repo! Was it removed before it could run repo.${method}?`)
       repos[i][method](payload)
     }
   },


Test patch:
diff --git a/test/unit/history/invoke.test.js b/test/unit/history/invoke.test.js
new file mode 100644
index 00000000..48f751c6
--- /dev/null
+++ b/test/unit/history/invoke.test.js
@@ -0,0 +1,23 @@
+import History from '../../../src/history'
+import Microcosm from '../../../src/microcosm'
+
+describe('History::invoke', function() {
+
+  it('it does invoke a repo that no longer exists', function() {
+    let parent = new Microcosm()
+    let child = parent.fork()
+
+    parent.on('change', () => child.teardown())
+
+    jest.spyOn(child, 'release')
+
+    parent.addDomain('test', {
+      getInitialState() {
+        return false
+      }
+    })
+
+    expect(child.release).not.toHaveBeenCalled()
+  })
+
+})
Repository: vigetlabs/microcosm
Pull request #303 (2017-04-19 11:46:50)

Handle spaces in key paths, increase key path test coverage
Pretty cut and dry. I'm working on some stuff that uses key paths and I noticed that spaces aren't allowed. This PR allows for change subscriptions like:

```javascript
repo.on('lists, items', callback)
// or
repo.on('lists,items', callback)
```

Not a new feature, it's just natural to add a space after a comma, so let's make sure we cover it.


Patch:
diff --git a/src/key-path.js b/src/key-path.js
index 11158cd2..5481f878 100644
--- a/src/key-path.js
+++ b/src/key-path.js
@@ -25,7 +25,7 @@ export function castPath (value) {
     return []
   }
 
-  return isString(value) ? value.split(KEY_DELIMETER) : [value]
+  return isString(value) ? value.trim().split(KEY_DELIMETER) : [value]
 }
 
 /**


Test patch:
diff --git a/test/unit/key-path/get-key-paths.test.js b/test/unit/key-path/get-key-paths.test.js
new file mode 100644
index 00000000..15e96e07
--- /dev/null
+++ b/test/unit/key-path/get-key-paths.test.js
@@ -0,0 +1,52 @@
+import {
+  getKeyPaths
+} from '../../../src/key-path'
+
+describe('getKeyPaths', function () {
+
+  it('removes leading spaces between paths', function () {
+    let path = getKeyPaths('foo, bar')
+
+    expect(path.length).toBe(2)
+
+    expect(path[0]).toEqual(['foo'])
+    expect(path[1]).toEqual(['bar'])
+  })
+
+  it('removes trailing spaces between paths', function () {
+    let path = getKeyPaths('foo ,bar')
+
+    expect(path.length).toBe(2)
+
+    expect(path[0]).toEqual(['foo'])
+    expect(path[1]).toEqual(['bar'])
+  })
+
+  it('removes spaces at the beginning of a path', function () {
+    let path = getKeyPaths(' foo,bar')
+
+    expect(path.length).toBe(2)
+
+    expect(path[0]).toEqual(['foo'])
+    expect(path[1]).toEqual(['bar'])
+  })
+
+  it('removes spaces at the end of a path', function () {
+    let path = getKeyPaths('foo,bar ')
+
+    expect(path.length).toBe(2)
+
+    expect(path[0]).toEqual(['foo'])
+    expect(path[1]).toEqual(['bar'])
+  })
+
+  it('does not remove space between words', function () {
+    let path = getKeyPaths('foo, b ar')
+
+    expect(path.length).toBe(2)
+
+    expect(path[0]).toEqual(['foo'])
+    expect(path[1]).toEqual(['b ar'])
+  })
+
+})
Repository: vigetlabs/microcosm
Pull request #365 (2017-07-11 21:09:42)

Add debug mode hook
Adds the debug hook we need for the developer tools. This is related to:
https://github.com/vigetlabs/microcosm-devtools/pull/25

![screen shot 2017-07-11 at 5 05 47 pm](https://user-images.githubusercontent.com/590904/28090850-c025bc30-665b-11e7-81bb-1302a1395482.png)


efatsi: so still would require some configuration `{debug: true}`, but that's a pretty low barrier 👍
nhunzaker: @efatsi Yeah, I figured you would do `{ debug: process.env.NODE_ENV !== 'production' }` once and forget about it.

Basically, I don't want to rely on the `NODE_ENV` environment variable, and I don't want this to automatically run in production. What do you think?

Patch:
diff --git a/src/install-devtools.js b/src/install-devtools.js
new file mode 100644
index 00000000..c5087735
--- /dev/null
+++ b/src/install-devtools.js
@@ -0,0 +1,9 @@
+export default function installDevtools(repo) {
+  let hook = global.__MICROCOSM_DEVTOOLS_GLOBAL_HOOK__
+
+  if (hook) {
+    hook.emit('init', repo)
+
+    repo.history.setLimit(Infinity)
+  }
+}
diff --git a/src/microcosm.js b/src/microcosm.js
index a8831cd8..c2965255 100644
--- a/src/microcosm.js
+++ b/src/microcosm.js
@@ -14,6 +14,7 @@ import CompareTree from './compare-tree'
 import coroutine from './coroutine'
 import getRegistration from './get-registration'
 import tag from './tag'
+import installDevtools from './install-devtools'
 import { RESET, PATCH, ADD_DOMAIN } from './lifecycle'
 import { merge, get, set, update } from './utils'
 
@@ -25,7 +26,8 @@ import { merge, get, set, update } from './utils'
 const DEFAULTS = {
   maxHistory: 0,
   parent: null,
-  batch: false
+  batch: false,
+  debug: false
 }
 
 /**
@@ -141,6 +143,10 @@ class Microcosm extends Emitter implements Domain {
     if (state) {
       this.reset(state, deserialize)
     }
+
+    if (options.debug) {
+      installDevtools(this)
+    }
   }
 
   /**


Test patch:
diff --git a/test/unit/microcosm/devtools.test.js b/test/unit/microcosm/devtools.test.js
new file mode 100644
index 00000000..e4383b30
--- /dev/null
+++ b/test/unit/microcosm/devtools.test.js
@@ -0,0 +1,28 @@
+import Microcosm from '../../../src/microcosm'
+
+describe('Microcosm devtools', function() {
+  it('installs the devtools when enabled', function() {
+    let emit = jest.fn()
+
+    global.__MICROCOSM_DEVTOOLS_GLOBAL_HOOK__ = { emit }
+
+    let repo = new Microcosm({ debug: true })
+
+    expect(emit).toHaveBeenCalledWith('init', repo)
+  })
+
+  it('adjusts the limit of history to Infinity', function() {
+    global.__MICROCOSM_DEVTOOLS_GLOBAL_HOOK__ = { emit: jest.fn() }
+
+    let repo = new Microcosm({ debug: true })
+
+    expect(repo.history.limit).toBe(Infinity)
+  })
+
+  it('does not fail when there is no dev tools hook', function() {
+    global.__MICROCOSM_DEVTOOLS_GLOBAL_HOOK__ = null
+
+    // More or less, this should not break
+    new Microcosm({ debug: true })
+  })
+})
Repository: vigetlabs/microcosm
Pull request #386 (2017-08-08 20:29:08)

Do not return undefined when getting null with no fallback
Just got hit by this nasty bug. Getting `null` out of an object was returning undefined because the loose null check returned an undefined fallback:

```
get({ prop: null }, 'prop') // undefined, but should be null
```

This is because we trigger the fallback on null. The problem is that a value is present here, so we should respect it when there is no fallback.


Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 351d9569..13e70f28 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,6 +5,8 @@
 - Microcosm ships with ES6 and UMD bundles
 - Domains and Effects can implement a `defaults` static object to
   provide default setup options.
+- Do not return undefined when using `get` to retrieve a null value
+  without a fallback.
 
 # 12.9.0
 
diff --git a/src/domain-engine.js b/src/domain-engine.js
index 8a800b5a..4c4d6210 100644
--- a/src/domain-engine.js
+++ b/src/domain-engine.js
@@ -93,8 +93,8 @@ class DomainEngine {
     for (var i = 0, len = handlers.length; i < len; i++) {
       var { key, source, handler } = handlers[i]
 
-      var base = get(result, key)
-      var head = get(snapshot.last, key)
+      var base = get(result, key, null)
+      var head = get(snapshot.last, key, null)
 
       if (
         // If the reference to the prior state changed
diff --git a/src/utils.js b/src/utils.js
index 558dd7d3..fb616071 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -98,7 +98,11 @@ export function get(object: ?Object, keyPath: *, fallback?: *) {
     value = value[path[i]]
   }
 
-  return value == null ? fallback : value
+  if (value === undefined || value === null) {
+    return arguments.length <= 2 ? value : fallback
+  }
+
+  return value
 }
 
 /**


Test patch:
diff --git a/test/unit/compare-tree/compare-tree.test.js b/test/unit/compare-tree/compare-tree.test.js
index a1fced00..0f37f489 100644
--- a/test/unit/compare-tree/compare-tree.test.js
+++ b/test/unit/compare-tree/compare-tree.test.js
@@ -250,7 +250,7 @@ describe('CompareTree', function() {
         meta: { selected: true }
       })
 
-      expect(handler).toHaveBeenCalledWith(undefined)
+      expect(handler).toHaveBeenCalledWith(null)
     })
 
     it('the root node does not get called twice if subscribing to two children', function() {
diff --git a/test/unit/utils/get.test.js b/test/unit/utils/get.test.js
index 9411271c..bb293b5c 100644
--- a/test/unit/utils/get.test.js
+++ b/test/unit/utils/get.test.js
@@ -32,6 +32,18 @@ describe('Utils.get', function() {
     expect(fallback).toBe(true)
   })
 
+  it('returns the value if there is no fallback and the value is null', function() {
+    let value = get({ prop: null }, 'prop')
+
+    expect(value).toBe(null)
+  })
+
+  it('returns the value if there is no fallback and the value is undefined', function() {
+    let value = get({ prop: undefined }, 'prop')
+
+    expect(value).toBe(undefined)
+  })
+
   it('returns the fallback if the key and fallback are null', function() {
     let fallback = get(null, null, true)
Repository: mcollina/autocannon
Pull request #494 (2023-08-03 18:38:53)

Resolve issue #493


Patch:
diff --git a/lib/httpRequestBuilder.js b/lib/httpRequestBuilder.js
index 1319902..efd86ec 100644
--- a/lib/httpRequestBuilder.js
+++ b/lib/httpRequestBuilder.js
@@ -72,6 +72,8 @@ function requestBuilder (defaults) {
 
     if (typeof body === 'string') {
       bodyBuf = Buffer.from(body)
+    } else if (typeof body === 'number') {
+      bodyBuf = Buffer.from(body + '')
     } else if (Buffer.isBuffer(body)) {
       bodyBuf = body
     } else if (body && Array.isArray(body._)) {


Test patch:
diff --git a/test/cli.test.js b/test/cli.test.js
index 3ef17b0..fe16b5d 100644
--- a/test/cli.test.js
+++ b/test/cli.test.js
@@ -254,3 +254,97 @@ test('run with workers', { skip: !hasWorkerSupport }, (t) => {
     })
     .on('end', t.end)
 })
+
+test('should run handle PUT bodies', (t) => {
+  t.test('"number" bodies work', t => {
+    t.plan(2)
+
+    const server = helper.startServer()
+    const url = 'http://localhost:' + server.address().port
+
+    const cmd = [
+      path.join(__dirname, '..'),
+      '-d', '1',
+      '-m', 'PUT',
+      '-H', 'content-type="application/x-www-form-urlencoded"',
+      '-b', '1',
+      url
+    ]
+    const child = childProcess.spawn(process.execPath, cmd, {
+      cwd: __dirname,
+      env: process.env,
+      stdio: ['ignore', 'pipe', 'pipe'],
+      detached: false
+    })
+
+    t.teardown(() => {
+      child.kill()
+    })
+
+    const outputLines = []
+    child
+      .stderr
+      .pipe(split())
+      .on('data', (line) => {
+        outputLines.push(line)
+      })
+      .on('end', () => {
+        t.equal(
+          outputLines.some(l => l === 'body must be either a string or a buffer'),
+          false
+        )
+        t.equal(
+          /.* requests in ([0-9]|\.)+s, .* read/.test(outputLines.pop()),
+          true
+        )
+        t.end()
+      })
+  })
+
+  t.test('"string" bodies work', t => {
+    t.plan(2)
+
+    const server = helper.startServer()
+    const url = 'http://localhost:' + server.address().port
+
+    const cmd = [
+      path.join(__dirname, '..'),
+      '-d', '1',
+      '-m', 'PUT',
+      '-H', 'content-type="application/x-www-form-urlencoded"',
+      '-b', '"1"',
+      url
+    ]
+    const child = childProcess.spawn(process.execPath, cmd, {
+      cwd: __dirname,
+      env: process.env,
+      stdio: ['ignore', 'pipe', 'pipe'],
+      detached: false
+    })
+
+    t.teardown(() => {
+      child.kill()
+    })
+
+    const outputLines = []
+    child
+      .stderr
+      .pipe(split())
+      .on('data', (line) => {
+        outputLines.push(line)
+      })
+      .on('end', () => {
+        t.equal(
+          outputLines.some(l => l === 'body must be either a string or a buffer'),
+          false
+        )
+        t.equal(
+          /.* requests in ([0-9]|\.)+s, .* read/.test(outputLines.pop()),
+          true
+        )
+        t.end()
+      })
+  })
+
+  t.end()
+})
Repository: mcollina/autocannon
Pull request #507 (2024-01-07 12:58:16)

allow only one host header
fixes https://github.com/mcollina/autocannon/issues/502


Patch:
diff --git a/lib/httpRequestBuilder.js b/lib/httpRequestBuilder.js
index efd86ec..57aa3de 100644
--- a/lib/httpRequestBuilder.js
+++ b/lib/httpRequestBuilder.js
@@ -45,14 +45,21 @@ function requestBuilder (defaults) {
     const headers = reqData.headers
     const body = reqData.body
 
-    let host = getPropertyCaseInsensitive(reqData.headers, 'host') || reqData.host
+    const headersDefinedHost = getPropertyCaseInsensitive(reqData.headers, 'host')
+    let host = headersDefinedHost || reqData.host
 
     if (!host) {
       const hostname = reqData.hostname
       const port = reqData.port
       host = hostname + ':' + port
     }
-
+    const baseReq = [
+      `${method} ${path} HTTP/1.1`
+    ]
+    if (!headersDefinedHost) {
+      baseReq.push(`Host: ${host}`)
+    }
+    baseReq.push('Connection: keep-alive')
     if (reqData.auth) {
       const encodedAuth = Buffer.from(reqData.auth).toString('base64')
       headers.Authorization = `Basic ${encodedAuth}`
@@ -62,12 +69,6 @@ function requestBuilder (defaults) {
       throw new Error(`${method} HTTP method is not supported`)
     }
 
-    const baseReq = [
-      `${method} ${path} HTTP/1.1`,
-      `Host: ${host}`,
-      'Connection: keep-alive'
-    ]
-
     let bodyBuf
 
     if (typeof body === 'string') {


Test patch:
diff --git a/test/httpRequestBuilder.test.js b/test/httpRequestBuilder.test.js
index f030e59..4841ab2 100644
--- a/test/httpRequestBuilder.test.js
+++ b/test/httpRequestBuilder.test.js
@@ -99,6 +99,23 @@ test('request builder should add a Content-Length header when the body buffer ex
     'request is okay')
 })
 
+test('request builder should add only one HOST header', (t) => {
+  t.plan(1)
+
+  const opts = server.address()
+  opts.method = 'POST'
+  opts.headers = {
+    Host: 'example.com'
+  }
+
+  const build = RequestBuilder(opts)
+
+  const result = build({ body: 'body' })
+  t.same(result,
+    Buffer.from('POST / HTTP/1.1\r\nConnection: keep-alive\r\nHost: example.com\r\nContent-Length: 4\r\n\r\nbody'),
+    'request is okay')
+})
+
 test('request builder should add a Content-Length header with correct calculated value when the body buffer exists and idReplacement is enabled as a default override', (t) => {
   t.plan(1)
Repository: mcollina/fastify-gql
Pull request #1 (2018-09-18 16:15:43)

add option to disable adding routes


Patch:
diff --git a/index.js b/index.js
index d6991a8..822c5ec 100644
--- a/index.js
+++ b/index.js
@@ -47,7 +47,7 @@ module.exports = fp(async function (app, opts) {
 
   const graphqlCtx = Symbol('ctx')
 
-  app.register(routes)
+  if (opts.routes !== false) app.register(routes)
 
   app.decorateReply(graphqlCtx, null)
 


Test patch:
diff --git a/test/routes.js b/test/routes.js
index a1efeab..232f2a8 100644
--- a/test/routes.js
+++ b/test/routes.js
@@ -189,3 +189,29 @@ test('GET route variables', async (t) => {
     }
   })
 })
+
+test('disable routes', async (t) => {
+  const app = Fastify()
+  const schema = `
+    type Query {
+      add(x: Int, y: Int): Int
+    }
+  `
+
+  const root = {
+    add: async ({ x, y }) => x + y
+  }
+
+  app.register(GQL, {
+    schema,
+    root,
+    routes: false
+  })
+
+  const res = await app.inject({
+    method: 'GET',
+    url: '/graphql?query={add(x:2,y:2)}'
+  })
+
+  t.deepEqual(res.statusCode, 404)
+})
Repository: mcollina/fastify-gql
Pull request #4 (2018-10-04 17:39:27)

Support custom scalar type


Patch:
diff --git a/index.js b/index.js
index 124bf1a..529a8a0 100644
--- a/index.js
+++ b/index.js
@@ -9,6 +9,7 @@ const {
   buildSchema,
   getOperationAST,
   GraphQLObjectType,
+  GraphQLScalarType,
   GraphQLSchema,
   extendSchema,
   validate,
@@ -97,6 +98,11 @@ module.exports = fp(async function (app, opts) {
         for (const prop of Object.keys(resolver)) {
           fields[prop].resolve = resolver[prop]
         }
+      } else if (type instanceof GraphQLScalarType) {
+        const resolver = resolvers[name]
+        for (const prop of Object.keys(resolver)) {
+          type[prop] = resolver[prop]
+        }
       } else {
         throw new Error(`Cannot find type ${name}`)
       }


Test patch:
diff --git a/test/app-decorator.js b/test/app-decorator.js
index 5057597..52f01b1 100644
--- a/test/app-decorator.js
+++ b/test/app-decorator.js
@@ -3,6 +3,7 @@
 const { test } = require('tap')
 const Fastify = require('fastify')
 const GQL = require('..')
+const { GraphQLScalarType } = require('graphql')
 
 test('basic GQL', async (t) => {
   const app = Fastify()
@@ -267,3 +268,52 @@ test('complex types', async (t) => {
     }
   })
 })
+
+test('scalar should be supported', async (t) => {
+  t.plan(2)
+
+  const app = Fastify()
+  const schema = `
+    scalar Date
+
+    type Query {
+      add(x: Int, y: Int): Date
+    }
+  `
+
+  const resolvers = {
+    add: async ({ x, y }) => x + y,
+    Date: new GraphQLScalarType({
+      name: 'Date',
+      description: 'Date custom scalar type',
+      parseValue (value) {
+        return value
+      },
+      serialize (value) {
+        t.pass(value, 4)
+        return value
+      },
+      parseLiteral (ast) {
+        // not called on this test
+        return null
+      }
+    })
+  }
+
+  app.register(GQL, {
+    schema,
+    resolvers
+  })
+
+  // needed so that graphql is defined
+  await app.ready()
+
+  const query = '{ add(x: 2, y: 2) }'
+  const res = await app.graphql(query)
+
+  t.deepEqual(res, {
+    data: {
+      add: 4
+    }
+  })
+})
Repository: mcollina/fastify-gql
Pull request #6 (2018-10-04 18:08:04)

Add support for enums


Patch:
diff --git a/index.js b/index.js
index e19fa74..feda580 100644
--- a/index.js
+++ b/index.js
@@ -10,6 +10,7 @@ const {
   getOperationAST,
   GraphQLObjectType,
   GraphQLScalarType,
+  GraphQLEnumType,
   GraphQLSchema,
   extendSchema,
   validate,
@@ -98,7 +99,7 @@ module.exports = fp(async function (app, opts) {
         for (const prop of Object.keys(resolver)) {
           fields[prop].resolve = resolver[prop]
         }
-      } else if (type instanceof GraphQLScalarType) {
+      } else if (type instanceof GraphQLScalarType || type instanceof GraphQLEnumType) {
         const resolver = resolvers[name]
         for (const prop of Object.keys(resolver)) {
           type[prop] = resolver[prop]


Test patch:
diff --git a/test/app-decorator.js b/test/app-decorator.js
index 8035859..8c6e66c 100644
--- a/test/app-decorator.js
+++ b/test/app-decorator.js
@@ -3,7 +3,10 @@
 const { test } = require('tap')
 const Fastify = require('fastify')
 const GQL = require('..')
-const { GraphQLScalarType } = require('graphql')
+const {
+  GraphQLScalarType,
+  GraphQLEnumType
+} = require('graphql')
 const { makeExecutableSchema } = require('graphql-tools')
 
 test('basic GQL', async (t) => {
@@ -348,3 +351,46 @@ test('scalar should be supported', async (t) => {
     }
   })
 })
+
+test('enum should be supported', async (t) => {
+  const app = Fastify()
+  const schema = `
+    enum MyEnum {
+      YES
+      NO
+    }
+
+    type Query {
+      add(x: Int, y: Int): MyEnum
+    }
+  `
+
+  const resolvers = {
+    add: async ({ x, y }) => x + y,
+    MyEnum: new GraphQLEnumType({
+      name: 'MyEnum',
+      description: 'MyEnum custom scalar type',
+      values: {
+        'YES': { value: 4 },
+        'NO': { value: 2 }
+      }
+    })
+  }
+
+  app.register(GQL, {
+    schema,
+    resolvers
+  })
+
+  // needed so that graphql is defined
+  await app.ready()
+
+  const query = '{ add(x: 2, y: 2) }'
+  const res = await app.graphql(query)
+
+  t.deepEqual(res, {
+    data: {
+      add: 'YES'
+    }
+  })
+})
Repository: mcollina/fastify-gql
Pull request #24 (2019-01-06 01:14:43)

Plugin name definition
There is no plugin definition which makes dependencies resolution not working if a plugin depends on `fastify-gql`


Patch:
diff --git a/index.js b/index.js
index 96f3005..07b0a06 100644
--- a/index.js
+++ b/index.js
@@ -204,4 +204,6 @@ module.exports = fp(async function (app, opts) {
 
     return execution
   }
+}, {
+  name: 'fastify-gql'
 })


Test patch:
diff --git a/test/plugin-definition.js b/test/plugin-definition.js
new file mode 100644
index 0000000..df6b0fb
--- /dev/null
+++ b/test/plugin-definition.js
@@ -0,0 +1,16 @@
+'use strict'
+
+const { test } = require('tap')
+const fp = require('fastify-plugin')
+const Fastify = require('fastify')
+const GQL = require('..')
+
+test('plugin name definition', async (t) => {
+  const app = Fastify()
+  app.register(GQL)
+  app.register(fp(async (app, opts) => {}, {
+    dependencies: ['fastify-gql']
+  }))
+
+  t.resolves(app.ready())
+})
Repository: mcollina/fastify-gql
Pull request #69 (2019-08-20 16:36:38)

add app to loaders context
added app to the context argument in loaders

mcollina: Can you please add a unit test?

Patch:
diff --git a/index.js b/index.js
index 0eab886..31e5c89 100644
--- a/index.js
+++ b/index.js
@@ -143,7 +143,7 @@ module.exports = fp(async function (app, opts) {
       factory = new Factory()
       app.decorateReply(kLoaders)
       app.addHook('onRequest', async function (req, reply) {
-        reply[kLoaders] = factory.create({ req, reply })
+        reply[kLoaders] = factory.create({ req, reply, app })
       })
     }
 


Test patch:
diff --git a/test/app-decorator.js b/test/app-decorator.js
index 78eda0b..c9ad63a 100644
--- a/test/app-decorator.js
+++ b/test/app-decorator.js
@@ -41,7 +41,7 @@ test('basic GQL', async (t) => {
   })
 })
 
-test('support context', async (t) => {
+test('support context in resolver', async (t) => {
   const app = Fastify()
   const schema = `
     type Query {
diff --git a/test/loaders.js b/test/loaders.js
index c25cdc6..e0a947a 100644
--- a/test/loaders.js
+++ b/test/loaders.js
@@ -262,3 +262,68 @@ test('defineLoaders method', async (t) => {
     }
   })
 })
+
+test('support context in loader', async (t) => {
+  const app = Fastify()
+
+  const resolvers = {
+    Query: {
+      dogs: (_, params, context) => {
+        return dogs
+      }
+    }
+  }
+
+  const loaders = {
+    Dog: {
+      async owner (queries, context) {
+        t.equal(context.app, app)
+        return queries.map(({ obj }) => owners[obj.name])
+      }
+    }
+  }
+
+  app.register(GQL, {
+    schema,
+    resolvers,
+    loaders
+  })
+
+  // needed so that graphql is defined
+  await app.ready()
+
+  const query = 'query { dogs { name owner { name } } }'
+  const res = await app.inject({
+    method: 'POST',
+    url: '/graphql',
+    body: {
+      query
+    }
+  })
+
+  t.deepEqual(JSON.parse(res.body), {
+    data: {
+      dogs: [{
+        name: 'Max',
+        owner: {
+          name: 'Jennifer'
+        }
+      }, {
+        name: 'Charlie',
+        owner: {
+          name: 'Sarah'
+        }
+      }, {
+        name: 'Buddy',
+        owner: {
+          name: 'Tracy'
+        }
+      }, {
+        name: 'Max',
+        owner: {
+          name: 'Jennifer'
+        }
+      }]
+    }
+  })
+})