-1

I am using Keystone 6, which ships with the latest version of Apollo. Normally, with GraphQL, we could insert a simple where clause with the following statement:

query {
  posts ( where: { title: "test" } ) {
    title
  }
}

However, upon trying this with Apollo Studio, I get the following error:

Expected value of type "StringFilter", found "test".

I have tried various ways to fix this but nothing seems to work. Can any of you help out?

Thank you.

Molomby
  • 5,859
  • 2
  • 34
  • 27
user36191
  • 13
  • 1
  • 2

1 Answers1

3

Ah, I know that error. Keystone 6 is in a pre-release period and there are still occasional breaking changes to the API. Recently some changes to the structure of the GraphQL schema were released. Running the older style of queries on the new GraphQL schema will produce the error you're seeing.

In this case, the query can be rewritten as:

query {
  posts ( where: { title: { equals: "test" } } ) {
    title
  }
}

The GraphQL Queries docs have more usage instructions and examples. There's also an upgrade guide that specifically covers all the changes you'll need to make to your queries from before this upgrade.

Molomby
  • 5,859
  • 2
  • 34
  • 27
  • Thank you. It is unfortunate how long it took me to find out. Somehow I did not stumble upon those keystone documents, thank you for bringing them to my attention. – user36191 Oct 18 '21 at 22:58
  • Is there a reason why the filtering patterns described in GraphQL docs do not work in Keystone? I mean, some rationale, explanation... This kinda makes trivial queries more complicated. – Jindrich Vavruska Mar 28 '23 at 20:26
  • Not sure what you mean @JindrichVavruska? The filtering patterns described in the Keystone docs work fine, the problem above is due to breaking changes early in KS6's development. If you're asking about the need to have `title: { equals: "test" }` rather than just `title: "test"`, this pattern lets Keystone support other comparison operators more cleanly (eg. `title: { gt: "test" }`. The alternative – having permutations for each field, eg. `title_gt`, `title_gte`, `title_contains`, etc. – significantly bloats the GraphQL schema. With the current pattern, the filter input type can be reused. – Molomby Mar 29 '23 at 22:58
  • 1
    Hi, @Molomby, you are right. I was using Keystine API browser to play with some queries following GraphQL docs and not reading the Keystone docs. When I do it according to Keystone docs, everything works fine :) – Jindrich Vavruska Mar 30 '23 at 14:28