Skip to content

Commit

Permalink
🚧 UPDATE: demo 2
Browse files Browse the repository at this point in the history
* 🚸 UPDATE: dep

* 🚧 UPDATE: demo 2

* 👌 FIX: lint
  • Loading branch information
jycouet committed Oct 10, 2022
1 parent d8931a7 commit 470d87b
Show file tree
Hide file tree
Showing 20 changed files with 1,413 additions and 811 deletions.
5 changes: 5 additions & 0 deletions .changeset/cyan-taxis-marry.md
@@ -0,0 +1,5 @@
---
'@kitql/all-in': patch
---

update the way @kitql/helper is used in all-in
4 changes: 1 addition & 3 deletions examples/demo2/houdini.config.js
@@ -1,9 +1,7 @@
/** @type {import('houdini').ConfigFile} */
const config = {
client: 'src/lib/graphql/client.ts',
schemaPath: 'src/**/*.graphql',
sourceGlob: 'src/**/*.{svelte,gql}',
framework: 'kit',
module: 'esm',
scalars: {
DateTime: {
type: 'Date',
Expand Down
17 changes: 11 additions & 6 deletions examples/demo2/package.json
Expand Up @@ -3,15 +3,16 @@
"version": "0.0.1",
"license": "MIT",
"description": "kitql demo 2",
"private": true,
"repository": {
"url": "https://github.com/jycouet/kitql",
"directory": "examples/demo2"
},
"scripts": {
"prepare": "svelte-kit sync && npm run gen",
"sync": "svelte-kit sync && npm run gen",
"dev": "vite dev --port 3778",
"gen": "npm run gen:modules && yarn gen:houdini && yarn gen:types",
"gen:modules": "node ./node_modules/@kitql/module-codegen/index.js",
"gen:modules": "node ./node_modules/@kitql/module-codegen/cjs/index.js",
"gen:houdini": "houdini generate",
"gen:types": "graphql-codegen --config ./.graphqlrc.yaml",
"build": "yarn build:date && vite build",
Expand All @@ -25,8 +26,8 @@
"update": "npm exec -- npx npm-check-updates -u -p yarn"
},
"devDependencies": {
"@sveltejs/adapter-auto": "next",
"@sveltejs/kit": "1.0.0-next.384",
"@sveltejs/adapter-auto": "1.0.0-next.80",
"@sveltejs/kit": "1.0.0-next.511",
"@typescript-eslint/eslint-plugin": "5.30.7",
"@typescript-eslint/parser": "5.30.7",
"eslint": "8.20.0",
Expand All @@ -42,8 +43,12 @@
"vite": "3.0.2"
},
"dependencies": {
"@kitql/all-in": "0.7.7",
"graphql": "16.5.0"
"@kitql/all-in": "0.8.0-next.2",
"houdini": "0.16.8",
"graphql": "15.5.3"
},
"resolutions": {
"graphql": "15.5.3"
},
"type": "module",
"engines": {
Expand Down
40 changes: 40 additions & 0 deletions examples/demo2/src/hooks.server.ts
@@ -0,0 +1,40 @@
import { dev } from '$app/environment';
import { kitqlServer, type IKitQLContext } from '$lib/graphql/kitQLServer';
import { handleGraphiql } from '@kitql/all-in';
import { handleGraphql } from '@kitql/all-in';
import { sequence } from '@sveltejs/kit/hooks';

/**
* 1/ With all default options
*/
export const handle = sequence(
// create the graphql endpoint
handleGraphql<IKitQLContext>(kitqlServer),

// enable graphiql in dev mode
handleGraphiql({
enabled: dev
})
);

/**
* 2/ With custom options
*/
// const endpoint = '/graphql'
// const graphiQLPath = '/graphiql'

// export const handle = sequence(
// // create the graphql endpoint
// handleGraphql<IKitQLContext>({
// endpoint,
// graphiQLPath,
// ...kitqlServer,
// }),

// // enable graphiql in dev mode
// handleGraphiql({
// enabled: dev,
// endpoint,
// graphiQLPath,
// })
// )
4 changes: 2 additions & 2 deletions examples/demo2/src/lib/graphql/client.ts
Expand Up @@ -8,7 +8,7 @@ async function fetchQuery({
session,
metadata
}: RequestHandlerArgs) {
const url = import.meta.env.VITE_GRAPHQL_ENDPOINT || '/api/graphql';
const url = '/api/graphql';

const result = await fetch(url, {
method: 'POST',
Expand All @@ -24,4 +24,4 @@ async function fetchQuery({
return await result.json();
}

export const houdiniClient = new HoudiniClient(fetchQuery);
export default new HoudiniClient(fetchQuery);
39 changes: 39 additions & 0 deletions examples/demo2/src/lib/graphql/kitQLServer.ts
@@ -0,0 +1,39 @@
import type { RequestEvent } from '@sveltejs/kit';
import { kitQLModules } from '@kitql/all-in';
import { modules } from './_kitql/_appModules';

const plugins = [];
plugins.push(kitQLModules(modules));

function getContext({ request }: RequestEvent) {
// get the cookie or the token...
const coolInfo = request.headers.get('Authorization');

// get the user from the coolInfo (redis or db)
const user = { id: 1, name: 'John' };

return {
request,
user
};
}

// Option 1 => explicitly set the context type
// export type IKitQLContext = {
// request: Request
// user?: {
// id: number
// name: string
// }
// }
// Option 2 => build IKitQLContext from getContext return
export type IKitQLContext = ReturnType<typeof getContext>;

// then, make use of "IKitQLContext" in code gen, generate resolvers fully typed!
// config:
// contextType: $graphql/kitQLServer#IKitQLContext

export const kitqlServer = {
plugins,
getContext
};
44 changes: 0 additions & 44 deletions examples/demo2/src/lib/graphql/server.ts

This file was deleted.

@@ -1,4 +1,4 @@
query Version {
query ExampleQueryVersion {
version {
releaseCreatedAtUtc
}
Expand Down
@@ -1,9 +1,3 @@
<script context="module" lang="ts">
import { houdiniClient } from '$graphql/client';
houdiniClient.init();
</script>

<svelte:head>
<title>KitQL</title>
</svelte:head>
Expand Down
5 changes: 5 additions & 0 deletions examples/demo2/src/routes/+page.gql
@@ -0,0 +1,5 @@
query Version {
version {
releaseCreatedAtUtc
}
}
File renamed without changes.
10 changes: 4 additions & 6 deletions examples/demo2/svelte.config.js
@@ -1,20 +1,18 @@
import adapter from '@sveltejs/adapter-auto';
import houdini from 'houdini/preprocess';
import path from 'path';
import preprocess from 'svelte-preprocess';

/** @type {import('@sveltejs/kit').Config} */
const config = {
// Consult https://github.com/sveltejs/svelte-preprocess
// for more information about preprocessors
preprocess: [preprocess(), houdini()],
preprocess: preprocess(),

kit: {
adapter: adapter(),
alias: {
$houdini: path.resolve('.', '$houdini'),
$graphql: path.resolve('./src/lib/graphql'),
$modules: path.resolve('./src/lib/modules')
$houdini: './$houdini',
$graphql: './src/lib/graphql',
$modules: './src/lib/modules'
}
}
};
Expand Down
3 changes: 2 additions & 1 deletion examples/demo2/tsconfig.json
Expand Up @@ -9,6 +9,7 @@
"$graphql/*": ["src/lib/graphql/*"],
"$modules": ["src/lib/modules"],
"$modules/*": ["src/lib/modules/*"]
}
},
"rootDirs": [".", "./.svelte-kit/types", "./.$houdini/types"]
}
}
22 changes: 0 additions & 22 deletions examples/demo2/vite.config.js

This file was deleted.

20 changes: 20 additions & 0 deletions examples/demo2/vite.config.ts
@@ -0,0 +1,20 @@
import { sveltekit } from '@sveltejs/kit/vite';
import houdini from 'houdini/vite';
// import watchAndRun from '@kitql/vite-plugin-watch-and-run';

import type { UserConfig } from 'vite';

const config: UserConfig = {
plugins: [
houdini(),
sveltekit()
// watchAndRun([
// {
// watch: '**/*.(gql|graphql)',
// run: 'npm run gen'
// }
// ])
]
};

export default config;

1 comment on commit 470d87b

@vercel
Copy link

@vercel vercel bot commented on 470d87b Oct 10, 2022

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:

kitql – ./

kitql-git-main-jycouet.vercel.app
kitql-jycouet.vercel.app
kitql.vercel.app
www.kitql.dev
kitql.dev

Please sign in to comment.