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

[Artemis 6.0.0] Two classes were generated with the same name DocumentDataType! -- which is an enum... #99

Closed
LasseRosenow opened this issue Mar 2, 2020 · 22 comments
Labels
bug Something isn't working

Comments

@LasseRosenow
Copy link
Contributor

Error:

Two classes were generated with the same name `DocumentDataType`!
You may want to:
- Make queries_glob stricter, to gather less .graphql files on a single output
- Use alias on one of the places a field of type `DocumentDataType` is requested
- Change naming_scheme to `pathedWithFields` to avoid duplication

Queries:

query moduleDataDocuments($moduleId: String!) {
  moduleDataDocuments(moduleId: $moduleId) {
    id
    type
    date
    title
    description
    feedback {
      required
      sent
    }
  }
}

query moduleDataDocumentsData($id: String! $moduleId: String!) {
  moduleDataDocumentsData(id: $id moduleId: $moduleId) {
    type
    data
  }
}

DocumentDataType gql schema:

enum DocumentDataType {
  PDF
  IMAGE
}

build.yaml:

targets:
  $default:
    sources:
      - lib/**
      - graphql/**
    builders:
      artemis:
        options:
          schema_mapping:
            - schema: graphql/schema.graphql
              queries_glob: graphql/**.query.graphql
              output: lib/graphql/graphql_api.dart
              naming_scheme: pathedWithFields

I use Artemis 6.0

Why do I get this error? Shouldn't Enums always be the same? Meaning that you can just use the same enum class on both queries?

Changing naming_scheme to pathedWithFields makes no difference.

@comigor comigor added the bug Something isn't working label Mar 2, 2020
@comigor
Copy link
Owner

comigor commented Mar 2, 2020

Yes, from 6.0+ (beta) Enums should always be the same!

I'll try to use your example to fix this issue!

@LasseRosenow
Copy link
Contributor Author

Thank you. To make it a bit more easy for you, here is my complete schema.

schema.graphql
type BaseSchoolEntity {
  id: String!
  name: String!
  city: String!
  theme: SchoolTheme!
  authRequired: Boolean!
}

type DocumentDataEntity {
  type: DocumentDataType!
  data: String!
}

# Document data type
enum DocumentDataType {
  PDF
  IMAGE
}

type DocumentEntity implements ModuleData {
  _type: String!
  title: String!
  description: String!
  date: String!
  type: DocumentDataType!
  id: String!
  feedback: DocumentFeedbackEntity!
}

type DocumentFeedbackEntity {
  required: Boolean!
  sent: Boolean!
  fields: [String!]!
}

type EntryTimeEntity {
  lesson: String!
  length: Int!
}

type ExamEntryEntity implements ModuleData {
  _type: String!
  id: String!
  date: String!
  sClass: String!
  time: EntryTimeEntity!
  subject: String!
  teacher: String!
  comment: String!
}

interface ModuleData {
  _type: String!
}

type ModuleDataEntity implements ModuleData {
  _type: String!
}

type Mutation {
  sickReport(body: sickReport!): SickReportEntity!
}

type PdfDataEntity {
  pdf: String!
}

type Query {
  school: SchoolEntity
  schools: [BaseSchoolEntity!]
  moduleDataSubst(moduleId: String!): [SubstitutionPlanEntity!]
  moduleDataExams(moduleId: String!): [ExamEntryEntity!]
  moduleDataDocuments(moduleId: String!): [DocumentEntity!]
  moduleDataDocumentsData(id: String!, moduleId: String!): DocumentDataEntity!
  pdfData(moduleId: String!): PdfDataEntity!
}

type SchoolEntity {
  id: String!
  name: String!
  city: String!
  theme: SchoolTheme!
  authRequired: Boolean!
  website: String!
  image: String!
  hidden: Boolean!
  codeOfConduct: [String!]!
  features: [SchoolFeatureEntity!]!
  modules: [SchoolModuleEntity!]!
  substData: [[SubstitutionPlanEntity!]!]!
}

type SchoolFeatureEntity {
  type: SchoolInformationFeatureType!
}

# School information feature type
enum SchoolInformationFeatureType {
  SICK_REPORT
}

# School module category
enum SchoolModuleCategory {
  SUBST
  EXAMS
  CAFETERIA
  NEWS
  DOCUMENTS
  OTHER
}

type SchoolModuleEntity {
  dataType: SchoolModuleType!
  id: String!
  category: SchoolModuleCategory!
  suffix: String!
}

# School module type
enum SchoolModuleType {
  SUBST
  EXAMS
  NEWS
  CAFETERIA
  PDF
  DOCUMENTS
}

# School theme
enum SchoolTheme {
  RED
  PINK
  PURPLE
  DEEP_PURPLE
  INDIGO
  BLUE
  LIGHT_BLUE
  CYAN
  TEAL
  GREEN
  LIGHT_GREEN
  AMBER
  ORANGE
  DEEP_ORANGE
  BROWN
  GREY
  BLUE_GREY
}

input sickReport {
  name: String!
  sClass: String!
  message: String!
  attested: Boolean!
  duration: sickReportDuration!
  specialEvent: String!
}

input sickReportDuration {
  start: String!
  end: String!
}

type SickReportDurationEntity {
  start: String!
  end: String!
}

type SickReportEntity {
  name: String!
  sClass: String!
  message: String!
  attested: Boolean!
  duration: SickReportDurationEntity!
  specialEvent: String!
}

# Subst entry type
enum SubstEntryType {
  EVA
  SUBST
  CANCELLED
  EXAM
  NORMAL
  SHIFTED_TO
  INSTEAD_OF
  SPECIAL
  BREAK_SUPERVISORY
  CUSTOM
}

type SubstitutionEntryAdditionalDataEntity {
  taskBy: [String!]!
  postponed: [SubstitutionEntryAdditionalDataTimeEntity!]!
  insteadOf: [SubstitutionEntryAdditionalDataTimeEntity!]!
  customType: String!
}

type SubstitutionEntryAdditionalDataTimeEntity {
  date: String!
  time: EntryTimeEntity!
}

type SubstitutionEntryEntity {
  date: String!
  sClass: String!
  room: String!
  comment: String!
  subject: String!
  newSubject: String!
  missingTeacher: String!
  teacher: String!
  time: EntryTimeEntity!
  type: SubstEntryType!
  additionalData: SubstitutionEntryAdditionalDataEntity!
}

type SubstitutionPlanEntity implements ModuleData {
  _type: String!
  date: String!
  entries: [SubstitutionEntryEntity!]!
  messages: [String!]!
}



@comigor
Copy link
Owner

comigor commented Mar 3, 2020

This helps a lot, thanks!

@vasilich6107
Copy link
Collaborator

vasilich6107 commented Mar 4, 2020

Hi @lazylazyllama - I can suggest you a temp fix, As far as I have a lot of work at the beginning of the project
It filters the duplicates at the last point. So there will be no duplicates at all)

artemis:
    git:
      url: https://github.com/comigor/artemis.git
      ref: ditrty/dedup-fix

I'll try to find a time for a better solution on the next week.

@comigor
Copy link
Owner

comigor commented Mar 4, 2020

Another way to circumvent this issue is temporarily have only one query on each file, but each of the generated files would still have the same enum.

@vasilich6107
Copy link
Collaborator

vasilich6107 commented Mar 4, 2020

Take a note that the @comigor’s solution could lead the entities import mess. Nevertheless it’s also valid) Who knows what surprises are hidden behind my solution...

@comigor
Copy link
Owner

comigor commented Mar 4, 2020

That should not in any terms be considered a solution, but just a way to temporarily make things work 😂

I'd like to discuss better how to gracefully generate the canonical classes (enums, input objects and fragments) in a non-duplicated and shareable way. I'll start a RFC taking in account the ideas proposed by @vasilich6107 later.

@LasseRosenow
Copy link
Contributor Author

Thank you a lot for your ideas how to fix it temporarily. I really appreciate that.

But it's all fine. I'm not in a rush or something. I have a lot of other things to do. So I'm totally fine if it will be fixed in the upcoming weeks.

:)

@SwannLV
Copy link

SwannLV commented Mar 18, 2020

Hi, just to say that I am encountering the same issue. Thank you very much :)

@grihlo
Copy link

grihlo commented Mar 30, 2020

Same here! Thank you for your work, it makes using GraphQL such a pleasure! 🚀

@vasilich6107
Copy link
Collaborator

Created new branch from latest beta release with dedup fix - temp/dedup-fix-on-beta

@vasilich6107
Copy link
Collaborator

@comigor
Hi. I have some time to work on Artemis next week and I would like to address this issue.

I propose the next approach - generate all canonical(enums, fragments, inputs) types which referred from the queries to the separate file. So on the step of generating the query types we will generate only with query dependent names and refer to the canonical ones through the import of canonical file.

@comigor
Copy link
Owner

comigor commented May 4, 2020

Yes, that's the way I'm thinking of doing: having a top-level configuration of schema and canonical pathes, somewhat like this:

targets:
  $default:
    builders:
      artemis:
        options:
          schema_mapping: # schema_mapping now becomes the global configuration
            - schema: lib/my_graphql_schema.graphql # each mapping will refer to a single schema
              canonical_output: lib/canonical_types.dart # with a canonical file output (enums, fragments, inputs)
              fragments_glob: lib/fragments/**.fragment.graphql
              scalar_mapping: # scalar mapping also refer to the schema, so they're configured here
                - custom_parser_import: package:my_package/coercers.dart
                  graphql_type: BigDecimal
                  dart_type:
                    name: Decimal
                    imports:
                      - package:decimal/decimal.dart
              queries_mapping: # and we now have a queries_mapping for this same schema as well
                - query: lib/**.graphql # (actually a glob)
                  output: lib/api.dart

@onemanstartup
Copy link

I'm trying last beta and I have this error when I have multiple queries or mutations in one file. If create one file for each query or mutation it's working fine. Does it matter? It's not supported?

@comigor
Copy link
Owner

comigor commented May 4, 2020

@onemanstartup It can be that both queries refer to the same GraphQL type and them both would generate Dart classes with the same name, which's considered an error, because each one of them could have different set of fields.

@vasilich6107
Copy link
Collaborator

vasilich6107 commented May 5, 2020

@comigor
I'll split the implementation on two parts.

  • first PR I'll fix deduplication
  • second PR I'll implement new yaml syntax

I am going to implement the fix for duplication only for pathedWithFields naming scheme

@vasilich6107
Copy link
Collaborator

Can we have additional output: lib/models/graphql config option(at the same level as canonical_output) to specify common folder for all outputs?

Example: if developer do not want to bother with juggling the output between folders he can specify a single output folder where all the generated data will be stored?

@vasilich6107
Copy link
Collaborator

I would also like to discuss a drop of naming_scheme support and make pathedWithFields a default one.

As far as we saw previously simple and pathedWithTypes will cause duplications in a long run.

What do you think?

@comigor
Copy link
Owner

comigor commented May 5, 2020

@vasilich6107 I'm all-in with all of those!

Only about the output field, maybe I would call it something like relative_to? (as it's a optional output folder configuration, and the query outputs will be relative to it?)

@vasilich6107
Copy link
Collaborator

Makes sense.
I will leave output/relative_to to think about when I get to the yaml adjustments.

@vasilich6107
Copy link
Collaborator

@lazylazyllama
Could you check the 6.0.10-beta.1

@LasseRosenow
Copy link
Contributor Author

It seems to be working :)
Thank you very much!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants