gql-dart / ferry

Stream-based strongly typed GraphQL client for Dart
https://ferrygraphql.com/
MIT License
593 stars 113 forks source link

Non-dev dependency in ferry_generator package #600

Closed alexeyinkin closed 1 day ago

alexeyinkin commented 2 months ago

I have the following in my generated serializers.gql.dart:

import 'package:gql_code_builder/src/serializers/operation_serializer.dart'
    show OperationSerializer;

This ends up imported into non-dev code that is used when making the actual GraphQL calls, but gql_code_builder is a dependency of ferry_generator which is a dev-dependency of the end-code according to the docs: https://ferrygraphql.com/docs/setup

This is not a problem when ferry_generator is directly included into pubspec.yaml of an app because dev dependencies are still pulled there.

However, when using ferry_generator as a dev-dependency in a package, it's not pulled into an end-app because dev-dependencies are not pulled recursively.

This breaks the build for me with this error despite all pub get run successfully:

Error: Couldn't resolve the package 'gql_code_builder' in 'package:gql_code_builder/src/serializers/default_scalar_serializer.dart'.
Error: Couldn't resolve the package 'gql_code_builder' in 'package:gql_code_builder/src/serializers/operation_serializer.dart'.
../dart_gh/lib/src/graphql/__generated__/schema.docs.2024-05-01.schema.gql.dart:9:8: Error: Not found: 'package:gql_code_builder/src/serializers/default_scalar_serializer.dart'
import 'package:gql_code_builder/src/serializers/default_scalar_serializer.dart'
       ^
../dart_gh/lib/src/graphql/__generated__/serializers.gql.dart:620:8: Error: Not found: 'package:gql_code_builder/src/serializers/operation_serializer.dart'
import 'package:gql_code_builder/src/serializers/operation_serializer.dart'
       ^

The workaround is simple: ferry_generator should be included as a non-dev dependency of the package. However, this brings redundant dependencies and breaks a lot of the original ideas (like the idea to separate ferry and ferry_generator in the first place).

knaeckeKami commented 2 months ago

Thanks!

You're right, this should be fixed, probably the serializers should move to another package.

For now, as a workaround, I suggest adding gql_code_builder as a direct dependency instead of the entirety of ferry_generator.

knaeckeKami commented 2 months ago

please check out ferry_generator 0.12.0-dev.1 note that you need to add gql_code_builder_serializers, which a package that just contains the common serializers that the code generation assumes exist