Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting null data for specific query #244

Closed
dokumanx opened this issue Aug 25, 2021 · 15 comments
Closed

Getting null data for specific query #244

dokumanx opened this issue Aug 25, 2021 · 15 comments

Comments

@dokumanx
Copy link

Hi, I am getting null response below query with ferry. I can get correct data within playground but ferry. I have tried different approaches but without an error it is hard to catch what is going on. If anyone has an idea please leave a comment.

Query

query StudentNotification($id: Id!) {
    student(studentId: $id) {
        notifications {
            id
            userId
            data
            status
            createdAt
        }
    }
}

Dart code that returns null data

Future<List<GStudentNotificationData_student_notifications>>
      getStudentNotifications({required String userId}) async {
    late final OperationResponse response;
    try {
      final studentNotificationsReq =
          GStudentNotificationReq((q) => q..vars.id.value = userId);

      response = await graphQlClient.request(studentNotificationsReq).first;
      print('THIS IS NOTIFICATION RESPONSE: $response');

      return [];
      // return response.data.student.notifications.toList()!;
    } catch (e) {
      print(response.graphqlErrors);
      throw Exception(e.toString());
    }
  }

Debug console

image

@chungonion
Copy link

I shared a similar situation, is that when the data has only 9 entries, and with the first parameter is at 10, then the entire data object is returning null.

Any idea on how to fix or is this a bug (or feature?)

@dokumanx
Copy link
Author

I shared a similar situation, is that when the data has only 9 entries, and with the first parameter is at 10, then the entire data object is returning null.

Any idea on how to fix or is this a bug (or feature?)

I don't understand your situation. Can you explain with an example? It is really weird getting null with no reason.

@chungonion
Copy link

chungonion commented Aug 26, 2021

I shared a similar situation, is that when the data has only 9 entries, and with the first parameter is at 10, then the entire data object is returning null.
Any idea on how to fix or is this a bug (or feature?)

I don't understand your situation. Can you explain with an example? It is really weird getting null with no reason.

Yes it is also quite weird to me that it returns null on a weird spot.

Assume I have a query that is going to get the comments, and the query looks like this:
query getComments($first:Int,$after:String){ comments(first: $first, after: $after) { nodes { content } pageInfo { startCursor endCursor hasPreviousPage hasNextPage } } }

if I have the first param being set as 10, and the data source (or database table) only have 9 entries, a TypedLinkException is thrown

螢幕截圖 2021-08-27 上午3 13 40

The stack trace retrieved from Android Studio is as follows
#0 BuiltJsonSerializers._deserialize (package:built_value/src/built_json_serializers.dart:178:11) #1 BuiltJsonSerializers.deserialize (package:built_value/src/built_json_serializers.dart:124:18) #2 BuiltJsonSerializers.deserializeWith (package:built_value/src/built_json_serializers.dart:42:12) #3 GgetMyclassData.fromJson (package:my_app/graphql/get_my_class.data.gql.dart:29:23) #4 GgetMyclassReq.parseData (package:my_app/graphql/get_my_class.req.gql.dart:53:27) #5 GqlTypedLink.request.<anonymous closure> (package:ferry/src/gql_typed_link.dart:29:42) #6 _HandlerEventSink.add (dart:async/stream_transformers.dart:209:17) #7 _SinkTransformerStreamSubscription._handleData (dart:async/stream_transformers.dart:111:24) #8 _rootRunUnary (dart:async/zone.dart:1362:47) #9 _CustomZone.runUnary (dart:async/zone.dart:1265:19) #10 _CustomZone.runUnaryGuarded (dart:async/zone.dart:1170:7) #11 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:341:11) #12 _DelayedData.perform (dart:async/stream_impl.dart:591:14) #13 _StreamImplEvents.handleNext (dart:async/stream_impl.dart:706:11) #14 _PendingEvents.schedule.<anonymous closure> (dart:async/stream_impl.dart:663:7) #15 _rootRun (dart:async/zone.dart:1346:47) #16 _CustomZone.run (dart:async/zone.dart:1258:19) #17 _CustomZone.runGuarded (dart:async/zone.dart:1162:7) #18 _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:1202:23) #19 _rootRun (dart:async/zone.dart:1354:13) #20 _CustomZone.run (dart:async/zone.dart:1258:19) #21 _CustomZone.runGuarded (dart:async/zone.dart:1162:7) #22 _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:1202:23) #23 _microtaskLoop (dart:async/schedule_microtask.dart:40:21) #24 _startMicrotaskLoop (dart:async/schedule_microtask.dart:49:5)

Thank you for the assistance!

@dokumanx
Copy link
Author

