KitQL - all-in
KitQL, A set of tools, helping you building efficient apps in a fast way.
⚡How to - all-in
1️⃣ In a SvelteKit project, install everything in one cmd!
(step 0, if it's not done, create a sveltekit project with everything true
🙃)
yarn add @kitql/all-in graphql
2️⃣ Create a .graphqlrc.yaml
at the root of your project
Like in the Demo 1
3️⃣ update your package.json
- Update your
dev port
to 3777
to fit the previous config file - Add a
gen
script to launch the codegen
"scripts": {
"prepare": "yarn gen",
"dev": "svelte-kit dev --port 3777",
"gen": "graphql-codegen --config ./.graphqlrc.yaml",
}
4️⃣ Install the plugin Watch & Run
In your svelte.config.js
add a watchAndRun with the following configuration:
import watchAndRun from './vite-plugin-watch-and-run.js';
const config = {
kit: {
vite: {
plugins: [
watchAndRun([
{
watch: '**/*.(gql|graphql)',
run: 'yarn gen'
}
])
]
}
}
};
export default config;
5️⃣ Add some operations & mutations
Like this file for example: demo1/src/lib/graphql/GetAllContinents.gql
If you were not running your app, run yarn gen
manually
6️⃣ Use your operations & mutations
<script context="module" lang="ts">
export async function load({ fetch }) {
await KQL_AllContinents.query({ fetch });
return {};
}
</script>
<script lang="ts">
await KQL_AllContinents.query();
</script>
<ul>
{#each $KQL_AllContinents.data?.continents as continent}
<li>
<p>{continent?.name}</p>
</li>
{/each}
</ul>
7️⃣8️⃣9️⃣
5️⃣ Run
yarn dev
🥳🥳🥳🥳🥳 (ok not yet, you need a bit more steps to create your server, client, etc, I will add it later to the README, even steps orders will change!).