Hugo Leonardo
Hugo Leonardo

Reputation: 1

Issue Filtering JSONB with GraphQL - Unhandled Runtime Error GraphQLError

I am using Hasura with GraphQL in a React application, and I'm trying to filter my ClientePayload based on the "Situacao" field (which can be "Ativo" or "Inativo"). While the query works fine in the Hasura console, it does not seem to work in my application.

Im having this error:

Unhandled Runtime Error GraphQLError: Syntax Error: Expected Name, found String "Situacao".

export function ChargeStageDashboard() {
  const {
    actions: { setFilters },
    state: { filters },
  } = useDashboardStore(({ state, actions }) => ({ state, actions }));

  const { handleSubmit, control } = useForm();

  const onSubmit: SubmitHandler<any> = (formData) => {
    const filteredData = Object.entries(formData).reduce((acc, [key, value]) => {
      if (value) acc[key] = value;
      return acc;
    }, {} as Partial<any>);

    setFilters({
      charges: {
        ...filters.charges,
        where: {
          ...filters.charges.where,
          ClientePayload: { _contains: { Situacao: filteredData?.clientesFiltro?.metadata } },
        },
      },
    });
  };

  return (
    <form onSubmit={handleSubmit(onSubmit)}>
      {/* Other form fields */}
      <Controller
        control={control}
        name="clientesFiltro"
        render={({ field: { onChange, value } }) => (
          <select onChange={onChange} value={value}>
            <option value="Ativo">Ativos</option>
            <option value="Inativo">Inativos</option>
          </select>
        )}
      />
      <button type="submit">Pesquisar</button>
    </form>
  );
}

Im trying to filter actives or inactives clients in my system

Like i said, in Hasura console this works:

{ inadimplencia_Clientes(where: {ClientePayload: {_contains: {Situacao: "Inativo"}}}) { Cliente_Id ClientePayload } }

Upvotes: 0

Views: 19

Answers (0)

Related Questions