Skip to content

Commit

Permalink
Exit pre-release mode (#525)
Browse files Browse the repository at this point in the history
* add test for page queries with sessions

* fix link and unset pre-release mode

* remove more SITE_URLs

* fix protocol in doc links

* update contextError message

* fix test name
  • Loading branch information
AlecAivazis authored Sep 9, 2022
1 parent 0944656 commit 345cba8
Show file tree
Hide file tree
Showing 11 changed files with 57 additions and 65 deletions.
2 changes: 1 addition & 1 deletion .changeset/pre.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"mode": "pre",
"mode": "exit",
"tag": "next",
"initialVersions": {
"houdini": "0.15.8",
Expand Down
1 change: 1 addition & 0 deletions integration/src/lib/utils/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export const routes = {
Plugin_load_loadAndGlobal: '/plugin/load/inlineAndGlobal',
Plugin_load_list: '/plugin/load/list',
Plugin_load_pageQuery: '/plugin/load/pageQuery',
Plugin_load_pageQuerySession: '/plugin/load/pageQuery-session',

Pagination_query_forward_cursor: '/pagination/query/forward-cursor',
Pagination_query_backwards_cursor: '/pagination/query/backwards-cursor',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
query PageQuerySession {
session
}
12 changes: 12 additions & 0 deletions integration/src/routes/plugin/load/pageQuery-session/+page.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<script lang="ts">
import type { PageData } from './$houdini';
export let data: PageData;
$: ({ PageQuerySession } = data);
</script>

<h1>SSR Session</h1>

<div id="result">
{$PageQuerySession.data?.session}
</div>
13 changes: 13 additions & 0 deletions integration/src/routes/plugin/load/pageQuery-session/spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { test } from '@playwright/test';
import { routes } from '../../../../lib/utils/routes.js';
import { expectToBe, expect_0_gql } from '../../../../lib/utils/testsHelper.js';

test.describe('Page Query with Session', () => {
test('No GraphQL request & Should display the session token', async ({ page }) => {
await page.goto(routes.Plugin_load_pageQuerySession);

await expect_0_gql(page);

await expectToBe(page, '1234-Houdini-Token-5678');
});
});
3 changes: 0 additions & 3 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@ export default {
nodeResolve({ preferBuiltins: true }),
replace({
HOUDINI_VERSION: packgeJSON.version,
SITE_URL: fs.existsSync('./.changeset/pre.json')
? 'https://docs-next-kohl.vercel.app'
: 'https://houdinigraphql.com',
}),
],
}
6 changes: 3 additions & 3 deletions src/cmd/generators/definitions/schema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ test('adds internal documents to schema', async function () {
"""
@paginate is used to to mark a field for pagination.
More info in the [doc](SITE_URL/guides/pagination).
More info in the [doc](https://houdinigraphql.com/guides/pagination).
"""
directive @paginate(name: String) on FIELD
Expand Down Expand Up @@ -96,7 +96,7 @@ test('list operations are included', async function () {
"""
@paginate is used to to mark a field for pagination.
More info in the [doc](SITE_URL/guides/pagination).
More info in the [doc](https://houdinigraphql.com/guides/pagination).
"""
directive @paginate(name: String) on FIELD
Expand Down Expand Up @@ -176,7 +176,7 @@ test("writing twice doesn't duplicate definitions", async function () {
"""
@paginate is used to to mark a field for pagination.
More info in the [doc](SITE_URL/guides/pagination).
More info in the [doc](https://houdinigraphql.com/guides/pagination).
"""
directive @paginate(name: String) on FIELD
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ export function graphql(str: TemplateStringsArray): any {
// if this is executed, the preprocessor is not enabled
throw new Error(`⚠️ graphql template was invoked at runtime. This should never happen and usually means that your project isn't properly configured.
Please make sure you have the appropriate plugin/preprocessor enabled. For more information, visit this link: SITE_URL/guides/setting-up-your-project
Please make sure you have the appropriate plugin/preprocessor enabled. For more information, visit this link: https://houdinigraphql.com/guides/setting-up-your-project
`)
}
2 changes: 1 addition & 1 deletion src/runtime/lib/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const siteURL = 'SITE_URL'
export const siteURL = 'https://houdinigraphql.com'

/**
* @param focus example "#0160"
Expand Down
41 changes: 7 additions & 34 deletions src/runtime/stores/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -422,42 +422,15 @@ export async function fetchParams<_Data extends GraphQLObject, _Input>(
const contextError = (storeName: string) => `
${log.red(`Missing event args in load function`)}.
Three options:
${log.cyan('1/ Prefetching & SSR')}
<script context="module" lang="ts">
import type { LoadEvent } from '@sveltejs/kit';
Please remember to pass event to fetch like so:
export async function load(${log.yellow('event')}: LoadEvent) {
const variables = { ... };
await ${log.cyan(storeName)}.fetch({ ${log.yellow('event')}, variables });
return { props: { variables } };
}
</script>
<script lang="ts">
import { type ${log.cyan(storeName)}$input } from '$houdini'
export let variables: ${log.cyan(storeName)}$input;
$: browser && ${log.cyan(storeName)}.fetch({ variables });
</script>
${log.cyan('2/ Client only')}
<script lang="ts">
$: browser && ${log.cyan(storeName)}.fetch({ variables: { ... } });
</script>
${log.cyan('3/ Endpoint')}
import { ${log.cyan(storeName)} } from '$houdini';
export async function get(event) {
return {
props: {
data: await ${log.cyan(storeName)}.fetch({ event })
}
};
}
import type { LoadEvent } from '@sveltejs/kit';
export async function load(${log.yellow('event')}: LoadEvent) {
return {
...load_MyQuery({ ${log.yellow('event')}, variables: { ... } })
};
}
`

type FetchGlobalParams<_Data extends GraphQLObject, _Input> = {
Expand Down
37 changes: 15 additions & 22 deletions src/vite/fsPatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ filesystem.statSync = function (filepath: string, options: Parameters<filesystem
const result = _statSync(filepath, options)
return result
} catch (error) {
return virtualFile(path.basename(filepath), { withFileTypes: true })
return virtual_file(path.basename(filepath), { withFileTypes: true })
}
}

Expand All @@ -112,51 +112,44 @@ filesystem.readdirSync = function (
// WORKAROUND: Using `unknown` type because our inherited options are not fully exhaustive.
const result: unknown[] = _readDirSync(filepath, options)

function getFileName(file: unknown) {
const file_names = result.map((file) => {
if (file instanceof Dirent) {
return file.name
} else if (typeof file === 'string') {
return file
} else {
return ''
}
}

function hasFileName(...names: string[]) {
return result.some((file) => {
return names.includes(getFileName(file))
})
})
function contains(...names: string[]) {
return names.some((name) => file_names.includes(name))
}

// if there is a route component but no script, add the script
if (
hasFileName('+page.svelte') &&
!hasFileName('+page.js', '+page.ts', '+page.server.js', '+page.server.ts')
contains('+page.svelte') &&
!contains('+page.js', '+page.ts', '+page.server.js', '+page.server.ts')
) {
result.push(virtualFile('+page.js', options))
result.push(virtual_file('+page.js', options))
}

// if there is a layout file but no layout.js, we need to make one
const layoutLoadFiles = ['+layout.ts', '+layout.js']
if (
hasFileName('+layout.svelte') &&
!result.find((fp) => layoutLoadFiles.includes(getFileName(fp)))
) {
result.push(virtualFile('+layout.js', options))
if (contains('+layout.svelte') && !contains('+layout.ts', '+layout.js')) {
result.push(virtual_file('+layout.js', options))
}

// if we are in looking inside of src/routes and there's no +layout.svelte file
// we need to create one
if (is_root_layout(filepath.toString()) && !hasFileName('+layout.svelte')) {
result.push(virtualFile('+layout.svelte', options))
if (is_root_layout(filepath.toString()) && !contains('+layout.svelte')) {
result.push(virtual_file('+layout.svelte', options))
}
// if we are in looking inside of src/routes and there's no +layout.server.js file
// we need to create one
if (
is_root_layout(filepath.toString()) &&
!hasFileName('+layout.server.js', '+layout.server.ts')
!contains('+layout.server.js', '+layout.server.ts')
) {
result.push(virtualFile('+layout.server.js', options))
result.push(virtual_file('+layout.server.js', options))
}

// we're done modifying the results
Expand All @@ -169,7 +162,7 @@ Object.defineProperty(globalThis, 'fs', {
value: filesystem,
})

function virtualFile(name: string, options: Parameters<typeof filesystem.readdirSync>[1]) {
function virtual_file(name: string, options: Parameters<typeof filesystem.readdirSync>[1]) {
return !options?.withFileTypes
? name
: {
Expand Down

1 comment on commit 345cba8

@vercel
Copy link

@vercel vercel bot commented on 345cba8 Sep 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.