Create one file for each query when using wildcards on queries_glob
I have this on my build.yaml
schema_mapping:
- schema: rygapp.schema.json
queries_glob: graphql/**.query.graphql
output: lib/graphql/consultas.dart
When I run I received this error :
Exception: Two classes were generated with the same name Usuario!
You may want to do either:
-
Enable add_query_prefix on this schema_map
-
Make queries_glob stricter, to gather less .graphql files on a single output
-
Use alias on one of the places a
Usuariofield is requestedOk. I understand what causes the issue.
What about create one file per query :
schema_mapping:
- schema: rygapp.schema.json
queries_glob: graphql/**.query.graphql
output: lib/graphql/**
So it will create many files without the need to declare each query on build.yaml
I thought that when you use queries_glob: graphql/**.query.graphql and leave without output it would create separate files for each query found.
Hey @danilolr, @amadeu01
That was the breaking change introduced in 1.0.0. Before that, it was possible to generate mutiple files just by using a query glob.
However, since 1.0.0, I've started using $lib$ synthetic input to builder code generation. It was a trade-off to make Artemis more performant, and to have more flexibility to change the output location. By using this synthetic input, we need to know the path of all output files before running the generator, and that's why you can't have an output glob anymore.
Say that you queries_glob have two queries (a_query and b_query). To make it work just like before you'll need to manually have a schema_mapping for each of them, like this:
schema_mapping:
- schema: rygapp.schema.json
queries_glob: graphql/a_query.graphql
output: lib/graphql/a_query.dart
- schema: rygapp.schema.json
queries_glob: graphql/b_query.graphql
output: lib/graphql/b_query.dart
I couldn't think in a way of defining multiple glob outputs from a glob input, so any feedback will be appreciated if you can think in a way we can solve this! Because, as I said, that's a limitation on how build work for Dart.
I'm gonna mark this as a possible enhancement to the library: to be able to have ouput globs again.
Oh yeah, people already gave me the idea of namespacing each query, like in this example, where we have two queries with a common type (Customer), with different fields.
query a_query {
customer {
name
}
}
query b_query {
customer {
age
}
}
In this example, two different classes would be generated: AQueryCustomer and BQueryCustomer. What do you guys feel about that?
In this example, two different classes would be generated: AQueryCustomer and BQueryCustomer. What do you guys feel about that?
@comigor This is how the apollo-tooling codegen works. It seems like a good approach.
Is this something that we can implement anytime soon? I'd like to ty artemis with a larger project, so I'd definitely like to avoid having to manually define each schema_mapping.
This should already be implemented just by enabling add_query_prefix on schema_mapping:
schema_mapping:
- schema: rygapp.schema.json
queries_glob: graphql/**.query.graphql
output: lib/graphql/consultas.dart
add_query_prefix: true
Could you test this approach and report back, please?
@comigor oh, great! Yes, I'll test and let you know if I run into any issues. Thanks for the quick response!
First of all, thank you for building this useful tool! I'm looking forward to have this implemented on this tool, my project would benefit a lot from this functionality. In the meantime I planned to use add_query_prefix to generate diferent prefixes and avoid the class name collision but I wasn't able to use it with all my queries whenever more than one query returned a graphql enum of the same type, however this setting worked fine with other queries that didn't return an enum of the same type.
Hello @edwjusti, thanks!
Hmm I see. It may be related to https://github.com/comigor/artemis/issues/30, which was fixed by this PR https://github.com/comigor/artemis/pull/46.
I bet that's the same issue with Enums, so I'll open another issue for that.