-
-
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.
* find_graphql looks for graphql function * dry up js and svelte processing * extract load functions * reactive transform respect graphql functions * cleanup * add graphql_tag_export to plugins * compute overloaded return values * generate graphql overloads * remove unused import and types * fix extraction * tests pass * support root graphql functions too * unused import * changeset * generate typedefs for fragment functions * linter * linter and update snapshots * update snapshots * update all docs to use graphql function * remove unnecessary type import * add graphql function to release notes * doc tweak * missed one * clean up comments * can -> should * docs housekeeping * remove file * include paginated fragments as valid args to fragment
- Loading branch information
1 parent
f0ac816
commit 8f70291
Showing
50 changed files
with
1,257 additions
and
315 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,6 @@ | ||
--- | ||
'houdini': patch | ||
'houdini-svelte': patch | ||
--- | ||
|
||
graphql template tag can now be used as a function for automatic typing |
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
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
21 changes: 8 additions & 13 deletions
21
e2e/sveltekit/src/routes/pagination/fragment/offset/+page.svelte
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 |
---|---|---|
@@ -1,33 +1,28 @@ | ||
<script lang="ts"> | ||
import { | ||
paginatedFragment, | ||
graphql, | ||
type OffsetFragment, | ||
type UserFragmentOffsetQueryStore | ||
} from '$houdini'; | ||
import { paginatedFragment, graphql } from '$houdini'; | ||
const queryResult: UserFragmentOffsetQueryStore = graphql` | ||
const queryResult = graphql(` | ||
query UserFragmentOffsetQuery { | ||
user(id: "1", snapshot: "pagination-fragment-offset") { | ||
...OffsetFragment | ||
} | ||
} | ||
`; | ||
`); | ||
const fragmentResult = paginatedFragment<OffsetFragment>( | ||
const fragmentResult = paginatedFragment( | ||
$queryResult.data?.user ?? null, | ||
graphql` | ||
graphql(` | ||
fragment OffsetFragment on User { | ||
friendsList(limit: 2) @paginate { | ||
name | ||
} | ||
} | ||
` | ||
`) | ||
); | ||
</script> | ||
|
||
<div id="result"> | ||
{$fragmentResult.data?.friendsList.map((node) => node?.name).join(', ')} | ||
{$fragmentResult?.data?.friendsList.map((node) => node?.name).join(', ')} | ||
</div> | ||
|
||
<button id="next" on:click={() => fragmentResult.loadNextPage()}>next</button> | ||
<button id="next" on:click={() => fragmentResult?.loadNextPage()}>next</button> |
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
89 changes: 89 additions & 0 deletions
89
packages/houdini-svelte/src/plugin/codegen/fragmentTypedefs/fragmentTypedefs.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,89 @@ | ||
import { parseJS, fs, path } from 'houdini' | ||
import { mockCollectedDoc, testConfig } from 'houdini/test' | ||
import { test, expect } from 'vitest' | ||
|
||
import generate from '..' | ||
|
||
const config = testConfig() | ||
const plugin_root = config.pluginDirectory('hodini-svelte') | ||
|
||
test('generates types for fragments', async function () { | ||
// create the mock filesystem | ||
await fs.mock({ | ||
[path.join(config.pluginDirectory('houdini-svelte'), 'runtime', 'fragments.d.ts')]: ` | ||
import { Fragment } from '$houdini/runtime/lib/types'; | ||
import { Readable } from 'svelte/store'; | ||
import { FragmentStore } from './stores'; | ||
import type { FragmentStorePaginated } from './stores/pagination/fragment'; | ||
export declare function fragment<_Fragment extends Fragment<any>>(ref: _Fragment, fragment: FragmentStore<_Fragment['shape']>): Readable<NonNullable<_Fragment['shape']>> & { | ||
data: Readable<_Fragment>; | ||
}; | ||
export declare function fragment<_Fragment extends Fragment<any>>(ref: _Fragment | null, fragment: FragmentStore<_Fragment['shape']>): Readable<NonNullable<_Fragment['shape']> | null> & { | ||
data: Readable<_Fragment | null>; | ||
}; | ||
export declare function paginatedFragment<_Fragment extends Fragment<any>>(initialValue: _Fragment | null, document: FragmentStore<_Fragment['shape']>): FragmentStorePaginated<_Fragment['shape'], {}>; | ||
export declare function paginatedFragment<_Fragment extends Fragment<any>>(initialValue: _Fragment, document: FragmentStore<_Fragment['shape']>): FragmentStorePaginated<_Fragment['shape'], {}>; | ||
`, | ||
}) | ||
|
||
// execute the generator | ||
await generate({ | ||
config, | ||
documents: [mockCollectedDoc(`fragment TestFragment on Query { viewer { id } } `)], | ||
framework: 'kit', | ||
plugin_root, | ||
}) | ||
|
||
// load the contents of the file | ||
const queryContents = await fs.readFile( | ||
path.join(config.pluginRuntimeDirectory('houdini-svelte'), 'fragments.d.ts') | ||
) | ||
|
||
expect(queryContents).toBeTruthy() | ||
|
||
//the parser doesn't work right but the type imports are correct. | ||
const parsedQuery = (await parseJS(queryContents!))?.script | ||
|
||
// verify contents | ||
expect(parsedQuery).toMatchInlineSnapshot(` | ||
import { TestFragmentStore } from "../stores/TestFragment"; | ||
import { Fragment } from "$houdini/runtime/lib/types"; | ||
import { Readable } from "svelte/store"; | ||
import { FragmentStore } from "./stores"; | ||
import type { FragmentStorePaginated } from "./stores/pagination/fragment"; | ||
export function fragment( | ||
initialValue: { | ||
$fragments: { | ||
TestFragment: true; | ||
}; | ||
}, | ||
document: TestFragmentStore | ||
): ReturnType<TestFragmentStore["get"]>; | ||
export function fragment( | ||
initialValue: { | ||
$fragments: { | ||
TestFragment: true; | ||
}; | ||
} | null, | ||
document: TestFragmentStore | ||
): ReturnType<TestFragmentStore["get"]> | null; | ||
export declare function fragment<_Fragment extends Fragment<any>>(ref: _Fragment, fragment: FragmentStore<_Fragment["shape"]>): Readable<NonNullable<_Fragment["shape"]>> & { | ||
data: Readable<_Fragment>; | ||
}; | ||
export declare function fragment<_Fragment extends Fragment<any>>(ref: _Fragment | null, fragment: FragmentStore<_Fragment["shape"]>): Readable<NonNullable<_Fragment["shape"]> | null> & { | ||
data: Readable<_Fragment | null>; | ||
}; | ||
export declare function paginatedFragment<_Fragment extends Fragment<any>>( | ||
initialValue: _Fragment | null, | ||
document: FragmentStore<_Fragment["shape"]> | ||
): FragmentStorePaginated<_Fragment["shape"], {}>; | ||
export declare function paginatedFragment<_Fragment extends Fragment<any>>(initialValue: _Fragment, document: FragmentStore<_Fragment["shape"]>): FragmentStorePaginated<_Fragment["shape"], {}>; | ||
`) | ||
}) |
Oops, something went wrong.