dapalex / py-graphql-mapper

A python library for generating GraphQL queries and mutations using plain python objects, no hardcoded strings.Any questions or issues, please report here https://github.com/dapalex/py-graphql-mapper/issues
MIT License
20 stars 2 forks source link

export_gql_source Error for non-recursive queries #25

Closed danieledwardgeorgehitchcock closed 1 year ago

danieledwardgeorgehitchcock commented 1 year ago

As mentioned in #24 I am using this tool to create a python module (details in previous issue)

When I come to perform the version query which returns a string at the root, I get the following error when using export_gql_source:

ERROR:root:'str' object has no attribute 'log_progress'
Traceback (most recent call last):
  File "C:\Users\danie\AppData\Local\hatch\env\virtual\ripple-energy\jAAfYL9X\ripple-energy\lib\site-packages\pygqlmap\components.py", line 124, in export_gql_source
    self.type.log_progress = self.log_progress
AttributeError: 'str' object has no attribute 'log_progress'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\danie\Documents\Projects New\ripple-energy\src\ripple_energy\test.py", line 7, in <module>
    data1 = version()
  File "C:\Users\danie\Documents\Projects New\ripple-energy\src\ripple_energy\ripple_energy.py", line 101, in version
    print(query.export_gql_source)
  File "C:\Users\danie\AppData\Local\hatch\env\virtual\ripple-energy\jAAfYL9X\ripple-energy\lib\site-packages\pygqlmap\components.py", line 140, in export_gql_source
    raise handle_recursive_ex(ex, 'Issue during export of ' + self.name)
pygqlmap.helper.CustomException: Issue during export of Version - 'str' object has no attribute 'log_progress'
dapalex commented 1 year ago

Hi,

I created a branch from this issue and pushed the fix.

I downloaded your project and tested your query, also I noticed another bug in the generation of a list of custom scalar type list_date[Date], that has been fixed too.

Soon I will publish a new version of the library with these fixes, in the meanwhile you could use the branch.

About the previous issue, since there were not bugs I will convert it in a discussion.

Thanks

danieledwardgeorgehitchcock commented 1 year ago

Confirmed as working in 1.1.2 thanks!

Regarding the list_date issue, will I need to re-run the schema generation?

danieledwardgeorgehitchcock commented 1 year ago

Is it also possible to make one of the fields in the output class as Optional?

I have tried importing the Optional typing and adding it to the field as follows, but it doesn't seem to work:

insightsChartData: Optional[DEFTF_InsightsChartDataOutput_Field]
danieledwardgeorgehitchcock commented 1 year ago

Also, do you support fragments like this:

query GetMember {
  member {
    ...MemberFragment
    __typename
  }
}

fragment MemberFragment on Member {
  id
  isBusiness
  businessName
  businessRegistrationNumber
  registrationCompleted
  fullyChargedPreregistered
  investmentTotal
  billSavingsAcrossAllProjects
  expectedGenerationAnnualTotal
  ownershipPercentageTotal
  capacityOwnedTotal
  hasReservedInActiveCoop
  dateOfReservationInActiveCoop
  dateOfLastSharePurchase
  hasBoughtSharesInActiveCoop
  hasBoughtSharesInGraigFatha
  hasBoughtSharesInKirkHill
  hasBoughtSharesInMultipleCoops
  isSuppliedByOctopusEnergy
  memberDocument {
    id
    file
    documentUrl
    __typename
  }
  address {
    id
    line1
    line2
    town
    postcode
    manuallyEntered
    __typename
  }
  badges {
    id
    name
    code
    description
    imageUrl
    __typename
  }
  beneficiaries {
    id
    nominatedPerson
    email
    phone
    line1
    line2
    town
    postcode
    __typename
  }
  invoices {
    id
    category
    quote {
      id
      arrangementFee
      billSavingsAnnualEstimate
      capacity
      costTotal
      costTotalLocale
      currency {
        code
        precision
        symbol
        __typename
      }
      ownershipMultiplier
      paymentTotal
      paymentTotalLocale
      electricityConsumptionAnnual
      __typename
    }
    __typename
  }
  memberships {
    id
    capacity
    reservedCapacity
    createdAt
    expectedGenerationAnnualTotal
    ownershipPercentage
    investmentTotal
    billSavingsForProjectLifespan
    billSavingsFirstYearEstimateTotal
    firstOwnershipPurchaseDate
    coop {
      ...CoopFragment
      __typename
    }
    lightShowImage
    __typename
  }
  currentMemberSupplier {
    id
    accountIdentifier
    supplier {
      id
      name
      logoUrl
      __typename
    }
    __typename
  }
  waitingListPlaces {
    ...WaitingListPlaceFragment
    __typename
  }
  __typename
}

fragment CoopFragment on Coop {
  id
  name
  code
  wattageSku
  status
  active
  description
  maxGenerationPerMember
  minGenerationPerMember
  percentageFunded
  publicCloseDate
  estimatedBillSavingsPerWattHour
  firstYearEstimatedBillSavingsPerWattHour
  costTotalPerWattHour
  isAvailableForLocalPurchase
  localPurchasePostcodes
  currency {
    id
    code
    precision
    symbol
    __typename
  }
  generationfarm {
    id
    name
    latitude
    longitude
    isLocationConfirmed
    startDate
    operationalStatus
    generationType
    capacity
    capacityToGenerationFactor
    lightShowImage
    currency {
      id
      code
      precision
      symbol
      __typename
    }
    __typename
  }
  documents {
    documentUrl
    version
    document {
      id
      name
      category
      subcategory
      description
      updatedAt
      documentTags {
        id
        name
        __typename
      }
      __typename
    }
    __typename
  }
  __typename
}

fragment WaitingListPlaceFragment on MemberCoopWaitingListPlace {
  id
  generationRequestedKwh
  waitingList {
    ...WaitingListFragment
    __typename
  }
  __typename
}

fragment WaitingListFragment on CoopWaitingList {
  id
  coop {
    id
    name
    __typename
  }
  __typename
}
dapalex commented 1 year ago

Hi,

Regarding list[Date] yes, you need to regenerate the code. Note that I added also a feature for the dynamic visibility of fields, the usage of * symbol.

About optional I suppose it is for unions in graphql. Interfaces, unions and fragments were something I was planning to do, but due to the effort needed and other ideas that came up for other projects I left it behind. It would need some analysis, design review, etc to implement it but I am quite confident it can be done.

If you are strongly interested I would let you close this issue and open a discussion for those.

Thanks