Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when getting enum value => Argument 'input' has invalid value #240

Open
Benkhouds opened this issue Dec 17, 2022 · 7 comments
Open

Comments

@Benkhouds
Copy link

I'm using the conventions library as a mock server, and I couldn't figure out how to map values, here's a query example
`
test(input: {
accountName: "Compte principal"
name: "test"
companyType: Association // this is an enum as you can see not a string value
businessActivity: AdministrativeServices // same
monthlyPaymentVolume: Between10000And50000 // same
email: "[email protected]"
language: "FR"

}) {
... onSuccessPayload {
  __typename
   status
}
... on BadRequestRejection {
  __typename
  message
}
... on ValidationRejection {
  __typename
  message
}
... on ForbiddenRejection {
  __typename
  message
}

}
}
`

And i'm using a I'm only using a requestHandler, so when i get a request I pass it to requestHandler.ProcessRequestAsync.
I have a workaround to pass the enum as string value and then parse it, but i'd rather not.
here's the full error I got:
In field 'businessActivity': [Expected type 'BusinessActivity', found AdministrativeServices.] In field 'monthlyPaymentVolume': [Expected type 'MonthlyPaymentVolume', found Between10000And50000.]","locations":[{"line":2,"column":31}],"extensions":{"code":"FIELD_RESOLUTION","codes":["FIELD_RESOLUTION","ARGUMENTS_OF_CORRECT_TYPE_ERROR"]}}]

@Benkhouds
Copy link
Author

I think i found the issue but still don't know how to fix it. When i describe my schema here's the screenshot for my enum
image

As you can see it changed it to constant case, but my enum is PascalCase

@tlil
Copy link
Collaborator

tlil commented Dec 18, 2022

I think i found the issue but still don't know how to fix it. When i describe my schema here's the screenshot for my enum

image

As you can see it changed it to constant case, but my enum is PascalCase

This is by design as enum values are all caps by convention following the recommendations in the GraphQL spec:

https://spec.graphql.org/June2018/#sec-Enum-Value

image

@Benkhouds
Copy link
Author

I'm not saying that this is not the convention, But for my case, the enums are already there (i'm mocking a real third party graphql server) and they are PascalCase. It would be really great if you can provide me with a solution to convert the values to PascalCase, i'm out of ideas :( Thanks

@tlil
Copy link
Collaborator

tlil commented Dec 18, 2022

I'm not saying that this is not the convention, But for my case, the enums are already there (i'm mocking a real third party graphql server) and they are PascalCase. It would be really great if you can provide me with a solution to convert the values to PascalCase, i'm out of ideas :( Thanks

You can use the [Name(...)] attribute on each enum value:

CleanShot 2022-12-18 at 19 38 52

See the Enum_Members_Have_Correct_Names unit test (above, with the last value as an addition) :-)

@Benkhouds
Copy link
Author

hoped for a more generic solution to apply for all enums but this will do. Thanks a lot

@tlil
Copy link
Collaborator

tlil commented Dec 18, 2022

hoped for a more generic solution to apply for all enums but this will do. Thanks a lot

See answer in #241 – adding your own attribute implementing MetaDataAttributeBase and IDefaultAttribute gives you a generic solution

@Benkhouds
Copy link
Author

Benkhouds commented Feb 5, 2023

So, after trying what you said previously, nothing really worked but i closed the issue because i went with sending the enum as a string and parsing it later (which i really don't like). And now, since I'm back working at this, I tried creating a class implementing the both MetaDataAttributeBase and IDefaultAttribute, to override MapEnumMember, but it seems that it's executed before the MapEnumMember of the NameAttribute. if the NameAttribute class had virtual methods I could override its implementation but that's not the case. Is it a choice you made that only Constant Case enums are supported unless specifying explicitly on each enum member (which is a pain to be honest since we have hundreds of enums). I propose 3 simple solutions :

  1. Adding EnumCase as a configuration and updating the MapEnumMember to behave accordingly
  2. making the NameNormalizer field public, so it can be replaced
  3. inside DiscoverDefaultAttributes, if there's a default attribute that's inheriting from one of the types inside _defaultAttributes, remove parent from list
    If you agree on any of the above, I can make a pr to do the change

@Benkhouds Benkhouds reopened this Feb 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants