forked from redwoodjs/redwood
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: Configure Redwood Realtime in GraphQL Yoga (redwoodjs#8397)
* Implement useRedwoodLiveQuery * Test useRedwoodLiveQuery * Rename to Realtime, add pub sub * Handle RedwoodRealtimeOptions and auto allow subs if ok * Refactor for realtime yoga config * Document realtime types * Apply suggestions from code review * Fix yarn.lock * Changes PubSub type * include the live directive for realtime support * Adds realtime graphql schema test case for live query directive * Ensure live query actually added to schema (just once) * Remove stray console.debug * yarn dedupe * Update test snapshot * Update packages/graphql-server/src/createGraphQLYoga.ts Co-authored-by: Josh GM Walker <56300765+Josh-Walker-GM@users.noreply.github.com> * Improved the should update schema with live directive test --------- Co-authored-by: Josh GM Walker <56300765+Josh-Walker-GM@users.noreply.github.com>
- Loading branch information
1 parent
46df16b
commit 29edb41
Showing
25 changed files
with
556 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
packages/graphql-server/src/plugins/__tests__/__snapshots__/useRedwoodRealtime.test.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`useRedwoodRealtime should update schema with live directive 1`] = `"@live"`; |
62 changes: 62 additions & 0 deletions
62
packages/graphql-server/src/plugins/__tests__/useRedwoodRealtime.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { | ||
createTestkit, | ||
createSpiedPlugin, | ||
assertStreamExecutionValue, | ||
} from '@envelop/testing' | ||
|
||
import { testLiveQuery, testSchema } from '../__fixtures__/common' | ||
import { | ||
useRedwoodRealtime, | ||
InMemoryLiveQueryStore, | ||
} from '../useRedwoodRealtime' | ||
|
||
describe('useRedwoodRealtime', () => { | ||
const liveQueryStore = new InMemoryLiveQueryStore() | ||
|
||
it('should support a @live query directive', async () => { | ||
const testkit = createTestkit( | ||
[useRedwoodRealtime({ liveQueries: { liveQueryStore } })], | ||
testSchema | ||
) | ||
|
||
const result = await testkit.execute(testLiveQuery, {}, {}) | ||
|
||
assertStreamExecutionValue(result) | ||
const current = await result.next() | ||
expect(current.value).toMatchInlineSnapshot(` | ||
{ | ||
"data": { | ||
"me": { | ||
"id": "1", | ||
"name": "Ba Zinga", | ||
}, | ||
}, | ||
"isLive": true, | ||
} | ||
`) | ||
}) | ||
|
||
it('should update schema with live directive', async () => { | ||
const spiedPlugin = createSpiedPlugin() | ||
|
||
// the original schema should not have the live directive before the useRedwoodRealtime plugin is applied | ||
expect(testSchema.getDirective('live')).toBeUndefined() | ||
|
||
createTestkit( | ||
[ | ||
useRedwoodRealtime({ liveQueries: { liveQueryStore } }), | ||
spiedPlugin.plugin, | ||
], | ||
testSchema | ||
) | ||
|
||
// the replaced schema should have the live directive afterwards | ||
const replacedSchema = | ||
spiedPlugin.spies.onSchemaChange.mock.calls[0][0].schema | ||
|
||
const liveDirectiveOnSchema = replacedSchema.getDirective('live') | ||
|
||
expect(liveDirectiveOnSchema.name).toEqual('live') | ||
expect(replacedSchema.getDirective('live')).toMatchSnapshot() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.