I shared a similar situation, is that when the data has only 9 entries, and with the first parameter is at 10, then the entire data object is returning null.

Any idea on how to fix or is this a bug (or feature?)

I don't understand your situation. Can you explain with an example? It is really weird getting null with no reason.

Yes it is also quite weird to me that it returns null on a weird spot.

Assume I have a query that is going to get the comments, and the query looks like this:

`query getComments($first:Int,$after:String){

comments(first: $first, after: $after)

{

    nodes

    {

        content

    }

    pageInfo

    {

        startCursor

        endCursor

        hasPreviousPage

        hasNextPage

    }

}

}`

if I have the first param being set as 10, and the data source (or database table) only have 9 entries, a TypedLinkException is thrown

螢幕截圖 2021-08-27 上午3 13 40

The stack trace retrieved from Android Studio is as follows

`#0 BuiltJsonSerializers._deserialize (package:built_value/src/built_json_serializers.dart:178:11)

#1 BuiltJsonSerializers.deserialize (package:built_value/src/built_json_serializers.dart:124:18)

#2 BuiltJsonSerializers.deserializeWith (package:built_value/src/built_json_serializers.dart:42:12)

#3 GgetMyclassData.fromJson (package:my_app/graphql/get_my_class.data.gql.dart:29:23)

#4 GgetMyclassReq.parseData (package:my_app/graphql/get_my_class.req.gql.dart:53:27)

#5 GqlTypedLink.request. (package:ferry/src/gql_typed_link.dart:29:42)

#6 _HandlerEventSink.add (dart:async/stream_transformers.dart:209:17)

#7 _SinkTransformerStreamSubscription._handleData (dart:async/stream_transformers.dart:111:24)

#8 _rootRunUnary (dart:async/zone.dart:1362:47)

#9 _CustomZone.runUnary (dart:async/zone.dart:1265:19)

#10 _CustomZone.runUnaryGuarded (dart:async/zone.dart:1170:7)

#11 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:341:11)

#12 _DelayedData.perform (dart:async/stream_impl.dart:591:14)

#13 _StreamImplEvents.handleNext (dart:async/stream_impl.dart:706:11)

#14 _PendingEvents.schedule. (dart:async/stream_impl.dart:663:7)

#15 _rootRun (dart:async/zone.dart:1346:47)

#16 _CustomZone.run (dart:async/zone.dart:1258:19)

#17 _CustomZone.runGuarded (dart:async/zone.dart:1162:7)

#18 _CustomZone.bindCallbackGuarded. (dart:async/zone.dart:1202:23)

#19 _rootRun (dart:async/zone.dart:1354:13)

#20 _CustomZone.run (dart:async/zone.dart:1258:19)

#21 _CustomZone.runGuarded (dart:async/zone.dart:1162:7)

#22 _CustomZone.bindCallbackGuarded. (dart:async/zone.dart:1202:23)

#23 _microtaskLoop (dart:async/schedule_microtask.dart:40:21)

#24 _startMicrotaskLoop (dart:async/schedule_microtask.dart:49:5)

`

Thank you for the assistance!

Is there any known solution?

@chungonion
Copy link

chungonion commented Aug 26, 2021

I shared a similar situation, is that when the data has only 9 entries, and with the first parameter is at 10, then the entire data object is returning null.

Any idea on how to fix or is this a bug (or feature?)

I don't understand your situation. Can you explain with an example? It is really weird getting null with no reason.

