BlowFish
BlowFish

Reputation: 354

How to pass variables in Graphql Apollo Query

I have the following query and i would like it to return the items with a specific parent name

query categorias ($name: String) {
  categories(level: 1, first: 13 ) {
    edges {
      node {
        id
        name
        level
        parent {
          name: $name
        }
        }
      }
    }
  }

Can't quite understand how to make this work. I've tried the following as well but "it's not a valid argument"

    query categorias ($name: String) {
      categories(level: 1, first: 13 ) {
        edges {
          node {
            id
            name
            level
            parent (name:$name{
              name
            }
            }
          }
        }
      

}

Upvotes: 0

Views: 436

Answers (1)

Hemant Parashar
Hemant Parashar

Reputation: 3774

You need to pass the name variable to the actual query i.e categories.Not sure what the schema is but the basic idea is below. categorias is the name given by you (so that you can use multiple queries) not the actual query. Something like this.

query categorias ($name: String) {
  categories(name: $name, level: 1, first: 13 ) {
    edges {
      node {
        id
        name
        level
        parent {
          name: $name
        }
        }
      }
    }
  }

Upvotes: 1

Related Questions