Apollo Client gql lte, gte null values Issue

Apollo Client gql lte, gte null values Issue


0

I have this query using to query from a graphql subgraph. I use apollo client in my Next.js front-end to query data.

This is my query:

const DOMAIN_FIELDS = gql`
  fragment DomainFields on Domain {
    expires
    id
    isListed
    name
    listingPrice
    listingExpiresAt
    lastSalePrice
    owner
    tokenId
    seller
  }
`;

export const GET_DOMAINS = gql`
  ${DOMAIN_FIELDS}
  query GetDomains(
    $min_date: BigInt
    $max_date: BigInt
  ) {
    domains(
      where: {
        expires_gte: $min_date
        expires_lte: $max_date
      }
    ) {
      ...DomainFields
    }
  }
`;

I use this query GET_DOMAINS inside a component. The initial values of minExpirationDate and maxExpirationDate variables are null. Those values will be populated when user input some date values. Otherwise they will be null.

When I try to use the above query to get data:

import React, { useEffect } from 'react';
import { useApolloClient } from '@apollo/client';
import { GET_DOMAINS } from '@/queries/queries';
import { useSelector } from 'react-redux';
....

const DomainsTable = () => {
   const client = useApolloClient();
   const { minExpirationDate, maxExpirationDate } = useSelector(
    (state) => state.domainExploreState
   );
   ....


  // Fetch data
  useEffect(() => {
    fetchDataFromGQL();
  }, [
    minExpirationDate,
    maxExpirationDate
  ]);

  const fetchDataFromGQL = async () => {
     try {
         const baseQuery = {
            query: GET_DOMAINS,
            variables: {
              min_date: minExpirationDate,
              max_date: maxExpirationDate
            },
         };

         const { data } = await client.query(baseQuery);
       
     } catch {
       ....
     }
     .....
  }

 .....

}

I am getting this error:

ApolloError: Failed to get entities from store: unsupported filter ` >= ` for value `null`, query = from "sgd4"."domain"[*]{expires >= null and expires <= null and name != null and name ~ ^*} order block_timestamp desc, id desc first 50 at 1702759 query_id 83555570bdb2da2d-6dc8c4ef99f8cc6a

Is there a way to write the GET_DOMAINS query to handle this? When the passing variable values are null, to ignore them? In this scenario, min_date & max_date both can be null at the same time, or one can be null while the other is not.

Thank You!


Load 5 more related questions


Show fewer related questions

0



Leave a Reply

Your email address will not be published. Required fields are marked *