nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: mcollina/fastify-gql
Pull request #93 (2019-12-15 22:35:55)

Fix TypeError: this.queue.close is not a function
In some rare cases there's a possibility when `close` will be called before `subscribe` will happen. In this case that error could cause even app server crash. Also it prevents `this.queue.destroy()` to be called.

I don't know how to properly test this case, cause it's caused by some abnormal behaviour of client side. Tried some options with closing ws client right after establishing connection, sending some crappy staff into it - nothing caused this bug to appear.
Anyway it's present and needed to be fixed.

mcollina: Can you add a test that directly call the `Subscriber`? I think that should be possible.
SkeLLLa: @mcollina test added.

Patch:
diff --git a/lib/subscriber.js b/lib/subscriber.js
index 8761046..bc7cdb1 100644
--- a/lib/subscriber.js
+++ b/lib/subscriber.js
@@ -61,7 +61,11 @@ class SubscriptionContext {
   }
 
   close () {
-    this.queue.close()
+    // In rare cases when `subscribe()` not called (e.g. some network error)
+    // `close` will be `undefined`.
+    if (typeof this.queue.close === 'function') {
+      this.queue.close()
+    }
     this.queue.destroy()
   }
 }


Test patch:
diff --git a/test/subscriber.js b/test/subscriber.js
index 2cbdac6..baa0e88 100644
--- a/test/subscriber.js
+++ b/test/subscriber.js
@@ -19,6 +19,16 @@ test('subscriber published an event', async (t) => {
   })
 })
 
+test('subscription context not throw error on close', t => {
+  t.plan(1)
+  const pubsub = new PubSub(mq())
+
+  const sc = new SubscriptionContext({ pubsub })
+
+  sc.close()
+  t.pass()
+})
+
 test('subscription context publish event returns a promise', t => {
   t.plan(1)
   const pubsub = new PubSub(mq())
Repository: mcollina/fastify-gql
Pull request #216 (2020-07-16 14:38:18)

Provide a better error message for bad schemas
This will help with https://github.com/mcollina/fastify-gql/issues/215.


Patch:
diff --git a/index.js b/index.js
index fc7d5cf..57daaf2 100644
--- a/index.js
+++ b/index.js
@@ -156,8 +156,10 @@ const plugin = fp(async function (app, opts) {
 
   app.addHook('onReady', async function () {
     const schemaValidationErrors = validateSchema(fastifyGraphQl.schema)
-    if (schemaValidationErrors.length > 0) {
-      const err = new Error('schema issues')
+    if (schemaValidationErrors.length === 1) {
+      throw schemaValidationErrors[0]
+    } else if (schemaValidationErrors.length > 1) {
+      const err = new Error('Schema issues, check out the .errors property on the Error.')
       err.errors = schemaValidationErrors
       throw err
     }
diff --git a/package.json b/package.json
index ca327fe..e6678d1 100644
--- a/package.json
+++ b/package.json
@@ -29,7 +29,7 @@
     "@typescript-eslint/parser": "^3.6.1",
     "autocannon": "^5.0.0",
     "fastify": "^3.0.2",
-    "graphql-tools": "^6.0.8",
+    "graphql-tools": "^6.0.14",
     "pre-commit": "^1.2.2",
     "proxyquire": "^2.1.3",
     "snazzy": "^8.0.0",


Test patch:
diff --git a/test/app-decorator.js b/test/app-decorator.js
index b6cf57e..1e0a173 100644
--- a/test/app-decorator.js
+++ b/test/app-decorator.js
@@ -1044,6 +1044,48 @@ test('Error in schema', async (t) => {
     })
     await app.ready()
   } catch (error) {
+    console.log(error.message, error.name)
+    t.equal(error.message, 'Interface field Event.Id expected but CustomEvent does not provide it.')
+    t.equal(error.name, 'GraphQLError')
+  }
+})
+
+test('Multiple errors in schema', async (t) => {
+  const schema = `
+    interface Event {
+      Id: Int!
+    }
+    type CustomEvent implements Event {
+      # Id needs to be specified here
+      Name: String!
+    }
+    type AnotherEvent implements Event {
+      # Id needs to be specified here
+      Name: String!
+    }
+    type Query {
+      listEvent: [Event]
+    }
+  `
+
+  const resolvers = {
+    listEvent: async () => []
+  }
+
+  const app = Fastify()
+
+  try {
+    app.register(GQL, {
+      schema,
+      resolvers
+    })
+    await app.ready()
+  } catch (error) {
+    t.equal(error.message, 'Schema issues, check out the .errors property on the Error.')
     t.equal(error.name, 'Error')
+    t.equal(error.errors[0].message, 'Interface field Event.Id expected but CustomEvent does not provide it.')
+    t.equal(error.errors[0].name, 'GraphQLError')
+    t.equal(error.errors[1].message, 'Interface field Event.Id expected but AnotherEvent does not provide it.')
+    t.equal(error.errors[1].name, 'GraphQLError')
   }
 })