Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

graphql where clause Angular Apollo Client

Using angular apollo client.

I'm trying to use the where clause

getPage(slug: string) {
    return this.apollo
      .query({
        variables: {
          slug: slug
        },
        query: gql`
          query pages(where: { $slug: slug }) {
            pages (slug: $slug) {
              slug,
              title,
              content,
              cover {
                name,
                url,
              },
              createdAt,
              updatedAt
            }
          }
        `
      });
  }

I get this error in browser console:

message: "Syntax Error: Expected $, found Name "where""

like image 333
KhoPhi Avatar asked Sep 14 '25 10:09

KhoPhi


1 Answers

Okay, I figured it out.

getPage(slug: string) {
    return this.apollo
      .query({
        variables: {
          slug: slug
        },
        query: gql`
          query pages ($slug: String) {
            pages (where: { slug: $slug }) {
              slug,
              title,
              content,
              cover {
                name,
                url,
              },
              createdAt,
              updatedAt
            }
          }
        `
      });
  }
like image 90
KhoPhi Avatar answered Sep 17 '25 18:09

KhoPhi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!