Squidex Request failed

Hello,

Getting this error using GraphQlAsync(query);
Squidex Request failed: {“errors”:[{“message”:“Body text could not be parsed. Body text should start with ‘{’ for normal graphql query or with ‘[’ for batched query.”}]}

Here is my query

{
  findPagesContent(id: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx") {
    id
    version
    data{
      title{
        iv
      }
      slug {
        iv
      }
      hero{
        iv{
          data{
            h2{
              iv
            }
            h2Span{
              iv
            }
            heroImage{
              iv{
                url
              }
            }
          }
        }
      }
      communitymodule{
        iv{
          data{
            communityCards{
              iv{
                data{
                  title{
                    iv
                  }
                  genreTag{
                    iv
                  }
                  communityDescription{
                    iv
                  }
                  communityImage{
                    iv{
                      url
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

This is the response I get back from the graphQL API on the cloud version

{
  "data": {
    "findPagesContent": {
      "id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
      "version": 6,
      "data": {
        "title": {
          "iv": "Community"
        },
        "slug": {
          "iv": "community"
        },
        "hero": {
          "iv": [
            {
              "data": {
                "h2": {
                  "iv": "Gaming"
                },
                "h2Span": {
                  "iv": "Communities"
                },
                "heroImage": {
                  "iv": [
                    {
                      "url": "https://cloud.squidex.io/api/assets/xxxxxxx/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/"
                    }
                  ]
                }
              }
            }
          ]
        },
        "communitymodule": {
          "iv": [
            {
              "data": {
                "communityCards": {
                  "iv": [
                    {
                      "data": {
                        "title": {
                          "iv": "Final Fantasy XIV"
                        },
                        "genreTag": {
                          "iv": "MMO"
                        },
                        "communityDescription": {
                          "iv": "We do stuff all fantasy like! And that's final!"
                        },
                        "communityImage": {
                          "iv": [
                            {
                              "url": "https://cloud.squidex.io/api/assets/xxxxxxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
                            }
                          ]
                        }
                      }
                    },
                    {
                      "data": {
                        "title": {
                          "iv": "Destiny 2"
                        },
                        "genreTag": {
                          "iv": "CO-OP"
                        },
                        "communityDescription": {
                          "iv": "We are destined to shoot things. PEW PEW PEW!"
                        },
                        "communityImage": {
                          "iv": [
                            {
                              "url": "https://cloud.squidex.io/api/assets/xxxxxxx/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/"
                            }
                          ]
                        }
                      }
                    },
                    {
                      "data": {
                        "title": {
                          "iv": "C.O.D."
                        },
                        "genreTag": {
                          "iv": "FPS"
                        },
                        "communityDescription": {
                          "iv": "When duty calls, go to the bathroom"
                        },
                        "communityImage": {
                          "iv": [
                            {
                              "url": "https://cloud.squidex.io/api/assets/xxxxx/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/"
                            }
                          ]
                        }
                      }
                    },
                    {
                      "data": {
                        "title": {
                          "iv": "New World"
                        },
                        "genreTag": {
                          "iv": "MMO"
                        },
                        "communityDescription": {
                          "iv": "It's new so we don't know yet."
                        },
                        "communityImage": {
                          "iv": [
                            {
                              "url": "https://cloud.squidex.io/api/assets/xxxxxxx/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/"
                            }
                          ]
                        }
                      }
                    },
                    {
                      "data": {
                        "title": {
                          "iv": "Swords of Legends Online"
                        },
                        "genreTag": {
                          "iv": "MMO"
                        },
                        "communityDescription": {
                          "iv": "This sword is legend... wait for it! dairy!"
                        },
                        "communityImage": {
                          "iv": [
                            {
                              "url": "https://cloud.squidex.io/api/assets/xxxxxxxx/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/"
                            }
                          ]
                        }
                      }
                    }
                  ]
                }
              }
            }
          ]
        }
      }
    }
  }
}

Everything is all good until I run it in code

var page = await pageClient.GraphQlAsync<JToken>(query);

Let me know if you need to see the schema.

Thanks

How have you defined your query?

I have a few graphql tests that run with every commit: https://github.com/Squidex/squidex/blob/master/backend/tools/TestSuite/TestSuite.ApiTests/GraphQLTests.cs

And here are a few more:

Here is the code sample

public async Task<Models.Pages.Root> GetPage(string slug)
        {
            switch (slug)
            {
                case "community":
                    var query = new
                    {
                        query = @"
                            {
                              findPagesContent(id: ""xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx"") {
                                id
                                version
                                data{
                                  title{
                                    iv
                                  }
                                  slug {
                                    iv
                                  }
                                  hero{
                                    iv{
                                      data{
                                        h2{
                                          iv
                                        }
                                        h2Span{
                                          iv
                                        }
                                        heroImage{
                                          iv{
                                            url
                                          }
                                        }
                                      }
                                    }
                                  }
                                  communitymodule{
                                    iv{
                                      data{
                                        communityCards{
                                          iv{
                                            data{
                                              title{
                                                iv
                                              }
                                              genreTag{
                                                iv
                                              }
                                              communityDescription{
                                                iv
                                              }
                                              communityImage{
                                                iv{
                                                  url
                                                }
                                              }
                                            }
                                          }
                                        }
                                      }
                                    }
                                  }
                                }
                              }
                            }"
                    };
                    var page = await pageClient.GraphQlAsync<JToken>(query);
                    var pageString = page.First.Last.ToString();
                    Models.Pages.Root returnPage = JsonConvert.DeserializeObject<Models.Pages.Root>(pageString);

                    return returnPage;
                default:
                    Models.Pages.Root root = JsonConvert.DeserializeObject<Models.Pages.Root>("error");

                    return root;
            }
        }

I tried the following code and it works for me…

using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Squidex.ClientLibrary;
using System;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp7
{
    class Program
    {
        static async Task Main(string[] args)
        {
            var clientManager = new SquidexClientManager(new SquidexOptions
            {
                AppName = "",
                ClientId = "",
                ClientSecret = ""
            });

            var pageClient = clientManager.CreateContentsClient<DynamicContent, DynamicData>("dynamic");

            var query = new
            {
                query = @"
                {
                    findPagesContent(id: ""xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx"") {
                        id
                        version
                        data {
                            title {
                                iv
                            }
                            slug {
                                iv
                            }
                            hero {
                                iv {
                                    data {
                                        h2 {
                                            iv
                                        }
                                        h2Span{
                                            iv
                                        }
                                        heroImage{
                                            iv {
                                                url
                                            }
                                        }
                                    }
                                }
                            }
                            communitymodule {
                                iv {
                                    data {
                                        communityCards {
                                            iv {
                                                data {
                                                    title {
                                                        iv
                                                    }
                                                    genreTag {
                                                        iv
                                                    }
                                                    communityDescription{
                                                        iv
                                                    }
                                                    communityImage {
                                                        iv {
                                                            url
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }"
            };

            try
            { 
                var page = await pageClient.GraphQlAsync<JToken>(query);

                Console.WriteLine(page.ToString(Formatting.Indented));
            }
            catch (SquidexGraphQlException ex)
            {
                Console.WriteLine(JsonConvert.SerializeObject(ex.Errors, Formatting.Indented));
            }
        }
    }
}

Of course it throws an exception because I do not have the schemas, but the error you get is from the beginning of the request. Have you updated the client library?

Updating the client library fixed it. You sir are a saint!

1 Like