Skip to content

Commit

Permalink
Add toggle to docs between typescript and jsdocs (#791)
Browse files Browse the repository at this point in the history
* Tweak docs for endpoints (#785)

* ✏️ DOC: tweaks

* ✏️ FIX: \t to ' '

* Fix error when prerendering application (#786)

* don't add session infrastructure when static is set to true

* use existing static config value

* changeset

* unused import

* 📦 v0.19.2 (#788)

* 📦 v{VERSION}

* update changelogs

* oops

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Alec Aivazis <[email protected]>

* add js/ts toggle

* fix search input sizing

* duplicate code examples and implement toggle

* convert all blocks to typescript

* transform handles variable declaration type signatures

* transform function parameters

* transform svelte documents

* add type definitions to rest of getting started guide

* update guides

* add types to authentication docs

* remove semicolon

* update snapshots

* move typescript test to js

Co-authored-by: JYC <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
4 people authored Dec 26, 2022
1 parent 14ceac0 commit bf3e525
Show file tree
Hide file tree
Showing 57 changed files with 1,540 additions and 1,135 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ $houdini
build/**
dist/**
.next/**

vite.config.js.timestamp-*
2 changes: 1 addition & 1 deletion e2e/sveltekit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"prettier": "^2.5.1",
"prettier-plugin-svelte": "^2.5.0",
"svelte": "3.55.0",
"svelte-check": "^2.2.6",
"svelte-check": "^3.0.1",
"svelte-preprocess": "^5.0.0",
"tslib": "^2.3.1",
"typescript": "^4.9",
Expand Down
1 change: 1 addition & 0 deletions e2e/sveltekit/src/lib/utils/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const routes = {
Stores_SSR_One_Store_Multivariables: '/stores/ssr-one-store-multivariables',
Stores_Fragment_Null: '/stores/fragment-null',
Stores_Metadata: '/stores/metadata',
Stores_action_mutation: '/stores/action-mutation',
Stores_Endpoint_Query: '/stores/endpoint-query',
Stores_Endpoint_Mutation: '/stores/endpoint-mutation',
Stores_Session: '/stores/session',
Expand Down
26 changes: 26 additions & 0 deletions e2e/sveltekit/src/routes/stores/action-mutation/+page.server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { graphql } from '$houdini';
import { fail } from '@sveltejs/kit';

/** @type {import('./$types').Actions} */
export const actions = {
add: async (event) => {
const data = await event.request.formData();

const name = data.get('name')?.toString();

if (!name) {
return fail(403, { name: '*' });
}

const actionMutation = graphql(`
mutation ActionMutation($name: String!) {
addUser(name: $name, birthDate: 254143016000, snapshot: "ActionMutation") {
id
name
}
}
`);

return await actionMutation.mutate({ name });
}
};
21 changes: 21 additions & 0 deletions e2e/sveltekit/src/routes/stores/action-mutation/+page.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<script>
import { enhance } from '$app/forms';
/** @type {import('./$types').ActionData} */
export let form;
</script>

<form method="POST" action="?/add" use:enhance>
<label>
Name
<input name="name" type="name" />
</label>
<span id="name-error"
>{#if form?.name}{form?.name}{/if}</span
>
<button type="submit">Add</button>
</form>

<div id="result">
{form?.addUser?.name || 'No user added'}
</div>
36 changes: 36 additions & 0 deletions e2e/sveltekit/src/routes/stores/action-mutation/spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { sleep } from '@kitql/helper';
import { test } from '@playwright/test';
import { routes } from '../../../lib/utils/routes.js';
import { expectToBe, goto } from '../../../lib/utils/testsHelper.js';

test.describe('action-mutation', () => {
test('happy path action-mutation ', async ({ page }) => {
await goto(page, routes.Stores_action_mutation);

await expectToBe(page, 'No user added');

// click the button
await Promise.all([
page.waitForResponse((res) => res.url().endsWith('action-mutation?/add'), { timeout: 1000 }),
page.getByRole('button', { name: 'Add' }).click()
]);

// a start should be displayed
await expectToBe(page, '*', 'span[id=name-error]');

// fill the input
await page.getByLabel('Name').fill('My New Name');

// add
await Promise.all([
page.waitForResponse((res) => res.url().endsWith('action-mutation?/add'), { timeout: 1000 }),
page.getByRole('button', { name: 'Add' }).click()
]);

// wait for the message to appear
await sleep(500);

// check that we have the right data
await expectToBe(page, 'My New Name');
});
});
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { GQL_Hello } from '$houdini';
import type { RequestEvent } from '@sveltejs/kit';

export async function load(event: RequestEvent) {
/** @type {import('./$types').PageServerLoad} */
export const load = async (event) => {
const { data } = await GQL_Hello.fetch({ event });

return { hello: data?.hello };
}
};
2 changes: 2 additions & 0 deletions packages/houdini-plugin-svelte-global-stores/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# houdini-plugin-svelte-global-stores

## 0.19.2

## 0.19.1

## 0.19.0
4 changes: 2 additions & 2 deletions packages/houdini-plugin-svelte-global-stores/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ query MyAwesomeQuery {
}
```

```javascript
```typescript
// src/routes/myRoute/+page.js
import { GQL_MyAwesomeQuery } from '$houdini'
```
Expand Down Expand Up @@ -117,7 +117,7 @@ Fragments stores can be created from your external documents by using the `.get`
Using a query store inside of an endpoint looks very similar to the `load` function: just pass the event you
are handed in your route function:

```javascript
```typescript
import { GQL_MyQuery } from '$houdini'

export async function get(event) {
Expand Down
2 changes: 1 addition & 1 deletion packages/houdini-plugin-svelte-global-stores/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "houdini-plugin-svelte-global-stores",
"version": "0.19.1",
"version": "0.19.2",
"description": "The svelte global store plugin for houdini",
"keywords": [
"typescript",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ test('global fragment type', async function () {
)

expect(contents).toMatchInlineSnapshot(
'"import { TestFragment1Store } from \'../../houdini-svelte/stores\'\\n\\nexport const GQL_TestFragment1: TestFragment1Store"'
`
"import { TestFragment1Store } from '../../houdini-svelte/stores'
export const GQL_TestFragment1: TestFragment1Store"
`
)
})
2 changes: 2 additions & 0 deletions packages/houdini-react/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# houdini-react

## 0.19.2

## 0.19.1

## 0.19.0
Expand Down
2 changes: 1 addition & 1 deletion packages/houdini-react/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "houdini-react",
"version": "0.19.1",
"version": "0.19.2",
"private": true,
"description": "The React plugin for houdini",
"keywords": [
Expand Down
6 changes: 6 additions & 0 deletions packages/houdini-svelte/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# houdini-svelte

## 0.19.2

### ✨ Features

- [#786](https://github.com/HoudiniGraphql/houdini/pull/786) [`0437769`](https://github.com/HoudiniGraphql/houdini/commit/043776906a1d7ec19e2e451ed4988614b14678e9) Thanks [@AlecAivazis](https://github.com/AlecAivazis)! - Static plugin config value can now be used to remove session infrastructure from application

## 0.19.1

## 0.19.0
Expand Down
2 changes: 1 addition & 1 deletion packages/houdini-svelte/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "houdini-svelte",
"version": "0.19.1",
"version": "0.19.2",
"description": "The svelte plugin for houdini",
"keywords": [
"typescript",
Expand Down
8 changes: 7 additions & 1 deletion packages/houdini-svelte/src/plugin/fsPatch.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import filesystem, { Dirent, PathLike } from 'fs'
import { fs, Plugin, path } from 'houdini'

import { _config } from '.'
import {
Framework,
is_root_layout,
is_root_layout_server,
is_route_script,
plugin_config,
resolve_relative,
} from './kit'

Expand Down Expand Up @@ -193,7 +195,11 @@ filesystem.readdirSync = function (
}
// 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_route(posix_filepath) && !contains('+layout.server.js', '+layout.server.ts')) {
if (
is_root_route(posix_filepath) &&
!contains('+layout.server.js', '+layout.server.ts') &&
!plugin_config(_config).static
) {
result.push(virtual_file('+layout.server.js', options))
}

Expand Down
5 changes: 4 additions & 1 deletion packages/houdini-svelte/src/plugin/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { HoudiniError, PluginFactory, path, fs } from 'houdini'
import { HoudiniError, PluginFactory, path, fs, type Config } from 'houdini'
import * as url from 'url'
import { loadEnv } from 'vite'

Expand All @@ -18,6 +18,8 @@ import validate from './validate'

let framework: Framework = 'svelte'

export let _config: Config

const HoudiniSveltePlugin: PluginFactory = async () => ({
order: 'core',

Expand Down Expand Up @@ -131,6 +133,7 @@ export const error = svelteKitError
*/

async after_load(cfg) {
_config = cfg
const cfgPlugin = plugin_config(cfg)

let client_file_exists = false
Expand Down
2 changes: 2 additions & 0 deletions packages/houdini/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# houdini

## 0.19.2

## 0.19.1

### 🐛 Fixes
Expand Down
2 changes: 1 addition & 1 deletion packages/houdini/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "houdini",
"version": "0.19.1",
"version": "0.19.2",
"description": "The disappearing GraphQL clients",
"keywords": [
"typescript",
Expand Down
2 changes: 1 addition & 1 deletion packages/houdini/src/codegen/transforms/lists.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ test('cannot use list directive if id is not a valid field', async function () {
nbError++
// @ts-ignore
expect(error[0].description).toMatchInlineSnapshot(
'"@list on \\u001b[32mLegend\\u001b[37m\\u001b[0m as a configuration issue. Object identification missing: \\"\\u001b[33mid\\u001b[37m\\u001b[0m\\". Check \'Custom IDs\' if needed."'
'"@list on [32mLegend[37m[0m as a configuration issue. Object identification missing: \\"[33mid[37m[0m\\". Check \'Custom IDs\' if needed."'
)
}
expect(nbError).toBe(1)
Expand Down
Loading

0 comments on commit bf3e525

Please sign in to comment.