Yes it is also quite weird to me that it returns null on a weird spot.
Assume I have a query that is going to get the comments, and the query looks like this:
`query getComments($first:Int,$after:String){

comments(first: $first, after: $after)

{

    nodes

    {

        content

    }

    pageInfo

    {

        startCursor

        endCursor

        hasPreviousPage

        hasNextPage

    }

}

}if I have thefirstparam being set as 10, and the data source (or database table) only have 9 entries, aTypedLinkExceptionis thrown ![螢幕截圖 2021-08-27 上午3 13 40](https://user-images.githubusercontent.com/13744707/131022399-9b5a38d1-f8c2-44a7-aa5f-48455cce9538.png) The stack trace retrieved from Android Studio is as follows#0 BuiltJsonSerializers._deserialize (package:built_value/src/built_json_serializers.dart:178:11)
#1 BuiltJsonSerializers.deserialize (package:built_value/src/built_json_serializers.dart:124:18)
#2 BuiltJsonSerializers.deserializeWith (package:built_value/src/built_json_serializers.dart:42:12)
#3 GgetMyclassData.fromJson (package:my_app/graphql/get_my_class.data.gql.dart:29:23)
#4 GgetMyclassReq.parseData (package:my_app/graphql/get_my_class.req.gql.dart:53:27)
#5 GqlTypedLink.request. (package:ferry/src/gql_typed_link.dart:29:42)
#6 _HandlerEventSink.add (dart:async/stream_transformers.dart:209:17)
#7 _SinkTransformerStreamSubscription._handleData (dart:async/stream_transformers.dart:111:24)
#8 _rootRunUnary (dart:async/zone.dart:1362:47)
#9 _CustomZone.runUnary (dart:async/zone.dart:1265:19)
#10 _CustomZone.runUnaryGuarded (dart:async/zone.dart:1170:7)
#11 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:341:11)
#12 _DelayedData.perform (dart:async/stream_impl.dart:591:14)
#13 _StreamImplEvents.handleNext (dart:async/stream_impl.dart:706:11)
#14 _PendingEvents.schedule. (dart:async/stream_impl.dart:663:7)
#15 _rootRun (dart:async/zone.dart:1346:47)
#16 _CustomZone.run (dart:async/zone.dart:1258:19)
#17 _CustomZone.runGuarded (dart:async/zone.dart:1162:7)
#18 _CustomZone.bindCallbackGuarded. (dart:async/zone.dart:1202:23)
#19 _rootRun (dart:async/zone.dart:1354:13)
#20 _CustomZone.run (dart:async/zone.dart:1258:19)
#21 _CustomZone.runGuarded (dart:async/zone.dart:1162:7)
#22 _CustomZone.bindCallbackGuarded. (dart:async/zone.dart:1202:23)
#23 _microtaskLoop (dart:async/schedule_microtask.dart:40:21)
#24 _startMicrotaskLoop (dart:async/schedule_microtask.dart:49:5)
`
Thank you for the assistance!

Is there any known solution?

That's also what I am looking for :-(

@chungonion
Copy link

@dokumanx I think we shared a similar issue, would you also post your stack trace provided in Android Studio breakpoint so that someone can see that?

@smkhalsa
Copy link
Member

smkhalsa commented Sep 6, 2021

@dokumanx in the debug console you posted, there was a linkException. Can you post the full exception?

@dokumanx
Copy link
Author

dokumanx commented Sep 6, 2021

stackTrace:

#0      GJSON.serializer.<anonymous closure> (package:meh/graphql/schema/schema.schema.gql.dart:47:48)
#1      DefaultScalarSerializer.deserialize (package:gql_code_builder/src/serializers/default_scalar_serializer.dart:21:19)
#2      BuiltJsonSerializers._deserialize (package:built_value/src/built_json_serializers.dart:184:28)
#3      BuiltJsonSerializers.deserialize (package:built_value/src/built_json_serializers.dart:124:18)
#4      _$GStudentNotificationData_student_notificationsSerializer.deserialize (package:meh/graphql/schema/queries/student_notifications.data.gql.g.dart:193:43)
#5      BuiltJsonSerializers._deserialize (package:built_value/src/built_json_serializers.dart:175:28)
#6      BuiltJsonSerializers.deserialize (package:built_value/src/built_json_serializers.dart:124:18)
#7      BuiltListSerializer.deserialize.<anonymous closure> (package:built_value/src/built_list_serializer.dart:46:31)
#8      MappedListIterable.elementAt (dart:_internal/iterable.dart:412:31)
#9      ListIterator.moveNext (dart:_internal/iterable.dart:341:26)
#10     new List.from (dart:core-patch/array_patch.dart:40:17)
#11     ListBuilder.replace (package:built_collection/src/list/list_builder.dart:44:20)
#12     BuiltListSerializer.deserialize (package:built_value/src/built_list_serializer.dart:45:12)
#13     BuiltJsonSerializers._deserialize (package:built_value/src/built_json_serializers.dart:175:28)
#14     BuiltJsonSerializers.deserialize (package:built_value/src/built_json_serializers.dart:124:18)
#15     _$GStudentNotificationData_studentSerializer.deserialize (package:meh/graphql/schema/queries/student_notifications.data.gql.g.dart:118:52)
#16     BuiltJsonSerializers._deserialize (package:built_value/src/built_json_serializers.dart:175:28)
#17     BuiltJsonSerializers.deserialize (package:built_value/src/built_json_serializers.dart:124:18)
#18     _$GStudentNotificationDataSerializer.deserialize (package:meh/graphql/schema/queries/student_notifications.data.gql.g.dart:61:46)
#19     BuiltJsonSerializers._deserialize (package:built_value/src/built_json_serializers.dart:175:28)
#20     BuiltJsonSerializers.deserialize (package:built_value/src/built_json_serializers.dart:124:18)
#21     BuiltJsonSerializers.deserializeWith (package:built_value/src/built_json_serializers.dart:42:12)
#22     GStudentNotificationData.fromJson (package:meh/graphql/schema/queries/student_notifications.data.gql.dart:32:12)
#23     GStudentNotificationReq.parseData (package:meh/graphql/schema/queries/student_notifications.req.gql.dart:48:36)
#24     GqlTypedLink.request.<anonymous closure> (package:ferry/src/gql_typed_link.dart:29:42)
#25     _HandlerEventSink.add (dart:async/stream_transformers.dart:209:17)
#26     _SinkTransformerStreamSubscription._handleData (dart:async/stream_transformers.dart:111:24)
#27     _rootRunUnary (dart:async/zone.dart:1362:47)
#28     _CustomZone.runUnary (dart:async/zone.dart:1265:19)
#29     _CustomZone.runUnaryGuarded (dart:async/zone.dart:1170:7)
#30     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:341:11)
#31     _DelayedData.perform (dart:async/stream_impl.dart:591:14)
#32     _StreamImplEvents.handleNext (dart:async/stream_impl.dart:706:11)
#33     _PendingEvents.schedule.<anonymous closure> (dart:async/stream_impl.dart:663:7)
#34     _rootRun (dart:async/zone.dart:1346:47)
#35     _CustomZone.run (dart:async/zone.dart:1258:19)
#36     _CustomZone.runGuarded (dart:async/zone.dart:1162:7)
#37     _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:1202:23)
#38     _rootRun (dart:async/zone.dart:1354:13)
#39     _CustomZone.run (dart:async/zone.dart:1258:19)
#40     _CustomZone.runGuarded (dart:async/zone.dart:1162:7)
#41     _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:1202:23)
#42     _microtaskLoop (dart:async/schedule_microtask.dart:40:21)
#43     _startMicrotaskLoop (dart:async/schedule_microtask.dart:49:5)

