-
-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix double import in generated subscription stores (#689)
* fix double import of subscription store * add happy path tests for generated stores * changeset * fix comment
- Loading branch information
1 parent
36401fa
commit db67e82
Showing
7 changed files
with
184 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'houdini-svelte': patch | ||
--- | ||
|
||
Fix duplicate import for generated subscription stores |
62 changes: 62 additions & 0 deletions
62
packages/houdini-svelte/src/plugin/codegen/stores/fragment.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 { fs, CollectedGraphQLDocument, path } from 'houdini' | ||
import { mockCollectedDoc } from 'houdini/test' | ||
import * as recast from 'recast' | ||
import * as typeScriptParser from 'recast/parsers/typescript' | ||
import { test, expect } from 'vitest' | ||
|
||
import runPipeline from '..' | ||
import '../..' | ||
import { test_config } from '../../../test' | ||
import { stores_directory } from '../../kit' | ||
|
||
test('generates a store for every query', async function () { | ||
const config = await test_config() | ||
const plugin_root = config.pluginDirectory('test-plugin') | ||
|
||
// the documents to test | ||
const docs: CollectedGraphQLDocument[] = [ | ||
mockCollectedDoc(`fragment TestFragment1 on User { id }`), | ||
mockCollectedDoc(`fragment TestFragment2 on User { id }`), | ||
] | ||
|
||
// execute the generator | ||
await runPipeline({ config, documents: docs, plugin_root, framework: 'kit' }) | ||
|
||
// look up the files in the artifact directory | ||
const files = await fs.readdir(stores_directory(plugin_root)) | ||
|
||
// and they have the right names | ||
expect(files).toEqual(expect.arrayContaining(['TestFragment1.js', 'TestFragment2.js'])) | ||
// and type definitions exist | ||
expect(files).toEqual(expect.arrayContaining(['TestFragment1.d.ts', 'TestFragment2.d.ts'])) | ||
|
||
const contents = await fs.readFile(path.join(stores_directory(plugin_root), 'TestFragment1.js')) | ||
const parsed = recast.parse(contents!, { | ||
parser: typeScriptParser, | ||
}).program | ||
|
||
await expect(parsed).toMatchInlineSnapshot( | ||
` | ||
import { FragmentStore } from '$houdini/plugins/houdini-svelte/runtime/stores' | ||
import artifact from '$houdini/artifacts/TestFragment1' | ||
// create the fragment store | ||
export class TestFragment1Store extends FragmentStore { | ||
constructor() { | ||
super({ | ||
artifact, | ||
storeName: "TestFragment1Store", | ||
variables: true, | ||
}) | ||
} | ||
} | ||
export const GQL_TestFragment1 = new TestFragment1Store() | ||
export default GQL_TestFragment1 | ||
` | ||
) | ||
}) |
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
56 changes: 56 additions & 0 deletions
56
packages/houdini-svelte/src/plugin/codegen/stores/mutation.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,56 @@ | ||
import { fs, CollectedGraphQLDocument, path } from 'houdini' | ||
import { mockCollectedDoc } from 'houdini/test' | ||
import * as recast from 'recast' | ||
import * as typeScriptParser from 'recast/parsers/typescript' | ||
import { test, expect } from 'vitest' | ||
|
||
import runPipeline from '..' | ||
import '../..' | ||
import { test_config } from '../../../test' | ||
import { stores_directory } from '../../kit' | ||
|
||
test('generates a store for every query', async function () { | ||
const config = await test_config() | ||
const plugin_root = config.pluginDirectory('test-plugin') | ||
|
||
// the documents to test | ||
const docs: CollectedGraphQLDocument[] = [ | ||
mockCollectedDoc(`mutation TestMutation1 { updateUser { id } }`), | ||
mockCollectedDoc(`mutation TestMutation2 { updateUser { id } }`), | ||
] | ||
|
||
// execute the generator | ||
await runPipeline({ config, documents: docs, plugin_root, framework: 'kit' }) | ||
|
||
// look up the files in the artifact directory | ||
const files = await fs.readdir(stores_directory(plugin_root)) | ||
|
||
// and they have the right names | ||
expect(files).toEqual(expect.arrayContaining(['TestMutation1.js', 'TestMutation2.js'])) | ||
// and type definitions exist | ||
expect(files).toEqual(expect.arrayContaining(['TestMutation1.d.ts', 'TestMutation2.d.ts'])) | ||
|
||
const contents = await fs.readFile(path.join(stores_directory(plugin_root), 'TestMutation1.js')) | ||
const parsed = recast.parse(contents!, { | ||
parser: typeScriptParser, | ||
}).program | ||
|
||
await expect(parsed).toMatchInlineSnapshot( | ||
` | ||
import artifact from '$houdini/artifacts/TestMutation1' | ||
import { MutationStore } from '$houdini/plugins/houdini-svelte/runtime/stores' | ||
export class TestMutation1Store extends MutationStore { | ||
constructor() { | ||
super({ | ||
artifact, | ||
}) | ||
} | ||
} | ||
export const GQL_TestMutation1 = new TestMutation1Store() | ||
export default GQL_TestMutation1 | ||
` | ||
) | ||
}) |
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
59 changes: 59 additions & 0 deletions
59
packages/houdini-svelte/src/plugin/codegen/stores/subscription.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,59 @@ | ||
import { fs, CollectedGraphQLDocument, path } from 'houdini' | ||
import { mockCollectedDoc } from 'houdini/test' | ||
import * as recast from 'recast' | ||
import * as typeScriptParser from 'recast/parsers/typescript' | ||
import { test, expect } from 'vitest' | ||
|
||
import runPipeline from '..' | ||
import '../..' | ||
import { test_config } from '../../../test' | ||
import { stores_directory } from '../../kit' | ||
|
||
test('generates a store for every query', async function () { | ||
const config = await test_config() | ||
const plugin_root = config.pluginDirectory('test-plugin') | ||
|
||
// the documents to test | ||
const docs: CollectedGraphQLDocument[] = [ | ||
mockCollectedDoc(`subscription TestSubscription1 { newUser { id } }`), | ||
mockCollectedDoc(`subscription TestSubscription2 { newUser { id } }`), | ||
] | ||
|
||
// execute the generator | ||
await runPipeline({ config, documents: docs, plugin_root, framework: 'kit' }) | ||
|
||
// look up the files in the artifact directory | ||
const files = await fs.readdir(stores_directory(plugin_root)) | ||
|
||
// and they have the right names | ||
expect(files).toEqual(expect.arrayContaining(['TestSubscription1.js', 'TestSubscription2.js'])) | ||
// and type definitions exist | ||
expect(files).toEqual( | ||
expect.arrayContaining(['TestSubscription1.d.ts', 'TestSubscription2.d.ts']) | ||
) | ||
|
||
const contents = await fs.readFile( | ||
path.join(stores_directory(plugin_root), 'TestSubscription1.js') | ||
) | ||
const parsed = recast.parse(contents!, { | ||
parser: typeScriptParser, | ||
}).program | ||
|
||
await expect(parsed).toMatchInlineSnapshot( | ||
` | ||
import { SubscriptionStore } from '$houdini/plugins/houdini-svelte/runtime/stores' | ||
export class TestSubscription1Store extends SubscriptionStore { | ||
constructor() { | ||
super({ | ||
artifact, | ||
}) | ||
} | ||
} | ||
export const GQL_TestSubscription1 = new TestSubscription1Store() | ||
export default GQL_TestSubscription1 | ||
` | ||
) | ||
}) |
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
db67e82
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.
Successfully deployed to the following URLs:
docs – ./site
docs-houdinigraphql.vercel.app
docs-git-main-houdinigraphql.vercel.app
houdinigraphql.com
www.houdinigraphql.com
docs-phi-fawn.vercel.app
db67e82
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.
Successfully deployed to the following URLs:
docs-next – ./site
docs-next-houdinigraphql.vercel.app
docs-next-git-main-houdinigraphql.vercel.app
docs-next-kohl.vercel.app