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

Strange generation of nullable and non-nullable lists #309

Closed
meg4cyberc4t opened this issue Aug 27, 2023 · 8 comments · Fixed by #312
Closed

Strange generation of nullable and non-nullable lists #309

meg4cyberc4t opened this issue Aug 27, 2023 · 8 comments · Fixed by #312
Labels
bug Something isn't working

Comments

@meg4cyberc4t
Copy link

Hi.
I have this input in my schema.graphql.

input TemplateDisciplineTopicContentInput {
  howStudyIt: String!
  infoContentBlocks: [InfoTemplateDisciplineTopicContentBlockInput!]!
  taskContentBlocks: [TaskTemplateDisciplineTopicContentBlockInput!]!
  testContentBlocks: [TestTemplateDisciplineTopicContentBlockInput!]! = []
  whyStudyIt: String!
}

You can see that "testContentBlocks" is not an updatable list with a default value. And "taskContentBlocks" is the same, but does not have a default value.
But they are generated in different ways, it confuses me exactly:

 List<Input$InfoDisciplineTopicContentBlockInput> get infoContentBlocks =>
      (_$data['infoContentBlocks']
          as List<Input$InfoDisciplineTopicContentBlockInput>);
  List<Input$TaskDisciplineTopicContentBlockInput> get taskContentBlocks =>
      (_$data['taskContentBlocks']
          as List<Input$TaskDisciplineTopicContentBlockInput>);
  List<Input$TestDisciplineTopicContentBlockInput>? get testContentBlocks =>
      (_$data['testContentBlocks']

"testContentBlocks" has become nullable.. but however, in the rest of the code, it is still considered non-null.

  TRes testContentBlocks(
          Iterable<Input$TestDisciplineTopicContentBlockInput> Function(
                  Iterable<
                      CopyWith$Input$TestDisciplineTopicContentBlockInput<
                          Input$TestDisciplineTopicContentBlockInput>>)
              _fn) =>
      call(
          testContentBlocks: _fn(_instance.testContentBlocks
              .map((e) => CopyWith$Input$TestDisciplineTopicContentBlockInput(
                    e,
                    (i) => i,
                  ))).toList());

-- This is an example where my linter indicates the use of a list without an operator ?.

As a result, an error occurs when building the application.

@github-actions
Copy link

👋 @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.

@meg4cyberc4t
Copy link
Author

To be honest, I don't fully understand how the values in the default input are processed on the client side.
In the generated files I also see:

 factory Input$DisciplineTopicContentInput({
    required String howStudyIt,
    required List<Input$InfoDisciplineTopicContentBlockInput> infoContentBlocks,
    required List<Input$TaskDisciplineTopicContentBlockInput> taskContentBlocks,
    List<Input$TestDisciplineTopicContentBlockInput>? testContentBlocks,
    required String whyStudyIt,
  }) =>
      Input$DisciplineTopicContentInput._({
        r'howStudyIt': howStudyIt,
        r'infoContentBlocks': infoContentBlocks,
        r'taskContentBlocks': taskContentBlocks,
        if (testContentBlocks != null) r'testContentBlocks': testContentBlocks,
        r'whyStudyIt': whyStudyIt,
      });

But because of this nullable value, the generation of "_CopyWithImpl$Input$DisciplineTopicContentInput" crashes

@meg4cyberc4t
Copy link
Author

For enough context:

graphql: ^5.2.0-beta.1
graphql_flutter: ^5.1.2
graphql_codegen: ^0.13.5

@budde377
Copy link
Contributor

I've recently changed how input with default values are generated and it would seem like I've missed a few places. Let me investigate!

@budde377 budde377 added the bug Something isn't working label Aug 27, 2023
@meg4cyberc4t
Copy link
Author

Hi. Is there any updates for me?)

@budde377
Copy link
Contributor

budde377 commented Sep 15, 2023 via email

@budde377
Copy link
Contributor

A fix should be released now as 0.13.6.

@meg4cyberc4t
Copy link
Author

It looks great! Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants