amplify-codegen icon indicating copy to clipboard operation
amplify-codegen copied to clipboard

Flutter: Import statements on generated models don't use a prefix causing type confusion

Open OSonntag opened this issue 3 years ago • 0 comments

Before opening, please confirm:

  • [X] I have installed the latest version of the Amplify CLI (see above), and confirmed that the issue still persists.
  • [X] I have searched for duplicate or closed issues.
  • [X] I have read the guide for submitting bug reports.
  • [X] I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.

How did you install the Amplify CLI?

npm

If applicable, what version of Node.js are you using?

v16.14.2

Amplify CLI Version

9.2.1

What operating system are you using?

macOS

Amplify Codegen Command

codegen models

Describe the bug

First of all this is flutter related!

When declaring types in the schema.graphql e.g. enum EventType { a, b } that do exists in terms of naming in the imported packages in the generated files from codegen, flutter is not able to resolve the correct type as it exits two times then.

image

Expected behavior

All self created types can be choosen (by name)

Reproduction steps

Declare a enum EventType { a, b } in the schema.graphql and use this type in an entity in the schema.graphql and then amplify push amplify codegen models .

The generated files are not compile able by default.

GraphQL schema(s)

# Put schemas below this line


Log output

# Put your logs below this line


Additional information

This can easy be solved if the imports:

import 'ModelProvider.dart';
import 'package:amplify_core/amplify_core.dart';
import 'package:collection/collection.dart';
import 'package:flutter/foundation.dart';

would be written like:

import 'ModelProvider.dart';
import 'package:amplify_core/amplify_core.dart' as amplify_core;
import 'package:collection/collection.dart' as collection;
import 'package:flutter/foundation.dart' as flutter_foundation;

beacuse now all types can be resolved correctly. Of course this prefix now needs to be added anywhere where its used!

OSonntag avatar Sep 05 '22 17:09 OSonntag