diff --git a/.changeset/violet-planets-bow.md b/.changeset/violet-planets-bow.md new file mode 100644 index 0000000000..25e5dbfabb --- /dev/null +++ b/.changeset/violet-planets-bow.md @@ -0,0 +1,6 @@ +--- +"grafast": patch +--- + +Fix bug handling an error raised in subscribePlan execution that was resulting +in websocket closure. diff --git a/grafast/grafast/src/prepare.ts b/grafast/grafast/src/prepare.ts index a527b3a8fe..86e639de8d 100644 --- a/grafast/grafast/src/prepare.ts +++ b/grafast/grafast/src/prepare.ts @@ -427,12 +427,12 @@ function executePreemptive( // Something major went wrong! const errors = [ new GraphQLError( - bucketRootValue.originalError.message, + bucketRootValue.message, operationPlan.rootOutputPlan.locationDetails.node, // node undefined, // source null, // positions null, // path - bucketRootValue.originalError, // originalError + bucketRootValue, // originalError null, // extensions ), ]; diff --git a/postgraphile/postgraphile/graphile.config.ts b/postgraphile/postgraphile/graphile.config.ts index 04b48dbcf8..cc8d4edcc4 100644 --- a/postgraphile/postgraphile/graphile.config.ts +++ b/postgraphile/postgraphile/graphile.config.ts @@ -384,6 +384,28 @@ const preset: GraphileConfig.Preset = { }, }, }), + makeExtendSchemaPlugin({ + typeDefs: gql` + extend type Subscription { + error: Int + } + `, + plans: { + Subscription: { + error: { + subscribePlan: EXPORTABLE( + (constant, lambda) => + function subscribePlan() { + return lambda(constant(3), () => { + throw new Error("Testing error"); + }); + }, + [constant, lambda], + ), + }, + }, + }, + }), // PrimaryKeyMutationsOnlyPlugin, PersistedPlugin, makeRuruTitlePlugin(""),