Skip to content

[json-schema] Incorrect schema generated with responseSchema and oneOf #4880

Closed
@AzzouQ

Description

@AzzouQ

Issue workflow progress

Progress of the issue based on the Contributor Workflow

Make sure to fork this template and run yarn generate in the terminal.

Please make sure Mesh package versions under package.json matches yours.

  • 2. A failing test has been provided
  • 3. A local solution has been provided
  • 4. A pull request is pending review

Describe the bug

@graphql-mesh/json-schema doesn't handle oneOf (and probably allOf & anyOf) JSON Schema's instruction correctly.

For the following instructions:

"shouldBeStringOrNumber": {
  "oneOf": [
    { "type": "number" },
    { "type": "string" }
  ]
}

The generated output will look like:

type MyObject {
  shouldBeStringOrNumber: query_myObject_shouldBeStringOrNumber!
}

union query_myObject_shouldBeStringOrNumber = Float_container | String_container

type Float_container {
  Float: Float
}

type String_container {
  String: String
}

Which is not the desired behavior. shouldBeStringOrNumber should be String | Float while it became an object with either a prop String: String or a prop Float: Float

To Reproduce
Steps to reproduce the behavior:

See this github reproduction or this codebox

Expected behavior

type MyObject {
  shouldBeStringOrNumber: query_myObject_shouldBeStringOrNumber!
}

union query_myObject_shouldBeStringOrNumber = Float | String

Environment:

  • OS: MacOS
  • @graphql-mesh/cli: ^0.80.4
  • @graphql-mesh/graphql: ^0.32.4
  • @graphql-mesh/json-schema: ^0.35.38

Additional context

None

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions