jycouet / kitql

A set of standalone tools to SpeedRun WebApps!
https://kitql.dev
MIT License
407 stars 37 forks source link

Unable to use without first writing a query somewhere #332

Closed jamesbirtles closed 1 year ago

jamesbirtles commented 1 year ago

Describe the bug

Trying to get started with KitQL, I find myself wanting to focus on the types and resolvers on the server before adding any queries to the client. I define a typedef in typedefs/user.graphql, and then start to add a resolver, resolvers/user.ts. Now I need the types generated so that ../$kitql/moduleTypes resolves to something and I can benefit from the types whilst writing my resolver. So, I run the dev server, pnpm run dev to generate my types as I am using the vite plugin. Unfortunately, this errors with:

ENOENT: no such file or directory, open 'src/lib/modules/user/$kitql/moduleTypes.ts'

It seems that this file will only get generated when I have added a query to my client. It's not the end of the world, I can just add a dummy .gql file with a dummy query until I am ready to actually start writing the queries on the client, but this is an annoying and weird requirement. I would think it would be quite common to want to get started by focusing on what things look like on the resolver/typedefs side before actually trying to make a query from the app. I would want to be able to see the graphiql environment before starting to write a query personally.

In the process of figuring this out, I ran the graphql codegen manually which gives me this output:

⚠ Generate outputs
  ❯ Generate to ./src/lib/modules/
    ✔ Load GraphQL schemas
    ✖
      Unable to find any GraphQL type definitions for the following pointers:
      - ./src/**/*.gql
      ,
      - ./src/**/*.svelte
      ,
      - ./$houdini/graphql/documents.gql
    ◼ Generate

I would guess KitQL probably shouldn't continue on if the main codegen step errored, which would prevent the opaque no such file or directory error I was getting, though the underlying problem of not being able to use the generated moduleTypes until I write a client query would still be present.

It doesn't seem like codegen actually needs to find documents in order to generate the moduleTypes.ts file, as if no documents are specified in the config (if i comment out what kitql is giving it), then it generates just fine. I don't know if theres a way to tell the codegen that it doesn't matter if the documents config is specified but it doesn't find any matching files?

Your Example Website or App

https://stackblitz.com/edit/sveltejs-kit-template-default-wrxwyh

Steps to Reproduce the Bug or Issue

Go to the stackblitz and run the dev server pnpm run dev, see error.

Expected behavior

The dev server should start up, and the types should be generated without care for there being no documents/queries

Screenshots or Videos

No response

Platform

Additional context

No response

stackblitz[bot] commented 1 year ago

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

jycouet commented 1 year ago

Hi, Thx for reaching out. Yes, you are right you must have at least one query today (and that's not ideal). That's why I left in src/lib/modules/__init/graphql/QUERY.Greetings.gql with:

query Greetings {
  _greetings
}

I'll look at how to remove this requirement in graphql-modules. 👍

jycouet commented 1 year ago

I close the issue as it's a graphql-modules topic and I'm not planning to upgrade @kitql/all-in. If you feel that it's wrong, please re open and we can speak here and/or on discord.

Happy coding