Skip to content

Commit

Permalink
fix(client): Accept nullish values for operationName and variables
Browse files Browse the repository at this point in the history
  • Loading branch information
enisdenjo committed Oct 31, 2020
1 parent fd207e8 commit 2d60dda
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/message.ts
Expand Up @@ -101,10 +101,14 @@ export function isMessage(val: unknown): val is Message {
hasOwnStringProperty(val, 'id') &&
hasOwnObjectProperty(val, 'payload') &&
(!hasOwnProperty(val.payload, 'operationName') ||
hasOwnStringProperty(val.payload, 'operationName')) &&
val.payload.operationName === undefined ||
val.payload.operationName === null ||
typeof val.payload.operationName === 'string') &&
(hasOwnStringProperty(val.payload, 'query') || // string query or persisted query id
hasOwnObjectProperty(val.payload, 'query')) && // document node query
(!hasOwnProperty(val.payload, 'variables') ||
val.payload.variables === undefined ||
val.payload.variables === null ||
hasOwnObjectProperty(val.payload, 'variables'))
);
case MessageType.Next:
Expand Down
25 changes: 25 additions & 0 deletions src/tests/client.ts
Expand Up @@ -170,6 +170,31 @@ describe('query operation', () => {

await sub.waitForComplete();
});

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

const client = createClient({ url });

// nothing
await tsubscribe(client, {
query: 'query { getValue }',
}).waitForComplete();

// undefined
await tsubscribe(client, {
operationName: undefined,
query: 'query { getValue }',
variables: undefined,
}).waitForComplete();

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

describe('subscription operation', () => {
Expand Down

0 comments on commit 2d60dda

Please sign in to comment.