Error Message:

type 'List<Object?>' is not a subtype of type 'String?' in type cast

Error Location in schema.schema.gql.dart

abstract class GJSON implements Built<GJSON, GJSONBuilder> {
  GJSON._();

  factory GJSON([String? value]) =>
      _$GJSON((b) => value != null ? (b..value = value) : b);

  String get value;
  @BuiltValueSerializer(custom: true)
  static Serializer<GJSON> get serializer => _i1.DefaultScalarSerializer<GJSON>(
      (Object serialized) => GJSON((serialized as String?)));
}

@smkhalsa
Copy link
Member

smkhalsa commented Sep 6, 2021

Looks like you're using a custom JSON scalar but haven't provided any configuration for it.

Did you follow the instructions in the docs for custom scalars?

@dokumanx
Copy link
Author

dokumanx commented Sep 6, 2021

I haven't changed anything for JSON scalar and it affects only this part. I created a custom scalar for Upload. If it is needed, would you mind give me an example for JSON scalar? And if you have any idea about why it affects only this part of the queries I will be appreciated to hear. Thanks for your response.

@smkhalsa
Copy link
Member

smkhalsa commented Sep 6, 2021

It would only affect this part of the query because it only triggers when trying to deserialize the scalar.

Please read the docs.

https://ferrygraphql.com/docs/custom-scalars#using-structuredserializers

@smkhalsa smkhalsa closed this as completed Sep 6, 2021
@dokumanx
Copy link
Author

dokumanx commented Sep 6, 2021

I read the docs. But still have no clue about creating StructuredSerializer. There is no enough example for different usecases. Can you give me an example or even an explanation about how it works and how can we customize it for our needs?

@chungonion
Copy link

I read the docs. But still have no clue about creating StructuredSerializer. There is no enough example for different usecases. Can you give me an example or even an explanation about how it works and how can we customize it for our needs?

Basically, to my understanding, you would have to create a Model class in your dart project, then specify how will the json object http response in plain text will be converted into your own dart classes. This the process known as serialization and deserialization.

If you wish, you may also refer to json_serializable package for less of a hassle on performing serialization and deserialization actions.

@smkhalsa
Copy link
Member

smkhalsa commented Sep 7, 2021

If you wish, you may also refer to json_serializable package for less of a hassle on performing serialization and deserialization actions.

ferry expects built_value serializers, so you won't be able to use json_serializable

@smkhalsa
Copy link
Member

smkhalsa commented Sep 7, 2021

I read the docs. But still have no clue about creating StructuredSerializer. There is no enough example for different usecases. Can you give me an example or even an explanation about how it works and how can we customize it for our needs?

I suggest asking for help on the discord

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants