KhoPhi
KhoPhi

Reputation: 9537

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""

Upvotes: 4

Views: 2209

Answers (1)

KhoPhi
KhoPhi

Reputation: 9537

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
            }
          }
        `
      });
  }

Upvotes: 3

Related Questions