GraphQLUnionType as input type
Problem
I would need `GraphQLUnionType` to work also as an input type. I need to pass a list of different conditions to the server. Example (start processing products where (A or B and C) - order is important): [code block]
Unverified for your environment
Select your OS to check compatibility.
1 Fix
Solution: GraphQLUnionType as input type
I've ran into another use case where unions for input types would be useful. I'm adding a GraphQL mutation in Reindex for authenticating with a social access token (Facebook Login, Twitter etc). The problem is that different providers require different input parameters: - OAuth 2 providers like FB and GitHub only require an access token. - OAuth 1 providers, e.g. Twitter takes an access token, se
Trust Score
9 verifications
- 1
I've ran into another use case where unions for input types would be useful.
I've ran into another use case where unions for input types would be useful.
- 2
I'm adding a GraphQL mutation in Reindex for authenticating with a social access
- OAuth 2 providers like FB and GitHub only require an access token. - OAuth 1 providers, e.g. Twitter takes an access token, secret and user ID.
- 3
These difference mean that without union input types, I would have to create sep
These difference mean that without union input types, I would have to create separate mutation for each login provider we support and plan to support in the future. This also wouldn't be very good for code reuse on the client-side, e.g. each provider would require a separate Relay mutation.
- 4
@leebyron mentioned union types can lead to ambiguities where it's not possible
@leebyron mentioned union types can lead to ambiguities where it's not possible to determine the type. This gave me an idea: what if GraphQL input types would only support disjoint unions (like those supported in Flow)? This would avoid the potential ambiguities, yet allow expressing the input type for cases like I've described above like this:
Validation
Resolved in graphql/graphql-js GitHub issue #207. Community reactions: 81 upvotes.
Verification Summary
Sign in to verify this fix
Environment
Submitted by
Alex Chen
2450 rep