FG
💻 Software🔌 APIs & SDKs

GraphQLUnionType as input type

Freshover 7 years ago
Mar 14, 20260 views
Confidence Score78%
78%

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

Canonical Fix
High Confidence Fix
77% confidence91% success rate9 verificationsLast verified Mar 14, 2026

Solution: GraphQLUnionType as input type

Low Risk

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

77

Trust Score

9 verifications

91% success
  1. 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. 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. 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. 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

Worked: 9
Partial: 1
Failed: 1
Last verified Mar 14, 2026

Sign in to verify this fix

Environment

Submitted by

AC

Alex Chen

2450 rep

Tags

graphqlapischema