graphicbeacon / recipe_management_app

A recipe management app built with Hasura GraphQL Backend and Flutter
31 stars 11 forks source link

HTTP Request to Hasura seems to be not working with current header #2

Open huskyjp opened 3 years ago

huskyjp commented 3 years ago

I am not able to send a POST request to Hasura both on simply from docker-compose setup and Heroku as instructed in the tutorial. Whenever I send a request, it returns error like below even from a Postman.

{"errors":[{"extensions":{"path":"$","code":"invalid-json"},"message":"Error in $: not enough input"}]}

I currently have same logic Client on Flutter using ferry like this - any idea why Hasura denies access? ( I guess I need to add some additional header?)

Client initClient(String url, String secret) {
  final link = HttpLink(
    url,
    defaultHeaders: {
      'x-hasura-admin-secret': secret,
    },
  );
  final cache = Cache();

  final client = Client(
    link: link,
    cache: cache,
  );
  return client;
}

P.S. Thanks for the nice tutorial on Youtube!

huskyjp commented 3 years ago

Widget error is like this - looks like response.data is null

The following _CastError was thrown building StreamBuilder<OperationResponse<GFetchRecipeListData,
GFetchRecipeListVars>>(dirty, state: _StreamBuilderBaseState<OperationResponse<GFetchRecipeListData,
GFetchRecipeListVars>, AsyncSnapshot<OperationResponse<GFetchRecipeListData,
GFetchRecipeListVars>>>#55ca8):
Null check operator used on a null value

The relevant error-causing widget was:
  StreamBuilder<OperationResponse<GFetchRecipeListData, GFetchRecipeListVars>>
  file:///C:/src/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/ferry_flutter-0.5.4/lib/src/operation.dart:47:12

Since I am using Dart2.0 and with null-safety, it always crashes at recipes!isEmpty.

final recipes = response.data?.recipes;
if (recipes!.isEmpty) {
                      return _buildNoRecipes(context);
                    }