question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Filter on null or "Not exists" for graphql fields

See original GitHub issue

Is your feature request related to a problem? Please describe.

I can’t filter on whether or not a field is null or “not exists”

Describe the solution you’d like

There are a couple ways of solving this, but the easiest solution I can think of is to allow this:

    const filter: ModelFooFilterInput = {
      field: { eq: null }
    };
    const results: ListFoosQuery = await this.apiService.ListStudyFoos(filter);

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
SwaySwaycommented, Oct 5, 2020

@malcomm I believe the filter you might be looking for in this scenario is if the attribute does not exist on the given record. Given this schema

type Restaurant @model {
  id: ID!
  name: String!
  description: String!
  city: String!
}

If I wanted to filter by Restaurants that did not have a description then I would filter as follows:

const service = new APIService();
const filter: ModelRestaurantFilterInput = {
    description: { attributeExists: false }
  };
const results: ListRestaurantsQuery = await service.ListRestaurants(filter);

If can also or them in the filter so it returns the field being null or the attribute not existing

const filter: ModelRestaurantFilterInput = {
    or: [
      { description: { attributeExists: false } },
      { description: { eq: null } }
    ]
  }
0reactions
github-actions[bot]commented, Nov 21, 2021

This issue has been automatically locked since there hasn’t been any recent activity after it was closed. Please open a new issue for related bugs.

Looking for a help forum? We recommend joining the Amplify Community Discord server *-help channels for those types of questions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Graphql query only not null objects - Stack Overflow
If you don't want certain data in your response, you have to filter it somewhere on the server. The only thing you have...
Read more >
Using nullability in GraphQL
A field can either be nullable or non-null, and this tells you whether or not you could receive a null value when you...
Read more >
Nulls in GraphQL: Cheatsheet - Hasura
Nulls in the query. A GraphQL query can have fields and inputs, with or without variables. Fields are always optional, whether nullable or...
Read more >
Search and Filtering - GraphQL - Dgraph
You can filter queries to find objects with a non-null value in a specified field using the has keyword. The has keyword can...
Read more >
When To Use GraphQL Non-Null Fields | by Caleb Meredith
In the GraphQL type system all types are nullable by default. This means that a type like Int can take any integer (...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found