graphql-platform icon indicating copy to clipboard operation
graphql-platform copied to clipboard

Validation of `OneOf` failing

Open atrauzzi opened this issue 2 years ago • 3 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

Product

Hot Chocolate

Describe the bug

I'm encountering a weird validation problem when trying to accept some structured input to a mutation.

It seems like when I write it out within the mutation, validation passes. If however I pass it in as the identical equivalent JSON structure, Hot Chocolate is failing validation with HC0016.

Steps to reproduce

Take a look at my repro repo, try the following graphql.

mutation SaveSetting(
  $iso639Code: String
  $organizationId: UUID!
  $purpose: String!
  $slot: String!
  $parameters: ParameterInput!
) {
  saveSetting(
    input: {
      iso639Code: $iso639Code
      organizationId: $organizationId
      purpose: $purpose
      slot: $slot
      parameters: $parameters
    }
  ) {
    setting {
      id
      slot
      iso639Code
      parameters {
        __typename
        ... on ColorParameters {
          red
          green
          blue
          alpha
        }
        ... on FileParameters {
          uri
        }
        ... on WebPaymentParameters {
          allowFeeCoverage
          coverFeesByDefault
          allowCurrencySelection
          defaultIso4217Code
          currencies {
            key
            value {
              iso4217Code
              steps {
                amountSmallestUnit
              }
            }
          }
        }
      }
    }
  }
}
{
  "organizationId":"9b33926e-8016-4b16-9e73-e8f2a410dd24",
  "purpose":"web-payment",
  "slot":"parameters",
  "parameters": {
    "webPayment": {
      "allowFeeCoverage":false,
      "coverFeesByDefault":false,
      "allowCurrencySelection":true,
      "defaultIso4217Code":"cad",
      "currencies": [
        {
          "key": "cad", 
          "value": {
            "iso4217Code": "cad",
            "steps": [
              {"amountSmallestUnit": 1200}
            ]
          }
        }
      ]
    }
  }
}

Relevant log output

{
  "errors": [
    {
      "message": "Variable `parameters` got an invalid value.",
      "locations": [
        {
          "line": 6,
          "column": 3
        }
      ],
      "extensions": {
        "code": "HC0016",
        "variable": "parameters"
      }
    }
  ]
}

Additional Context?

One thing that is worth calling out is that if I just hard-code the data into the query (instead of using parameter JSON), the mutation works. But in either scenario, both BCP and HC don't seem to report any errors and all type assist and client-side validation is satisfied. It's only once the JSON value hits the server that it seems to think that the data provided is bad.

This problem started happening after I added the relatively more complex WebPaymentParameters to my OneOf.

Version

13.7.0

atrauzzi avatar Nov 13 '23 23:11 atrauzzi

Thank you for the repo ... I will have a look at it.

michaelstaib avatar Nov 14 '23 09:11 michaelstaib

@michaelstaib - Just checking in, were you able to run my repro?

atrauzzi avatar Nov 17 '23 22:11 atrauzzi

@michaelstaib - So I might have stumbled on something while testing. It looks like if I change my dictionary from IDictionary to Dictionary, the validation passes... Any chance this potentially makes sense to you?

atrauzzi avatar Nov 23 '23 16:11 atrauzzi