Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Astro support #242

Open
alexanderalmstrom opened this issue Feb 25, 2024 · 2 comments
Open

Astro support #242

alexanderalmstrom opened this issue Feb 25, 2024 · 2 comments

Comments

@alexanderalmstrom
Copy link

Is there a way to enable typed queries in .astro files, just like in .ts and .tsx?

I've got a page route /posts/[...slug].astro with a custom graphql client using introspection to a remote graphql endpoint but the query does not seem to be recognized like in .ts files.

---
import { graphql } from "@/graphql";
import { client } from "@/lib/client";

const { slug } = Astro.params;

const PostsQuery = graphql(`
  query PostsQuery($slug: String!) {
    PostItems(by_slugs: $slug) {
      items {
        id
        name
      }
    }
  }
`);

const { data, error } = await client.query(PostsQuery, {
  slug: "posts/" + slug,
});

if (error) {
  return Astro.redirect("/500");
}

const post = data.PostItems.items[0];

if (!post) {
  return Astro.redirect("/404");
}
---

<article>
  <h1>{post.name}</h1>
</article>

@kitten
Copy link
Member

kitten commented Feb 25, 2024

I think this basically comes down more to how the Astro language server integrates with TypeScript and/or whether they have a TS plugin that works around the different file formats.

For example, as far as I know Vue has basically implemented this, although we haven't explicitly tested against their implementation yet.

It shiuld works for Vue because of how "Volar" is implemented: https://volarjs.dev/
And the page also says that Volar is used by Astro.

So, while we haven't tested this, this isn't really something we can influence or implement. The main thing to keep in mind is whether you're using Astro's language server based on Volar afaik

@JoviDeCroock JoviDeCroock transferred this issue from 0no-co/gql.tada Feb 27, 2024
@JoviDeCroock
Copy link
Member

Related to #168

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants