-
Notifications
You must be signed in to change notification settings - Fork 7
Subscribe #121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Subscribe #121
Changes from 7 commits
756ff23
281039d
e21bfb0
19cc8ee
23c78cc
572135f
422f8d0
eff2051
ec8d96c
a0dde86
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -36,6 +36,7 @@ | |
| "scripts": { | ||
| "build": "rimraf dist && tsc", | ||
| "test": "jest --runInBand --coverage", | ||
| "testOnly": "jest --runInBand", | ||
| "coveralls": "cat ./coverage/lcov.info | coveralls", | ||
| "lint": "eslint src", | ||
| "format": "prettier --write \"src/**/*.ts\"", | ||
|
|
@@ -79,6 +80,7 @@ | |
| "graphql": "15.1.0", | ||
| "graphql-middleware": "4.0.2", | ||
| "graphql-scalars": "1.1.5", | ||
| "graphql-subscriptions": "^1.1.0", | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion: This should be in |
||
| "graphql-tag": "2.10.3", | ||
| "husky": "4.2.5", | ||
| "jest": "26.0.1", | ||
|
|
@@ -95,4 +97,4 @@ | |
| "peerDependencies": { | ||
| "graphql": "^14.0.0 || ^15.0.0" | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| import { createSqlmancerClient } from '../../' | ||
| import { SqlmancerClient } from './sqlmancer' | ||
| import { PubSub } from 'graphql-subscriptions' | ||
|
|
||
| export const client = createSqlmancerClient<SqlmancerClient>(__dirname + '/schema.ts', require('./knex')) | ||
| export const client = createSqlmancerClient<SqlmancerClient>(__dirname + '/schema.ts', require('./knex'), new PubSub()) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,10 @@ | ||
| /* eslint-disable jest/require-top-level-describe */ | ||
| /* eslint-disable no-useless-escape */ | ||
| import { graphql, validateSchema } from 'graphql' | ||
| import { schema, client } from './schema' | ||
| import { graphql, validateSchema, subscribe, parse, ExecutionResult } from 'graphql' | ||
| import { schema, client, pubsub } from './schema' | ||
| import { EventEmitter } from 'events' | ||
| import { mockResolveInfo } from '../utilities' | ||
|
|
||
|
|
||
| const describeMaybeSkip = process.env.DB && !process.env.DB.split(' ').includes('postgres') ? describe.skip : describe | ||
|
|
||
|
|
@@ -394,4 +397,55 @@ describeMaybeSkip('integration (postgres)', () => { | |
| expect(errors).toBeUndefined() | ||
| expect(data?.films.some((f: any) => f.sequel && f.sequel.id)).toBe(true) | ||
| }) | ||
|
|
||
| test('subscriptions', async () => { | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion: This test can be removed. This test is extraneous because it's not testing anything specific to the library. |
||
| const document = parse(` | ||
| subscription { | ||
| create | ||
| } | ||
| `) | ||
|
|
||
| const sub = <AsyncIterator<ExecutionResult>>await subscribe(schema, document); | ||
| expect(sub.next).toBeDefined() | ||
| setImmediate(() => pubsub.publish('CREATE_ONE', { create: "FLUM!" })) | ||
JeffML marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| const { value: { errors, data } } = await sub.next() | ||
|
|
||
| expect(errors).toBeUndefined() | ||
| expect(data).toBeDefined() | ||
| expect(data.create).toBe('FLUM!') | ||
| }) | ||
|
|
||
| // this test times out (sub.next() does not return) | ||
JeffML marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| test.skip('subscription triggered by mutation', async () => { | ||
| const document = parse(` | ||
| subscription { | ||
| create | ||
| } | ||
| `) | ||
|
|
||
|
|
||
| const query = `mutation { | ||
| createCustomerWithPayload { | ||
| customer { | ||
| id | ||
| } | ||
| } | ||
| }` | ||
|
|
||
| const sub = <AsyncIterator<ExecutionResult>>await subscribe(schema, document); | ||
| expect(sub.next).toBeDefined() | ||
|
|
||
| const info = await mockResolveInfo(schema, 'Mutation', 'createCustomerWithPayload', query) | ||
| expect(info).toBeDefined() | ||
| expect(info.operation).toBeDefined() | ||
| expect(info.operation.operation).toBeDefined() | ||
| expect(info.operation.operation).toBe('mutation') | ||
|
|
||
| const { value: { errors, data } } = await sub.next() | ||
|
|
||
| expect(errors).toBeUndefined() | ||
| expect(data.event).toBeDefined() | ||
| }, 10000) | ||
| }) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion:
sakila.dbis created and modified while running the SQLite integration tests. We don't want to check it by accident, so this should be left as-is.