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

[bug] The dissimilarity of fromJSON with data when using fragments over union types #341

Closed
meg4cyberc4t opened this issue Mar 2, 2024 · 2 comments

Comments

@meg4cyberc4t
Copy link

I have this query:

query getStudentTask($input: GetStudentTaskInput!, $studentId: UUID) {
  getStudentTask_v2(input: $input) {
    ...TaskFragment
  }
}

fragment TaskFragment on Task {
  id
  contentBlock {
    ...TopicContentBlockFragment
  }
  answers {
    ...TaskAnswerFragment
  }
}


fragment TopicContentBlockFragment on DisciplineTopicContentBlock {
  ... on InfoDisciplineTopicContentBlock {
    body
    id
    kind
    name
    order
  }
  ... on TaskDisciplineTopicContentBlock {
    body
    id
    kind
    maxScore
    name
    order
    studentCanSendAnswers(studentId: $studentId)
    studentCanSendAnswersAfterDeadline(studentId: $studentId)
    studentDeadline(studentId: $studentId)
  }
  ... on TestDisciplineTopicContentBlock {
    body
    deadlineDate
    id
    kind
    testMaxScore: maxScore
    name
    order
    testId
    canBePassed
    canBeUpdated
    studentScore(studentId: $studentId)
    availableIntervalForStudent(studentId: $studentId) {
      from
      to
    }
  }
}

The assembly takes place without errors, scanning network requests, it is clear that everything is OK.
Снимок экрана 2024-03-02 в 20 25 13

However, at the moment of fromJson unpacking, the following error appears:

StudentTaskBloc cathing error type 'Null' is not a subtype of type 'String' in type cast | type 'Null' is not a subtype of type 'String' in type cast
flutter: #0      new Fragment$TopicContentBlockFragment$$TaskDisciplineTopicContentBlock.fromJson (package:new_lxp_mobile/src/features/topics/data/data_sources/remote/fragments/topic_content_block_fragment.graphql.dart:894:21)
...

After conducting my own research, I find out that:

factory Query$getStudentTask.fromJson(Map<String, dynamic> json) {
    print(json);
    ...
}

sends this

flutter: {getStudentTask_v2: {id: a3ac7438-4f4e-4109-83c0-f27e8f148952, contentBlock: {__typename: TaskDisciplineTopicContentBlock}, answers: [], __typename: Task}, __typename: Query}

For all proxies, I saw that the data is being received, but at the very top of FromJSON, the part with steaming from union is lost.

Copy link

github-actions bot commented Mar 2, 2024

👋 @meg4cyberc4t
Thank you for raising an issue. I will investigate the issue and get back to you as soon as possible.
Please make sure you have provided enough context.

This library is created and maintained by me, @budde377. Please consider supporting my work and ensure our survival by donating here.

@budde377
Copy link
Contributor

budde377 commented Mar 5, 2024

Thanks for reporting this! If I understand you correctly the vales from the GraphQL client does not match the network request. I suspect this might be caused by normalisation. Can you share your schema? And have you provided the possibleTypesMap to your client?

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

2 participants