0

Have a site that uses jquery, so trying to make calls to the graphql api using $.ajax(). It works fine for simple queries, but when trying to pass Int values for parameters, I keep hitting a variable type error: "Int cannot represent non-integer value". It appears that maybe my Int values are getting converted to strings in transit - is there a way to avoid this?

A simplified version of the query:

const BLOG_QUERY = `
query SimpleQuery($offset: Int, $limit: Int) {
  entries(section: "blog", limit: $limit, offset: $offset, orderBy: "postDate DESC") {
    id
    url
    title
  }
}
`;

The jquery ajax call:

const params = {
  query: BLOG_QUERY,
  variables: {
    offset:1,
    limit:2
  },
}

$.ajax({
  context: this,
  type : 'POST',
  url : BLOG_POST_ENDPOINT,
  headers: { 'X-Requested-With': 'XMLHttpRequest' },
  data: params,
  dataType : 'json',
  encode : true
}).done(
  ...// Do success stuff...
)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.