-
-
Notifications
You must be signed in to change notification settings - Fork 119
Simple naming causes duplicate Query/Mutation classes #226
Comments
Hi. You need to give them different names or use another naming schema |
@vasilich6107 when you say different names do you mean inside the graphql file? query client { # <-- this name
client(id: ID!) {
# ... fields
}
}
# file B
query clientDetails { # <-- is different from this
clientDetails {
# ... fields
}
} Or do you mean different names somewhere else? |
For some reason it generates two classes with |
Could you fill the issue with all data required for reproduction?
|
@vasilich6107 I managed to narrow it right down to a super minimal queries/schema which I've posted in the link above. If that isn't clear or doesn't work in that tool I can repost them here since I've stripped out anything sensitive |
I’ll check. |
Check if this fix works for you
|
@vasilich6107 That seems to have worked just rebuilt my project and didn't get the error. It now seems to build separate |
Awesome, I'll prepare a new release later this week |
@vasilich6107 I think I spoke too soon. I'm no longer getting the name clash and separate classes per query are being created but all the subclasses are named with what looks like the default strategy and quite a few of the simply named types that are being referenced aren't being created |
Could you add more information? |
It will be great if you create some demo repo to showcase your issues. I’ll be able to quickly reproduce and test fixes |
@vasilich6107 I just created https://github.com/akinsho/test_artemis which demonstrates the issue. If you pull this down and build the types, then go to the |
Thanks |
@akinsho could you reinstall the |
@vasilich6107 I think that's the one 👍🏿 just tried it and it seems to have solved the issues |
Some thought about
From our experience only Then you'll be able to use them as Supporting 3 naming schemas adds more complexity and maintenance overhead. |
@vasilich6107 I've tried both of the alternatives but we have a few complex with a lot of fields and sub types. These queries don't really need fragments (since we won't reuse the selections) and the sort of class names that are being generated are huge. I think it would makes things a bit complex for my colleagues to have a bunch of fragments we only ever use once just so we can generate more readable names. I'm happy to have to alias things if they clash but much prefer the simple naming. I've used type generation for graphql using gqlgen for golang and apollo with TS and they both seem to create readable names 🤷🏿♂️ I don't know much about their internals but maybe there might be an applicable solution there. Anyway the solution you provided in the branch seems to fix things. 🤞🏿 you don't remove the strategy anytime soon 😅 |
The most interesting part will begin when you'll need 2 types with different selection set ;-) |
I assume we will come with some kind of an alternative strategy for simple naming in case we decide to discontinue naming schema support) |
😅 I'm assuming in this case I would be able to alias the query and that should work. I've had to do a similar thing before when using gqlgen and that was fine, especially since the queries are technically different having a different name makes sense.
👍🏿 I think having some form of simpler naming (even with trade offs) would be much appreciated by other people |
@akinsho how it works? |
@vasilich6107 yeah this resolved the duplicate name issue for me 👍🏿 , I ended up switching naming scheme anyway though since I ended up with another I think unrelated error about missing constructors. Don't remember the exact error atm. But yeah I think this is good to go. As a side note this is what some of the longer names look like |
Extract your selection set into a fragment and you’ll get a Something like
Then you’ll get |
Which scheme is preferable to rely on so that in the future there will be no problems when updating? |
@alexkharech |
Fixed in 6.17 |
Bug description
When running artemis code generation, using the
simple
naming scheme with two queries in two separate files both returning different data. I get a duplicate class name error for theQuery
.From what I can see with only one query a class called
Query
is generated representing the single query I have. Once I have another though this causes a conflict. I understand that the simple naming doesn't do any name spacing and just uses the graphql class name but I would have thought in the case of a query or mutation the name I gave my query would be the class name.e.g.
In this case I would have expected the class name generated to be
GetActivityQuery
andGetUserQuery
rather than attempting to create 2Query
classes.It could be that I've misunderstood how the
simple
strategy works and that it is only valid if you have one query and one mutation but I guessed not. Anyway thanks for your hard work it's made my development much easier in general 🙌🏿 . If you need any information please let me know, I've only added snippets of the output as it's a private work project 😓 . But I don't think the verbose output shows anything more as this happens regardless of what actual query isSpecs
Artemis version: 6.13.1-beta.1
build.yaml:
Artemis output:
GraphQL schema:
GraphQL query:
The text was updated successfully, but these errors were encountered: