Skip to content

Commit 245779a

Browse files
authored
feat: Support graphqls file (heftapp#313)
1 parent a0f1737 commit 245779a

14 files changed

Lines changed: 371 additions & 35 deletions

File tree

packages/graphql_codegen/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# 0.13.7
2+
3+
- Support `.graphqls` files
4+
15
# 0.13.6
26

37
- Fix bad copy class on list with default value.
File renamed without changes.

packages/graphql_codegen/example/lib/schema.graphql.dart renamed to packages/graphql_codegen/example/lib/schema.graphqls.dart

File renamed without changes.

packages/graphql_codegen/example/pubspec.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ packages:
329329
path: ".."
330330
relative: true
331331
source: path
332-
version: "0.13.6"
332+
version: "0.13.7"
333333
graphql_flutter:
334334
dependency: "direct main"
335335
description:

packages/graphql_codegen/example/test/input_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import 'package:graphql_codegen_example/schema.graphql.dart';
1+
import 'package:graphql_codegen_example/schema.graphqls.dart';
22
import 'package:test/expect.dart';
33
import 'package:test/scaffolding.dart';
44

packages/graphql_codegen/lib/builder.dart

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import 'package:path/path.dart' as path;
1414

1515
final p = path.Context(style: path.Style.posix);
1616

17+
const kGraphQLFileExtensions = ['graphql', 'graphqls', 'gql'];
18+
1719
class _GraphQLParserResource {
1820
Map<AssetId, DocumentNode> _fileCache = {};
1921
Future<DocumentNode> readFile(BuildStep step, AssetId id) async {
@@ -154,30 +156,34 @@ class GraphQLBuilder extends Builder {
154156
@override
155157
Map<String, List<String>> get buildExtensions {
156158
if (p.isRelative(config.outputDirectory)) {
157-
return {
158-
'{{dir}}/{{file}}.graphql': [
159-
p.join('{{dir}}', config.outputDirectory, '{{file}}.graphql.dart')
160-
],
161-
'{{dir}}/{{file}}.gql': [
162-
p.join('{{dir}}', config.outputDirectory, '{{file}}.gql.dart')
163-
]
164-
};
159+
return Map.fromEntries(
160+
kGraphQLFileExtensions.map(
161+
(extension) => MapEntry(
162+
'{{dir}}/{{file}}.${extension}',
163+
[
164+
p.join(
165+
'{{dir}}',
166+
config.outputDirectory,
167+
'{{file}}.${extension}.dart',
168+
),
169+
],
170+
),
171+
),
172+
);
165173
}
166-
return {
167-
p.join(_assetsPrefix, '{{dir}}', '{{file}}.graphql'): [
168-
p.join(
169-
p.relative(config.outputDirectory, from: '/'),
170-
'{{dir}}',
171-
'{{file}}.graphql.dart',
172-
)
173-
],
174-
p.join(_assetsPrefix, '{{dir}}', '{{file}}.gql'): [
175-
p.join(
176-
p.relative(config.outputDirectory, from: '/'),
177-
'{{dir}}',
178-
'{{file}}.gql.dart',
179-
)
180-
],
181-
};
174+
return Map.fromEntries(
175+
kGraphQLFileExtensions.map(
176+
(e) => MapEntry(
177+
p.join(_assetsPrefix, '{{dir}}', '{{file}}.${e}'),
178+
[
179+
p.join(
180+
p.relative(config.outputDirectory, from: '/'),
181+
'{{dir}}',
182+
'{{file}}.${e}.dart',
183+
)
184+
],
185+
),
186+
),
187+
);
182188
}
183189
}

packages/graphql_codegen/lib/src/config/config.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ class GraphQLCodegenConfig {
7373
this.scalars = const {},
7474
this.enums = const {},
7575
this.addTypename = true,
76-
this.assetsPath = "lib/**{.graphql,.gql}",
77-
this.scopes = const ["**{.graphql,.gql}"],
76+
this.assetsPath = "lib/**{.graphql,.gql,.graphqls}",
77+
this.scopes = const ["**{.graphql,.gql,.graphqls}"],
7878
this.addTypenameExcludedPaths = const [],
7979
this.generatedFileHeader = "",
8080
this.namingSeparator = r"$",

packages/graphql_codegen/lib/src/config/config.g.dart

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/graphql_codegen/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ description: |
33
Simple, opinionated, codegen library for GraphQL. It allows you to
44
generate serializers and client helpers to easily call and parse your data.
55
6-
version: 0.13.6
6+
version: 0.13.7
77
homepage: https://github.com/heftapp/graphql_codegen/tree/main/packages/graphql_codegen
88
repository: https://github.com/heftapp/graphql_codegen/tree/main/packages/graphql_codegen
99

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
type Query {
2+
status: String
3+
}
4+
5+
query Q {
6+
status
7+
}

0 commit comments

Comments
 (0)