Skip to content

Commit

Permalink
more updates to the hooks changeset
Browse files Browse the repository at this point in the history
  • Loading branch information
enisdenjo committed Jan 15, 2025
1 parent 8d30500 commit c0002ef
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions .changeset/strange-ties-mix.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ Additionally, the `onOperation`, `onError`, `onNext` and `onComplete` now have t
#### `schema`

```diff
import { ExecutionArgs } from 'graphql';
import { ServerOptions, SubscribePayload } from 'graphql-ws';

const opts: ServerOptions = {
- schema(ctx, message) {
- schema(ctx, message, argsWithoutSchema: Omit<ExecutionArgs, 'schema'>) {
- const messageId = message.id;
- const messagePayload: SubscribePayload = message.payload;
- },
Expand All @@ -32,14 +33,15 @@ const opts: ServerOptions = {
#### `context`

```diff
import { ExecutionArgs } from 'graphql';
import { ServerOptions, SubscribePayload } from 'graphql-ws';

const opts: ServerOptions = {
- context(ctx, message) {
- context(ctx, message, args: ExecutionArgs) {
- const messageId = message.id;
- const messagePayload: SubscribePayload = message.payload;
- },
+ context(ctx, id, payload) {
+ context(ctx, id, payload, args: ExecutionArgs) {
+ const messageId = id;
+ const messagePayload: SubscribePayload = payload;
+ },
Expand Down Expand Up @@ -69,14 +71,14 @@ The `SubscribeMessage.payload` is not useful here at all, the `payload` has been

```diff
import { ExecutionArgs } from 'graphql';
import { ServerOptions, SubscribePayload } from 'graphql-ws';
import { ServerOptions, SubscribePayload, OperationResult } from 'graphql-ws';

const opts: ServerOptions = {
- onOperation(ctx, message) {
- onOperation(ctx, message, args: ExecutionArgs, result: OperationResult) {
- const messageId = message.id;
- const messagePayload: SubscribePayload = message.payload;
- },
+ onOperation(ctx, id, payload) {
+ onOperation(ctx, id, payload, args: ExecutionArgs, result: OperationResult) {
+ const messageId = id;
+ const messagePayload: SubscribePayload = payload;
+ },
Expand Down Expand Up @@ -111,18 +113,16 @@ const opts: ServerOptions = {
The `NextMessage.payload` (`FormattedExecutionResult`) is not useful here at all, the user has access to `ExecutionResult` that contains actual object references to error instances. The user can always convert and return `FormattedExecutionResult` by serialising the errors with `GraphQLError.toJSON()` method.

```diff
import { ExecutionResult, FormattedExecutionResult } from 'graphql';
import { ExecutionArgs, ExecutionResult, FormattedExecutionResult } from 'graphql';
import { ServerOptions, SubscribePayload } from 'graphql-ws';

const opts: ServerOptions = {
- onNext(ctx, message, _args, result) {
- onNext(ctx, message, args: ExecutionArgs, result: ExecutionResult) {
- const messageId = message.id;
- const graphqlResult: ExecutionResult = result;
- const nextMessagePayload: FormattedExecutionResult = message.payload;
- },
+ onNext(ctx, id, payload, _args, result) {
+ onNext(ctx, id, payload, args: ExecutionArgs, result: ExecutionResult) {
+ const messageId = id;
+ const graphqlResult: ExecutionResult = result;
+ const subscribeMessagePayload: SubscribePayload = payload;
+ const nextMessagePayload: FormattedExecutionResult = { ...result, errors: result.errors?.map((e) => e.toJSON()) };
+ },
Expand Down

0 comments on commit c0002ef

Please sign in to comment.