Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions packages/graphql_codegen/example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@ packages:
dependency: transitive
description:
name: characters
sha256: f71061c654a3380576a52b451dd5532377954cf9dbd272a78fc8479606670803
sha256: faf38497bda5ead2a8c7615f4f7939df04333478bf32e4173fcb06d428b5716b
url: "https://pub.dev"
source: hosted
version: "1.4.0"
version: "1.4.1"
checked_yaml:
dependency: transitive
description:
Expand Down Expand Up @@ -337,7 +337,7 @@ packages:
path: ".."
relative: true
source: path
version: "3.0.0"
version: "3.0.1"
graphql_flutter:
dependency: "direct main"
description:
Expand Down Expand Up @@ -430,18 +430,18 @@ packages:
dependency: transitive
description:
name: material_color_utilities
sha256: f7142bb1154231d7ea5f96bc7bde4bda2a0945d2806bb11670e30b850d56bdec
sha256: "9c337007e82b1889149c82ed242ed1cb24a66044e30979c44912381e9be4c48b"
url: "https://pub.dev"
source: hosted
version: "0.11.1"
version: "0.13.0"
meta:
dependency: transitive
description:
name: meta
sha256: e3641ec5d63ebf0d9b41bd43201a66e3fc79a65db5f61fc181f04cd27aab950c
sha256: "1741988757a65eb6b36abe716829688cf01910bbf91c34354ff7ec1c3de2b349"
url: "https://pub.dev"
source: hosted
version: "1.16.0"
version: "1.18.0"
mime:
dependency: transitive
description:
Expand Down Expand Up @@ -832,5 +832,5 @@ packages:
source: hosted
version: "3.1.3"
sdks:
dart: ">=3.9.0 <4.0.0"
dart: ">=3.10.0-0 <4.0.0"
flutter: ">=3.29.0"
2 changes: 1 addition & 1 deletion packages/graphql_codegen/example/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: graphql_codegen_example

environment:
sdk: ">=2.17.0 <3.0.0"
sdk: ">=3.8.0 <4.0.0"

dependencies:
graphql_flutter: ^5.2.1
Expand Down
3 changes: 0 additions & 3 deletions packages/graphql_codegen/lib/src/config/config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ class GraphQLCodegenConfigScalar {
this.toJsonFunctionName,
});

@override
factory GraphQLCodegenConfigScalar.fromJson(Map<String, dynamic> json) =>
_$GraphQLCodegenConfigScalarFromJson(json);

Expand All @@ -45,7 +44,6 @@ class GraphQLCodegenConfigEnum {
required this.fallbackEnumValue,
});

@override
factory GraphQLCodegenConfigEnum.fromJson(Map<String, dynamic> json) =>
_$GraphQLCodegenConfigEnumFromJson(json);

Expand Down Expand Up @@ -92,7 +90,6 @@ class GraphQLCodegenConfig {
this.setOperationName = false,
});

@override
factory GraphQLCodegenConfig.fromJson(Map<String, dynamic> json) =>
_$GraphQLCodegenConfigFromJson(json);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ class RecursiveTransformingVisitor extends Visitor<Node> {
description: visitOne(node.description),
directives: visitAll(node.directives),
fields: visitAll(node.fields),
interfaces: visitAll(node.interfaces),
);
}

Expand All @@ -205,6 +206,7 @@ class RecursiveTransformingVisitor extends Visitor<Node> {
name: visitOne(node.name),
directives: visitAll(node.directives),
fields: visitAll(node.fields),
interfaces: visitAll(node.interfaces),
);
}

Expand Down
42 changes: 27 additions & 15 deletions packages/graphql_codegen/lib/src/visitor/context_visitor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -143,25 +143,37 @@ class ContextVisitor extends RecursiveVisitor {
_visitInFragment(fragmentDef, fragmentName);
return;
}
if (context.currentType is! ObjectTypeDefinitionNode) {
return;
}
// Current type condition
final typeCondition = fragmentDef.typeCondition;
if (context.currentType is ObjectTypeDefinitionNode) {
// Current type condition
final typeCondition = fragmentDef.typeCondition;

// Find concrete types of the type conditions.
final typeConditionConcreteTypes = context.schema
.lookupConcreteTypes(typeCondition.on.name)
.map((e) => e.name)
.toSet();
// Find concrete types of the type conditions.
final typeConditionConcreteTypes = context.schema
.lookupConcreteTypes(typeCondition.on.name)
.map((e) => e.name)
.toSet();

if (!typeConditionConcreteTypes.contains(context.currentType.name)) {
if (!typeConditionConcreteTypes.contains(context.currentType.name)) {
return;
}
final typedFragmentName = fragmentName.withSegment(
TypeNameSegment(context.currentType.name),
);
_visitInFragment(fragmentDef, typedFragmentName);
return;
}
final typedFragmentName = fragmentName.withSegment(
TypeNameSegment(context.currentType.name),
);
_visitInFragment(fragmentDef, typedFragmentName);

final currentType = context.currentType;
if (currentType is InterfaceTypeDefinitionNode) {
final typeConditionName = fragmentDef.typeCondition.on.name;
final currentTypeInterfaces = currentType.interfaces
.map((e) => e.name)
.toSet();
if (!currentTypeInterfaces.contains(typeConditionName)) {
return;
}
_visitInFragment(fragmentDef, fragmentName);
}
}

@override
Expand Down
10 changes: 5 additions & 5 deletions packages/graphql_codegen/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ packages:
dependency: transitive
description:
name: _fe_analyzer_shared
sha256: dd3d2ad434b9510001d089e8de7556d50c834481b9abc2891a0184a8493a19dc
sha256: f0bb5d1648339c8308cc0b9838d8456b3cfe5c91f9dc1a735b4d003269e5da9a
url: "https://pub.dev"
source: hosted
version: "89.0.0"
version: "88.0.0"
analyzer:
dependency: transitive
description:
name: analyzer
sha256: c22b6e7726d1f9e5db58c7251606076a71ca0dbcf76116675edfadbec0c9e875
sha256: "0b7b9c329d2879f8f05d6c05b32ee9ec025f39b077864bdb5ac9a7b63418a98f"
url: "https://pub.dev"
source: hosted
version: "8.2.0"
version: "8.1.1"
args:
dependency: transitive
description:
Expand Down Expand Up @@ -698,4 +698,4 @@ packages:
source: hosted
version: "3.1.3"
sdks:
dart: ">=3.9.0 <4.0.0"
dart: ">=3.8.0 <4.0.0"
2 changes: 1 addition & 1 deletion packages/graphql_codegen/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ environment:
sdk: ">=3.8.0 <4.0.0"

dependencies:
gql: ^1.0.0
gql: ^1.0.1
build: "^4.0.1"
glob: ^2.0.1
code_builder: ^4.2.0
Expand Down
29 changes: 29 additions & 0 deletions packages/graphql_codegen/test/assets/issue_415/schema.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
interface Node {
id: ID!
}
interface Animal implements Node {
id: ID!
name: String!
}
type Dog implements Animal & Node {
id: ID!
name: String!
goodBoy: Boolean!
}
type Query {
animal: Animal!
}

fragment NodeFragment on Node {
id
}
fragment AnimalFragment on Animal {
...NodeFragment
name
}

query GetAnimal {
animal {
...AnimalFragment
}
}
Loading
Loading