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

List<Object?> is not subtype of List<Upload> when accepting multiple Uploads in Mutation #15

Closed
SleepySquash opened this issue Sep 17, 2023 · 3 comments

Comments

@SleepySquash
Copy link

Thank you for the package, it's working great!

I've discovered that multiple Uploads currently throw a GraphQLError due to type cast error, caused by leto_generator.

Let's say we have:

@Mutation()
Future<Novel> uploadNovel(
  Ctx ctx, {
  required NovelId id,
  required List<Upload> uploads,
}) async {
    // ...
}

When running leto_generator, the following code is generated:

GraphQLObjectField<Novel, Object?, Object?> get uploadNovelGraphQLField =>
    _uploadNovelGraphQLField.value;
final _uploadNovelGraphQLField =
    HotReloadableDefinition<GraphQLObjectField<Novel, Object?, Object?>>(
        (setValue) => setValue(novelGraphQLType.nonNull().field<Object?>(
              'uploadNovel',
              resolve: (obj, ctx) {
                final args = ctx.args;

                return uploadNovel(ctx,
                    id: (args["id"] as NovelId),
                    uploads: (args["uploads"] as List<Upload>));
              },
            ))
              ..inputs.addAll([
                novelIdGraphQLType.nonNull().inputField('id'),
                Upload.graphQLType
                    .nonNull()
                    .list()
                    .nonNull()
                    .inputField('uploads')
              ]));

And the line:

uploads: (args["uploads"] as List<Upload>));

throws an error in runtime: List<Object?> is not subtype of List<Upload> in type cast.

If that line is changed to:

uploads: (args["uploads"] as List<Object?>).cast<Upload>());

or

uploads: (args["uploads"] as List<Object?>).map((e) => e as Upload).toList());

then everything works flawlessly, uploads are successful.

@SleepySquash SleepySquash changed the title List<Object?> is not subtype of List<Upload> when accepting multiple Uploads in Mutations List<Object?> is not subtype of List<Upload> when accepting multiple Uploads in Mutation Sep 17, 2023
@SleepySquash
Copy link
Author

Workaround I've discovered (until this is fixed):

GraphQLUploadType get objectGraphQLType => uploadGraphQLType;

...

@Mutation()
Future<Novel> uploadNovel(
  Ctx ctx, {
  required NovelId id,
  required List<Object?> uploads,
}) async {
    // use `uploads.cast<Upload>();`
}

juancastillo0 added a commit that referenced this issue Sep 27, 2023
@juancastillo0
Copy link
Owner

Thanks for the issue! Could you try the latest leto_schema: ^0.0.1-dev.5?

@SleepySquash
Copy link
Author

@juancastillo0, works perfectly, thanks 🎉

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