Skip to content

Commit

Permalink
feat: Add extensions field to the subscribe message payload
Browse files Browse the repository at this point in the history
  • Loading branch information
enisdenjo committed May 31, 2021
1 parent 7fa963d commit d86a8e4
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
1 change: 1 addition & 0 deletions PROTOCOL.md
Expand Up @@ -72,6 +72,7 @@ interface SubscribeMessage {
operationName?: string | null;
query: string;
variables?: Record<string, unknown> | null;
extensions?: Record<string, unknown> | null;
};
}
```
Expand Down
7 changes: 7 additions & 0 deletions docs/interfaces/common.subscribepayload.md
Expand Up @@ -8,12 +8,19 @@

### Properties

- [extensions](common.subscribepayload.md#extensions)
- [operationName](common.subscribepayload.md#operationname)
- [query](common.subscribepayload.md#query)
- [variables](common.subscribepayload.md#variables)

## Properties

### extensions

`Optional` `Readonly` **extensions**: ``null`` \| *Record*<string, unknown\>

___

### operationName

`Optional` `Readonly` **operationName**: ``null`` \| *string*
Expand Down
7 changes: 6 additions & 1 deletion src/common.ts
Expand Up @@ -94,6 +94,7 @@ export interface SubscribePayload {
readonly operationName?: string | null;
readonly query: string;
readonly variables?: Record<string, unknown> | null;
readonly extensions?: Record<string, unknown> | null;
}

/** @category Common */
Expand Down Expand Up @@ -171,7 +172,11 @@ export function isMessage(val: unknown): val is Message {
(!hasOwnProperty(val.payload, 'variables') ||
val.payload.variables === undefined ||
val.payload.variables === null ||
hasOwnObjectProperty(val.payload, 'variables'))
hasOwnObjectProperty(val.payload, 'variables')) &&
(!hasOwnProperty(val.payload, 'extensions') ||
val.payload.extensions === undefined ||
val.payload.extensions === null ||
hasOwnObjectProperty(val.payload, 'extensions'))
);
case MessageType.Next:
return (
Expand Down
4 changes: 3 additions & 1 deletion src/tests/client.ts
Expand Up @@ -422,7 +422,7 @@ describe('query operation', () => {
await sub.waitForComplete();
});

it('should accept nullish value for `operationName` and `variables`', async () => {
it('should accept nullish value for `operationName`, `variables` and `extensions`', async () => {
const { url } = await startTServer();

const client = createClient({
Expand All @@ -441,13 +441,15 @@ describe('query operation', () => {
operationName: undefined,
query: 'query { getValue }',
variables: undefined,
extensions: undefined,
}).waitForComplete();

// null
await tsubscribe(client, {
operationName: null,
query: 'query { getValue }',
variables: null,
extensions: null,
}).waitForComplete();
});
});
Expand Down

0 comments on commit d86a8e4

Please sign in to comment.