ticruz38/graphql-codegen-svelte-apollo

Converted query with sort take HTTP error 400 Bad requesr

yoleoagain opened this issue ยท 8 comments

Correct me if I'm wrong. Here is the code with query sorted by date. He is work in graphql playground but genereated query take 400HTTP error.
query GetItems { items(sort: "created_at:DESC") { id name description created_at } }
image

I don't think 400 HTTP errors can be related to this library. Are you sure that the query is correct? Your parameters looks strange to me, It is either a wrong query, or you are targeting the wrong endpoint for your graphQL client.

@ticruz38 Thx for your answer, i will be glad if you can help. How i can write a simple query sorted by date for example? This works in playground.
image

In the apollo-client you have the right uri? to the good endpoint?

In the apollo-client you have the right uri? to the good endpoint?

Yes simple GET without sort works as well.
I
image

It's a bit difficult to help you out with this small information.

You mean that this is working;

$: query = GetItems({});

And this is not working (with a 400 error code);

$: query = GetItems({ variables: {sort: "created_at:DESC"}});

Is it a correct understanding?

$: query = GetItems({});

$: query = GetItems({}); - this code in both cases but, different gql syntax. May be it was something happend with my dev server, but now its 200OK with not sorted items.

  1. Get items but not sorted
    query GetItems { items(sort: "created_at:ASC") { id name description created_at } }

  2. Get items too
    query GetItems { items{ id name description created_at } }

I think I know what's wrong, and it may be a kind of flexibility that is not allowed by this plugin, I will need to try myself.

Can you try writing your query like this?

query GetItems($sort: String) {
  items(sort: $sort) {
    id
    name
    description
    created_at
  }
}

and use it like that

$: query = GetItems({sort: "created_at:ASC"});
$: query = GetItems({sort: "created_at:ASC"});

Thank you so much, it is works perfect, and your library is awesome and its very helps me. I'm new for backend and graphql and i use strapi headless cms which generate for me graphql schema and graphql-codegen-svelte-apollo. For me right syntax of calling query is
image
PS an thx to @jycouet