Skip to content

Commit

Permalink
Improved the should update schema with live directive test
Browse files Browse the repository at this point in the history
  • Loading branch information
dthyresson committed Jun 1, 2023
1 parent bb2b74c commit fc0cf00
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 150 deletions.
Original file line number Diff line number Diff line change
@@ -1,136 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`useRedwoodRealtime should update schema with live directive 1`] = `
[MockFunction] {
"calls": [
[
{
"replaceSchema": [Function],
"schema": GraphQLSchema {
"__validationErrors": [],
"_directives": [
"@live",
"@include",
"@skip",
"@deprecated",
"@specifiedBy",
],
"_implementationsMap": {},
"_mutationType": undefined,
"_queryType": "Query",
"_subTypeMap": {},
"_subscriptionType": undefined,
"_typeMap": {
"Boolean": "Boolean",
"ID": "ID",
"Int": "Int",
"Query": "Query",
"String": "String",
"User": "User",
"__Directive": "__Directive",
"__DirectiveLocation": "__DirectiveLocation",
"__EnumValue": "__EnumValue",
"__Field": "__Field",
"__InputValue": "__InputValue",
"__Schema": "__Schema",
"__Type": "__Type",
"__TypeKind": "__TypeKind",
},
"astNode": {
"description": undefined,
"directives": [],
"kind": "SchemaDefinition",
"operationTypes": [
{
"kind": "OperationTypeDefinition",
"operation": "query",
"type": {
"kind": "NamedType",
"name": {
"kind": "Name",
"value": "Query",
},
},
},
],
},
"description": undefined,
"extensionASTNodes": [],
"extensions": {
Symbol(useRedwoodRealtime.wasLiveQueryAdded): true,
},
},
},
],
[
{
"replaceSchema": [Function],
"schema": GraphQLSchema {
"__validationErrors": [],
"_directives": [
"@live",
"@include",
"@skip",
"@deprecated",
"@specifiedBy",
],
"_implementationsMap": {},
"_mutationType": undefined,
"_queryType": "Query",
"_subTypeMap": {},
"_subscriptionType": undefined,
"_typeMap": {
"Boolean": "Boolean",
"ID": "ID",
"Int": "Int",
"Query": "Query",
"String": "String",
"User": "User",
"__Directive": "__Directive",
"__DirectiveLocation": "__DirectiveLocation",
"__EnumValue": "__EnumValue",
"__Field": "__Field",
"__InputValue": "__InputValue",
"__Schema": "__Schema",
"__Type": "__Type",
"__TypeKind": "__TypeKind",
},
"astNode": {
"description": undefined,
"directives": [],
"kind": "SchemaDefinition",
"operationTypes": [
{
"kind": "OperationTypeDefinition",
"operation": "query",
"type": {
"kind": "NamedType",
"name": {
"kind": "Name",
"value": "Query",
},
},
},
],
},
"description": undefined,
"extensionASTNodes": [],
"extensions": {
Symbol(useRedwoodRealtime.wasLiveQueryAdded): true,
},
},
},
],
],
"results": [
{
"type": "return",
"value": undefined,
},
{
"type": "return",
"value": undefined,
},
],
}
`;
exports[`useRedwoodRealtime should update schema with live directive 1`] = `"@live"`;
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
assertStreamExecutionValue,
} from '@envelop/testing'

import { testLiveSchema, testLiveQuery } from '../__fixtures__/common'
import { testLiveQuery, testSchema } from '../__fixtures__/common'
import {
useRedwoodRealtime,
InMemoryLiveQueryStore,
Expand All @@ -16,7 +16,7 @@ describe('useRedwoodRealtime', () => {
it('should support a @live query directive', async () => {
const testkit = createTestkit(
[useRedwoodRealtime({ liveQueries: { liveQueryStore } })],
testLiveSchema
testSchema
)

const result = await testkit.execute(testLiveQuery, {}, {})
Expand All @@ -39,26 +39,24 @@ describe('useRedwoodRealtime', () => {
it('should update schema with live directive', async () => {
const spiedPlugin = createSpiedPlugin()

const testkit = createTestkit(
// 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,
],
testLiveSchema
testSchema
)

await testkit.execute(testLiveQuery, {}, {})
// the replaced schema should have the live directive afterwards
const replacedSchema =
spiedPlugin.spies.onSchemaChange.mock.calls[0][0].schema

const liveDirectiveOnSchema = replacedSchema.getDirective('live')

// the schema should have been updated with the live directive
// "schema": GraphQLSchema {
// "__validationErrors": [],
// "_directives": [
// "@live",
// "@include",
// "@skip",
// "@deprecated",
// "@specifiedBy",
// ],
expect(spiedPlugin.spies.onSchemaChange).toMatchSnapshot()
expect(liveDirectiveOnSchema.name).toEqual('live')
expect(replacedSchema.getDirective('live')).toMatchSnapshot()
})
})

0 comments on commit fc0cf00

Please sign in to comment.