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

Trouble passing variables to query #106

Open
Banjerr opened this issue May 20, 2018 · 0 comments
Open

Trouble passing variables to query #106

Banjerr opened this issue May 20, 2018 · 0 comments

Comments

@Banjerr
Copy link

Banjerr commented May 20, 2018

Howdy everyone.

I'm attempting to pass a variable into a query, but keep running into issues and I'm not sure exactly why.

My query looks like this...

let queryVar = client.variable('currentTags', 'String!', currentTags); // currentTags = 'camping OR green'
    console.log(queryVar); // echoes out the VariableDefinition, which looks correct
    client.send(gql(client)
      `query ($currentTags: String!) {
         shop {
           products(first: 5, query: $currentTags) {
             pageInfo {
               hasNextPage
               hasPreviousPage
             }
             edges {
               node {
                 id
                 title
                 options {
                   name
                   values
                 }
                 variants(first: 25) {
                   pageInfo {
                     hasNextPage
                     hasPreviousPage
                   }
                   edges {
                     node {
                       title
                       selectedOptions {
                         name
                         value
                       }
                       image {
                         src
                       }
                       price
                     }
                   }
                 }
                 images(first: 5) {
                   pageInfo {
                     hasNextPage
                     hasPreviousPage
                   }
                   edges {
                     node {
                       src
                     }
                   }
                 }
               }
             }
           }
         }
       }
     `, [queryVar]).then((res) => {
       console.log('res is ', res);
    });

But I keep getting issues like expected Hash to be a Array if I pass the variable like [{currentTags: currentTags}] and an error like Variable currentTags of type String! was provided invalid value if I pass the variable like above.

Any suggestions?

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

1 participant