Skip to content
This repository has been archived by the owner on Oct 2, 2024. It is now read-only.

Create one file for each query when using wildcards on queries_glob #27

Open
danilolr opened this issue Sep 17, 2019 · 9 comments
Open
Labels
enhancement New feature or request

Comments

@danilolr
Copy link

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 Usuario field is requested

    Ok. 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

@amadeu01
Copy link
Contributor

I thought that when you use queries_glob: graphql/**.query.graphql and leave without output it would create separate files for each query found.

@comigor
Copy link
Owner

comigor commented Sep 18, 2019

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.

@comigor
Copy link
Owner

comigor commented Sep 18, 2019

I'm gonna mark this as a possible enhancement to the library: to be able to have ouput globs again.

@comigor comigor added the enhancement New feature or request label Sep 18, 2019
@comigor
Copy link
Owner

comigor commented Sep 18, 2019

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?

@smkhalsa
Copy link

smkhalsa commented Oct 16, 2019

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.

@comigor
Copy link
Owner

comigor commented Oct 16, 2019

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?

@smkhalsa
Copy link

@comigor oh, great! Yes, I'll test and let you know if I run into any issues. Thanks for the quick response!

@edwjusti
Copy link

edwjusti commented Nov 5, 2019

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.

@comigor
Copy link
Owner

comigor commented Nov 5, 2019

Hello @edwjusti, thanks!

Hmm I see. It may be related to #30, which was fixed by this PR #46.

I bet that's the same issue with Enums, so I'll open another issue for that.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants