How to find missing data in GraphQL

How can I find null values in GraphQL?

Given example schema:

type User {
  username: String! @id
  firstName: String @search(by: [exact, term, fulltext, regexp])
}

How can I find all users that have not set a firstName?

I tried to build a filter for it like:

{
  queryUser(filter: {firstName: {eq: null}}) {
    username
    firstName
  }
}

Which while it doesn’t throw a error for invalid query syntax and breaking schema, it does not produce any results either.

The only way I can do it I can think of is to have two separate queries like:

{
  queryUser @recurse {
    username
    firstName
  }
}

Then with list of usernames as a variable do a filter with not. The problem then becomes that I cannot give an array to search in like I can if the id is a true id.

This leads to a use case for:

  • The need to filter for null
  • The need to filter for in Array with String and enum types.

Hi,

We already had plans to add such a feature soon. I’ve added it as a github issue so you can track it : Add equivalent of Dgraph's 'has' to GraphQL · Issue #5819 · dgraph-io/dgraph · GitHub

I didn’t understand your second dot point, can you elaborate on that one.

1 Like

Maybe the second thought would be a different topic, but I feel like I already made too many topics lol.

Another use case to make it simpler would be having a predicate userRole that points to an enum and I want to do a SQL like IN(...) operation. Yes I could do it long route with

...filter({userRole: {eq: SUBSCRIBER} or: {userRole: {eq: EDITOR}}}) ...

But if I had an array variable with those types in it, it would be easier to do:

...filter({userRole: {in: [SUBSCRIBER, EDITOR]}}) ...

Yeah, I see what you mean now. Yes you can do those kinds of enum queries at the moment, but that in syntax looks really nice. I guess it could be added every time that eq gets added.

That sure would be helpful amd make graphQL filters shorter for sure. Those or or and and or... can get confusing if not done right for sure.

You guys are awesome!

1 Like

Oh shucks … if you say stuff like that, you’ll definitely get your suggestions considered :grinning: