This is an experimental command to run to add a GraphQL server (powered by graphql-helix
) to your SvelteKit project.
You must start with a fresh copy of the official SvelteKit template, which is currently created by running this command. You must say yes to TypeScript preprocessing.
npm init svelte@next
Once that is set up, run this command in your project directory to set up GraphQL:
npx svelte-add graphql-server
After the preset runs,
-
You can create a GraphQL schema in
src/graphql/schema.ts
using any library or technique you want. Additionally, you can set thedefaultQuery
that shows up when GraphiQL is loaded in the browser. -
You can query your API (with POST requests) at the
/graphql
endpoint. -
You can visit GraphiQL in the browser at the
/graphql
endpoint. -
You can see an example of how you may set up resolver-level authorization with the
contextFactory
line insrc/routes/graphql.ts
and theauthorization
argument insrc/graphql/schema.ts
. -
The
/
route (in yoursrc/routes/index.svelte
file) will show an example of how to use your GraphQL API inpreload
. -
You can apply another Svelte Adder to your project for more functionality.
Create an issue and I'll try to help.
Create an issue or pull request and I'll try to fix.
These are new tools, so there are likely to be problems in this project. Thank you for bringing them to my attention or fixing them for me.
MIT
Repository preview image generated with GitHub Social Preview
This README was generated with ❤️ by readme-md-generator