comigor / artemis

Build dart types from GraphQL schemas and queries
MIT License
495 stars 119 forks source link

fix: naming conflict on document with naming_scheme: simple #352

Closed jjangga0214 closed 2 years ago

jjangga0214 commented 2 years ago

Bug description

With naming_schema: simple, an error appears when two different documents requests difference sets of fields of same type. (In this example, one requests title of Post type, the other requests content of Post type. )

Specs

Artemis version: ^7.1.1-beta.1

build.yaml: ```yaml # Please paste your `build.yaml` file targets: $default: builders: artemis: options: schema_mapping: - output: lib/generated/graphql.dart schema: lib/graphql/schema.graphql queries_glob: lib/graphql/documents/**.graphql naming_scheme: simple scalar_mapping: - graphql_type: Uuid dart_type: String - graphql_type: Bigint dart_type: int - graphql_type: Date dart_type: DateTime custom_parser_import: '../graphql/coercers.dart' - graphql_type: Timetz dart_type: name: TimeOfDay imports: - 'package:flutter/material.dart' custom_parser_import: '../graphql/coercers.dart' - graphql_type: Timestamptz dart_type: DateTime custom_parser_import: '../graphql/coercers.dart' ```
Artemis output: **Main Point to debug!**: ``` Class A name:ClassPropertyName(name:r'title'), Class B name:ClassPropertyName(name:r'content'), ``` ```bash # Please paste the output of $ flutter pub run build_runner build --verbose #or $ pub run build_runner build --verbose [ +75 ms] executing: uname -m [ +38 ms] Exit code 0 from: uname -m [ ] x86_64 [ +7 ms] executing: [/home/jjangga/snap/flutter/common/flutter/] git -c log.showSignature=false log -n 1 --pretty=format:%H [ +6 ms] Exit code 0 from: git -c log.showSignature=false log -n 1 --pretty=format:%H [ ] ffb2ecea5223acdd139a5039be2f9c796962833d [ ] executing: [/home/jjangga/snap/flutter/common/flutter/] git tag --points-at ffb2ecea5223acdd139a5039be2f9c796962833d [ +15 ms] Exit code 0 from: git tag --points-at ffb2ecea5223acdd139a5039be2f9c796962833d [ ] 2.5.1 [ +12 ms] executing: [/home/jjangga/snap/flutter/common/flutter/] git rev-parse --abbrev-ref --symbolic @{u} [ +7 ms] Exit code 0 from: git rev-parse --abbrev-ref --symbolic @{u} [ ] origin/stable [ ] executing: [/home/jjangga/snap/flutter/common/flutter/] git ls-remote --get-url origin [ +5 ms] Exit code 0 from: git ls-remote --get-url origin [ ] https://github.com/flutter/flutter.git [ +97 ms] executing: [/home/jjangga/snap/flutter/common/flutter/] git rev-parse --abbrev-ref HEAD [ +6 ms] Exit code 0 from: git rev-parse --abbrev-ref HEAD [ ] stable [ +86 ms] Artifact Instance of 'AndroidGenSnapshotArtifacts' is not required, skipping update. [ ] Artifact Instance of 'AndroidInternalBuildArtifacts' is not required, skipping update. [ ] Artifact Instance of 'IOSEngineArtifacts' is not required, skipping update. [ ] Artifact Instance of 'FlutterWebSdk' is not required, skipping update. [ +4 ms] Artifact Instance of 'WindowsEngineArtifacts' is not required, skipping update. [ ] Artifact Instance of 'WindowsUwpEngineArtifacts' is not required, skipping update. [ ] Artifact Instance of 'MacOSEngineArtifacts' is not required, skipping update. [ ] Artifact Instance of 'LinuxEngineArtifacts' is not required, skipping update. [ ] Artifact Instance of 'LinuxFuchsiaSDKArtifacts' is not required, skipping update. [ ] Artifact Instance of 'MacOSFuchsiaSDKArtifacts' is not required, skipping update. [ ] Artifact Instance of 'FlutterRunnerSDKArtifacts' is not required, skipping update. [ ] Artifact Instance of 'FlutterRunnerDebugSymbols' is not required, skipping update. [ +101 ms] Artifact Instance of 'MaterialFonts' is not required, skipping update. [ +3 ms] Artifact Instance of 'GradleWrapper' is not required, skipping update. [ ] Artifact Instance of 'AndroidGenSnapshotArtifacts' is not required, skipping update. [ ] Artifact Instance of 'AndroidInternalBuildArtifacts' is not required, skipping update. [ ] Artifact Instance of 'IOSEngineArtifacts' is not required, skipping update. [ ] Artifact Instance of 'FlutterWebSdk' is not required, skipping update. [ ] Artifact Instance of 'FlutterSdk' is not required, skipping update. [ ] Artifact Instance of 'WindowsEngineArtifacts' is not required, skipping update. [ ] Artifact Instance of 'WindowsUwpEngineArtifacts' is not required, skipping update. [ ] Artifact Instance of 'MacOSEngineArtifacts' is not required, skipping update. [ ] Artifact Instance of 'LinuxEngineArtifacts' is not required, skipping update. [ ] Artifact Instance of 'LinuxFuchsiaSDKArtifacts' is not required, skipping update. [ ] Artifact Instance of 'MacOSFuchsiaSDKArtifacts' is not required, skipping update. [ ] Artifact Instance of 'FlutterRunnerSDKArtifacts' is not required, skipping update. [ ] Artifact Instance of 'FlutterRunnerDebugSymbols' is not required, skipping update. [ ] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update. [ ] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update. [ ] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update. [ ] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update. [ ] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update. [ ] Artifact Instance of 'FontSubsetArtifacts' is not required, skipping update. [ ] Artifact Instance of 'PubDependencies' is not required, skipping update. [ +47 ms] Using /home/jjangga/snap/flutter/common/flutter/.pub-cache for the pub cache. [ ] executing: /home/jjangga/snap/flutter/common/flutter/bin/cache/dart-sdk/bin/pub run build_runner build --verbose [INFO] Entrypoint:Generating build script... [INFO] Entrypoint:Generating build script completed, took 540ms [INFO] BuildDefinition:Initializing inputs [INFO] BuildDefinition:Reading cached asset graph... [INFO] BuildDefinition:Reading cached asset graph completed, took 96ms [INFO] BuildDefinition:Checking for updates since last build... [INFO] BuildDefinition:Checking for updates since last build completed, took 931ms [INFO] Build:Running build... [INFO] Build:Running build completed, took 25ms [INFO] Build:Caching finalized dependency graph... [INFO] Build:Caching finalized dependency graph completed, took 86ms [SEVERE] artemis:artemis on lib/$lib$ (cached): Two classes were generated with the same name `ClassName(name:r'Post')` but with different selection set. Class A ClassDefinition(name:ClassName(name:r'Post'), properties:[ClassProperty(type:TypeName(name:r'String'), name:ClassPropertyName(name:r'__typename'), annotations:[r'''JsonKey(name: '__typename')'''], isResolveType:true), ClassProperty(type:DartTypeName(name:r'String', isNonNull:true), name:ClassPropertyName(name:r'id'), isResolveType:false), ClassProperty(type:DartTypeName(name:r'String', isNonNull:true), name:ClassPropertyName(name:r'title'), isResolveType:false)], factoryPossibilities:{}, typeNameField:ClassPropertyName(name:r'__typename'), isInput:false) Class B ClassDefinition(name:ClassName(name:r'Post'), properties:[ClassProperty(type:TypeName(name:r'String'), name:ClassPropertyName(name:r'__typename'), annotations:[r'''JsonKey(name: '__typename')'''], isResolveType:true), ClassProperty(type:DartTypeName(name:r'String', isNonNull:true), name:ClassPropertyName(name:r'id'), isResolveType:false), ClassProperty(type:DartTypeName(name:r'String', isNonNull:true), name:ClassPropertyName(name:r'content'), isResolveType:false)], factoryPossibilities:{}, typeNameField:ClassPropertyName(name:r'__typename'), isInput:false) package:artemis/generator.dart 75:7 generateLibrary. package:artemis/generator/helpers.dart 110:43 _mergeDuplicatesBy.. dart:collection MapMixin.update package:artemis/generator/helpers.dart 110:12 _mergeDuplicatesBy. dart:core List.forEach package:artemis/generator/helpers.dart 108:8 _mergeDuplicatesBy package:artemis/generator/helpers.dart 122:7 ExtensionsOnIterable.mergeDuplicatesBy package:artemis/generator.dart 73:19 generateLibrary package:artemis/builder.dart 180:29 GraphQLQueryBuilder.build [SEVERE] Build: Failed after 165ms [+4352 ms] "flutter run" took 4,544ms. [ +5 ms] pub finished with exit code 1 [ +1 ms] #0 throwToolExit (package:flutter_tools/src/base/common.dart:10:3) #1 _DefaultPub.interactively (package:flutter_tools/src/dart/pub.dart:391:7) #2 PackagesForwardCommand.runCommand (package:flutter_tools/src/commands/packages.dart:247:5) #3 FlutterCommand.run. (package:flutter_tools/src/runner/flutter_command.dart:1125:27) #4 AppContext.run. (package:flutter_tools/src/base/context.dart:150:19) #5 CommandRunner.runCommand (package:args/command_runner.dart:209:13) #6 FlutterCommandRunner.runCommand. (package:flutter_tools/src/runner/flutter_command_runner.dart:288:9) #7 AppContext.run. (package:flutter_tools/src/base/context.dart:150:19) #8 FlutterCommandRunner.runCommand (package:flutter_tools/src/runner/flutter_command_runner.dart:236:5) #9 run.. (package:flutter_tools/runner.dart:62:9) #10 AppContext.run. (package:flutter_tools/src/base/context.dart:150:19) #11 main (package:flutter_tools/executable.dart:92:3) [ +202 ms] ensureAnalyticsSent: 200ms [ +7 ms] Running shutdown hooks [ +1 ms] Shutdown hooks complete [ +2 ms] exiting with code 1 ```
GraphQL schema: ```graphql # If possible, please paste your GraphQL schema file, # or a minimum reproducible schema of the bug. type Query { node( """A globally unique id""" id: ID! ): Node """ fetch data from the table: "post" """ postConnection( after: String before: String """distinct select on columns""" distinctOn: [PostSelectColumn!] first: Int last: Int """sort the rows by one or more columns""" orderBy: [PostOrderBy!] """filter the rows returned""" where: PostBoolExp ): PostConnection! ping: String! } """mutation root""" type Mutation { """ delete data from the table: "post" """ deletePost( """filter the rows which have to be deleted""" where: PostBoolExp! ): PostMutationResponse """ delete single row from the table: "post" """ deletePostByPk(uid: Uuid!): Post """ insert data into the table: "post" """ insertPost( """the rows to be inserted""" objects: [PostInsertInput!]! """on conflict condition""" onConflict: PostOnConflict ): PostMutationResponse """ insert a single row into the table: "post" """ insertPostOne( """the row to be inserted""" object: PostInsertInput! """on conflict condition""" onConflict: PostOnConflict ): Post """ update data of the table: "post" """ updatePost( """sets the columns of the filtered rows to the given values""" _set: PostSetInput """filter the rows which have to be updated""" where: PostBoolExp! ): PostMutationResponse """ update single row of the table: "post" """ updatePostByPk( """sets the columns of the filtered rows to the given values""" _set: PostSetInput pkColumns: PostPkColumnsInput! ): Post } type Subscription { node( """A globally unique id""" id: ID! ): Node """ fetch data from the table: "post" """ postConnection( after: String before: String """distinct select on columns""" distinctOn: [PostSelectColumn!] first: Int last: Int """sort the rows by one or more columns""" orderBy: [PostOrderBy!] """filter the rows returned""" where: PostBoolExp ): PostConnection! } """An object with globally unique ID""" interface Node { """A globally unique identifier""" id: ID! } type PageInfo { endCursor: String! hasNextPage: Boolean! hasPreviousPage: Boolean! startCursor: String! } """ Boolean expression to compare columns of type "String". All fields are combined with logical 'AND'. """ input StringComparisonExp { _eq: String _gt: String _gte: String """does the column match the given case-insensitive pattern""" _ilike: String _in: [String!] """ does the column match the given POSIX regular expression, case insensitive """ _iregex: String _isNull: Boolean """does the column match the given pattern""" _like: String _lt: String _lte: String _neq: String """does the column NOT match the given case-insensitive pattern""" _nilike: String _nin: [String!] """ does the column NOT match the given POSIX regular expression, case insensitive """ _niregex: String """does the column NOT match the given pattern""" _nlike: String """ does the column NOT match the given POSIX regular expression, case sensitive """ _nregex: String """does the column NOT match the given SQL regular expression""" _nsimilar: String """ does the column match the given POSIX regular expression, case sensitive """ _regex: String """does the column match the given SQL regular expression""" _similar: String } """column ordering options""" enum OrderBy { """in ascending order, nulls last""" asc """in ascending order, nulls first""" ascNullsFirst """in ascending order, nulls last""" ascNullsLast """in descending order, nulls first""" desc """in descending order, nulls first""" descNullsFirst """in descending order, nulls last""" descNullsLast } """ columns and relationships of "post" """ type Post implements Node { content: String! createdAt: Timestamptz! id: ID! title: String! uid: Uuid! updatedAt: Timestamptz! } """ A Relay connection object on "post" """ type PostConnection { edges: [PostEdge!]! pageInfo: PageInfo! } type PostEdge { cursor: String! node: Post! } """ Boolean expression to filter rows from the table "post". All fields are combined with a logical 'AND'. """ input PostBoolExp { _and: [PostBoolExp!] _not: PostBoolExp _or: [PostBoolExp!] content: StringComparisonExp createdAt: TimestamptzComparisonExp title: StringComparisonExp uid: UuidComparisonExp updatedAt: TimestamptzComparisonExp } """ unique or primary key constraints on table "post" """ enum PostConstraint { """unique or primary key constraint""" postPkey } """ input type for inserting data into table "post" """ input PostInsertInput { content: String createdAt: Timestamptz title: String uid: Uuid updatedAt: Timestamptz } """ response of any mutation on the table "post" """ type PostMutationResponse { """number of rows affected by the mutation""" affectedRows: Int! """data from the rows affected by the mutation""" returning: [Post!]! } """ on conflict condition type for table "post" """ input PostOnConflict { constraint: PostConstraint! updateColumns: [PostUpdateColumn!]! = [] where: PostBoolExp } """Ordering options when selecting data from "post".""" input PostOrderBy { content: OrderBy createdAt: OrderBy title: OrderBy uid: OrderBy updatedAt: OrderBy } """primary key columns input for table: post""" input PostPkColumnsInput { uid: Uuid! } """ select columns of table "post" """ enum PostSelectColumn { """column name""" content """column name""" createdAt """column name""" title """column name""" uid """column name""" updatedAt } """ input type for updating data in table "post" """ input PostSetInput { content: String createdAt: Timestamptz title: String uid: Uuid updatedAt: Timestamptz } """ update columns of table "post" """ enum PostUpdateColumn { """column name""" content """column name""" createdAt """column name""" title """column name""" uid """column name""" updatedAt } scalar Timestamptz """ Boolean expression to compare columns of type "timestamptz". All fields are combined with logical 'AND'. """ input TimestamptzComparisonExp { _eq: Timestamptz _gt: Timestamptz _gte: Timestamptz _in: [Timestamptz!] _isNull: Boolean _lt: Timestamptz _lte: Timestamptz _neq: Timestamptz _nin: [Timestamptz!] } scalar Uuid """ Boolean expression to compare columns of type "uuid". All fields are combined with logical 'AND'. """ input UuidComparisonExp { _eq: Uuid _gt: Uuid _gte: Uuid _in: [Uuid!] _isNull: Boolean _lt: Uuid _lte: Uuid _neq: Uuid _nin: [Uuid!] } ```
GraphQL query: ```graphql # If possible, please paste your GraphQL query file, # or a minimum reproducible query of the bug. mutation insertPostOne($object: PostInsertInput!) { insertPostOne(object: $object) { __typename id title } } mutation deletePostByPk($uid: Uuid!) { deletePostByPk(uid: $uid) { __typename id content } } ```
vasilich6107 commented 2 years ago

The naming scheme simple does not handle this properly. Use pathedWithFields