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

[Feature Request] Missing support for unions #5

Open
jnv opened this issue Jan 14, 2022 · 1 comment
Open

[Feature Request] Missing support for unions #5

jnv opened this issue Jan 14, 2022 · 1 comment
Labels
enhancement New feature or request

Comments

@jnv
Copy link
Contributor

jnv commented Jan 14, 2022

Given a union structure in profile like this:

[ string! | number! ]

I recieve this exception on one-service start:

.../node_modules/@superfaceai/one-service/dist/schema.types.js:235
            throw new Error(`Variable type not implemented for: ${structure.kind}`);
                  ^

Error: Variable type not implemented for: UnionStructure
    at outputType (.../node_modules/@superfaceai/one-service/dist/schema.types.js:235:19)
    at outputType (.../node_modules/@superfaceai/one-service/dist/schema.types.js:231:46)
    at .../node_modules/@superfaceai/one-service/dist/schema.types.js:219:27
    at Array.forEach (<anonymous>)
    at outputType (.../node_modules/@superfaceai/one-service/dist/schema.types.js:217:89)
    at outputType (.../node_modules/@superfaceai/one-service/dist/schema.types.js:231:46)
    at generateStructureResultType (.../node_modules/@superfaceai/one-service/dist/schema.types.js:102:18)
    at generateUseCaseFieldConfig (.../node_modules/@superfaceai/one-service/dist/schema.types.js:60:24)
    at generateProfileTypes (.../node_modules/@superfaceai/one-service/dist/schema.types.js:28:36)
    at generate (.../node_modules/@superfaceai/one-service/dist/schema.js:41:91)

Profile example

usecase GetRoomsAvailability {
  input {
    arrivalDate! string!
    departureDate! string!

    "Room/apartment IDs"
    rooms! [string! | number!]
  }

  result [
    {
      date! string!
      availableQuantity! number!
      rooms! [string! | number!]
    }
  ]
}
@jnv jnv added the enhancement New feature or request label Jan 14, 2022
@freaz
Copy link
Member

freaz commented Jan 18, 2022

After some dive to unions in GraphQL, I don't see a way how to support them. Because GraphQL doesn't allow unions in input at all and for outputs it must be an object.

So only unions defined in Comlink as below would work.

model WeatherInformation {
  airTemperature
  atmosphericPressure
}

model WeatherDetailedInformation {
  airTemperature
  atmosphericPressure
  wind
  windGusts
  rain
}

model WeatherData WeatherInformation | WeatherDetailedInformation

Since the limitation in GraphQL is big, I wouldn't implement it. Also because the union in profile can be rewritten to single type.

Action item here is to document it in README as known limitation.


There is new specification and suggested as an alternative for unions for inputs. It is called OneOf Input Objects. Once implementation is merged, we should be able to use it to map Comlink Profile Unionsas OneOf Input Objects.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants