Can an @ArgType be created using a combination of union @Field?

Is there a way for me to define an input / argtype that could either be a ContactCreate or a ContactRead? I'm uncertain if it's feasible.

import { ContactCreate } from 'contact/ContactCreate'
import { ContactRead } from 'contact/ContactRead'
import { ArgsType, createUnionType, Field } from 'type-graphql'

const ContactObtainUnion = createUnionType({
  name: 'ContactObtain',
  types: () => [ContactCreate, ContactRead],
  resolveType: value => {
    if ('uuid' in value) {
      return ContactRead
    }
    return ContactCreate
  }
})

@ArgsType()
export class ContactObtain {
  @Field(() => ContactObtainUnion)
  contact: typeof ContactObtainUnion
}

Would it be possible to use a union of two distinct type objects as a @Field?

Answer №1

Currently, input unions are not supported in the GraphQL spec, meaning you are unable to utilize them in both @ArgsType and @InputType.

To gain further insights on this limitation, refer to the RFC and ongoing discussion on GitHub: https://github.com/graphql/graphql-spec/issues/627

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

NestJS Exporting: Establishing a connection for PostgreSQL multi tenancy

I have been working on implementing a multi tenancy architecture using postgres. The functionality is all in place within the tenant service, but now I need to import this connection into a different module called shops. Can anyone provide guidance on how ...

Error encountered in Typescript when attempting to invoke axios - the call lacks a suitable overload

When I make a call to axios, I include a config object like this: const req = { method, url, timeout: 300000, headers: { 'Content-Type': 'application/json' } } axios(req) An error in TypeScript is thrown stating that "No overload matc ...

Integrating @types/arcgis-js-api into an Angular 5 project

Incorporating arcgis-js-api types into my angular5 application has been a challenge. Whenever I attempt to import the types in multiple components, an uncaught reference error occurs: __esri is not defined. I made sure to include arcgis-js-api in the typ ...

Steps for combining a sequence of subsequent subscriptions in RxJS

In my approach, I followed the code below. this.service1.info .subscribe(a => this.service2.getDetails(a.id) .subscribe(b => { this.doStuff(b); }) ); Lately, it has come to my attention that we will be adding more steps that gradu ...

Tips for passing certain optional parameters while excluding others without resorting to undefined or empty values like ""

Is there a way to invoke the function while omitting certain optional parameters without resorting to undefined and empty strings? import { MouseEvent } from "react"; import { DialogType } from "editor-constants"; export interface Dial ...

Is there a way to automatically validate v-forms inside a v-data-table when the page loads?

In my data entry form, I have utilized a v-data-table with each column containing a v-form and v-text-field for direct value updates. My goal is to validate all fields upon page load to identify any incorrect data inputs. However, I am facing challenges in ...

Identify any missing periods and combine the years into a single range

I am working on restructuring year ranges with gaps and consolidating them. For example, converting [{start: 2002, end: 2020}, {start: 2020, end: null}] to {start: 2002, end: null} or [{2002, 2004},{2006, 2008}, {2008, null}] to [{2002-2004}, {2006-null}]. ...

Angular 2 encounters issues with *ngFor functionality

I am currently experiencing some difficulties while trying to use *ngFor to access an array of objects in Angular 2. When I define the array like this: employees=[ {name:'a',age:'25'}, {name:'b',age:&apo ...

What is the meaning of boolean true in a Firestore query using TypeScript?

Currently, I am facing an issue with querying Firestore in Angular 8 using AngularFire. While querying a string like module_version works perfectly fine as shown in the code snippet below, the problem arises when attempting to query a boolean field in Fire ...

Using Angular's setTimeout() function with an external lambda that includes a parameter

My goal is to tackle two issues at once: 1) using setTimeout( #action#, timeMillis) with #action# as a lambda 2) supplying the lambda with a parameter. The common method of setTimeout( ()=>{ #callback# }, timeMillis) works flawlessly when extracting () ...

Upgrading from Angular 4 to Angular 5 may result in the following error message: "Error TS2322: The type 'Promise<void | LineSideInspection>' is not compatible with the type 'Promise<LineSideInspection>'"

I recently updated my Angular project from version 4 to 5.0 and started encountering an error. The code for the entire project (in Angular 4) can be found on github at https://github.com/SudhirSahoo/IQS ERROR in src/app/lineside-inspection/lineside-inspec ...

Iterate over Observable data, add to an array, and showcase all outcomes from the array in typescript

Is there a way to iterate through the data I've subscribed to as an Observable, store it in an array, and then display the entire dataset from the array rather than just page by page? Currently, my code only shows data from each individual "page" but ...

Utilize multiple activated modules in Angular 2

Recently, I've been exploring the new features of Angular 2 final release, particularly the updated router functionality. An interesting example showcasing the router in action can be found at this link: http://plnkr.co/edit/mXSjnUtN7CM6ZqtOicE2?p=pr ...

Obtain the ViewContainerRef object from the Component

Looking to create nested components in Angular 4? This is the Chooser Component import {InputComponent} from './input/input.component' import {BlockComponent} from './block/block.component' export const FormChooser = { Block: Block ...

Error: The AppModule encountered a NullInjectorError with resolve in a R3InjectorError

I encountered a strange error in my Angular project that seems to be related to the App Module. The error message does not provide a specific location in the code where it occurred. The exact error is as follows: ERROR Error: Uncaught (in promise): NullInj ...

When utilizing Angular, the mat-datepicker is displayed underneath the modal, even after attempting to modify the z-index

I am encountering a problem with a mat-datepicker displaying below a modal in my Angular application. Here are the key details: Html: <div class="col-12"> <mat-form-field appearance="fill"> <mat-label>Start Date ...

Handling errors with JWT authentication in NestJS GraphQL

Utilizing express JWT with nest js and integrating it into a GraphQL gateway, I aim to handle token errors such as expiration or invalidity when making calls to GraphQL APIs. Below is the snippet of code where I implement express JWT in the main file of m ...

What is the best approach to develop a React Component Library adorned with Tailwind CSS and enable the main project to easily customize its theme settings?

Currently, I am in the process of developing an internal component library that utilizes Tailwind for styling. However, a question has arisen regarding how the consuming project can incorporate its own unique styles to these components. Although I have th ...

Dealing with observable errors in Angular 2 beta.12 and RxJS 5 beta.3

Greetings, Currently, I am working with Angular2 beta 12 within VS2015. Upon updating from rxjs version 5.0.0-beta.2 to beta.3, I started encountering several exceptions primarily related to promises. For instance: The property map is not present in th ...

What is the best way to utilize the characteristics found in the properties of a different type?

Consider the following scenario: type Individual = { name: string, age: number, nicknames: string[], } Now, I aim to generate a new type based on the types of the properties within the Individual type. The desired outcome is: type IndividualTypes = ...