An error was triggered in Apollo GraphQL due to a custom GQL scalar type that includes a regular expression test function

When developing a GraphQL custom scalar in TypeScript, I am working on implementing the serialize/parseValue/parseLiteral functions. In order to match incoming values against a regex, I tried using

if (value.test(yearMonthDayRegex)) {}
as a condition, but encountered an Apollo runtime error:

TypeError: value.test is not a function
            at GraphQLScalarType.coerceType (/Users/mej/Documents/elastigraph/elastigraph/packages/core/src/lib/gqlScalarTypes.ts:30:20)
            at coerceInputValueImpl (/Users/mej/Documents/elastigraph/elastigraph/node_modules/.pnpm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f7908596879f869bb7c6c1d9c1d9c7">[email protected]</a>/node_modules/graphql/utilities/coerceInputValue.js:151:26)
            at coerceInputValueImpl (/Users/mej/Documents/elastigraph/elastigraph/node_modules/.pnpm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="6c0b1e0d1c041d002c5d5a425a425c">[email protected]</a>/node_modules/graphql/utilities/coerceInputValue.js:117:34)
            at coerceInputValueImpl (/Users/mej/Documents/elastigraph/elastigraph/node_modules/.pnpm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="294e5b485941584569181f071f0719">[email protected]</a>/node_modules/graphql/utilities/coerceInputValue.js:117:34)
            at coerceInputValue (/Users/mej/Documents/elastigraph/elastigraph/node_modules/.pnpm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="2b4c594a5b435a476b1a1d051d051b">[email protected]</a>/node_modules/graphql/utilities/coerceInputValue.js:32:10)
            at coerceVariableValues (/Users/mej/Documents/elastigraph/elastigraph/node_modules/.pnpm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="8aedf8ebfae2fbe6cabbbca4bca4ba">[email protected]</a>/node_modules/graphql/execution/values.js:132:69)
            at getVariableValues (/Users/mej/Documents/elastigraph/elastigraph/node_modules/.pnpm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c0a7b2a1b0a8b1ac80f1f6eef6eef0">[email protected]</a>/node_modules/graphql/execution/values.js:45:21)
            at buildExecutionContext (/Users/mej/Documents/elastigraph/elastigraph/node_modules/.pnpm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="33544152435b425f7302051d051d03">[email protected]</a>/node_modules/graphql/execution/execute.js:280:63)
            at execute (/Users/mej/Documents/elastigraph/elastigraph/node_modules/.pnpm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="9ff8edfeeff7eef3dfaea9b1a9b1af">[email protected]</a>/node_modules/graphql/execution/execute.js:116:22)
            at /Users/mej/Documents/elastigraph/elastigraph/node_modules/.pnpm/@<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d4b1baa2b1b8bba4ffb7bba6b194e7fae4fae2">[email protected]</a>/node_modules/@envelop/core/cjs/orchestrator.js:376:33

Does anyone know how to incorporate regex functionality into a custom scalar like this? Am I overlooking something basic about regex in TypeScript? The regex involved looks like this:

const yearMonthDayRegex = /^d{4}-(0?[1-9]|1[012])-(0?[1-9]|[12][0-9]|3[01])$/;
.

Answer №1

The information provided by @InSync is accurate. When testing regex patterns, it is done using regex.test("teststring") instead of teststring.test(regex).

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

using a regex pattern to locate values within a string of data that is separated by

I am working with comma separated data that looks like this: "go,godown,goup,go,ago,agon,aerugos,gone,going,good,goof,goaway,nogo,go" I need a regular expression that will match the word go only when it appears as a complete word, not as part of any othe ...

Encountering a bug in Angular 11 while fetching data from the backend to display on the screen - facing an issue with trying to access property 'values' of an undefined variable

I am currently working on retrieving data from the backend/api and attempting to display it using *ngFor. However, I am encountering the following errors: Cannot read property 'values' of undefined Below are the components, service codes, and ...

Each time the Angular Service is called, it undergoes a reset process

For my Angular web project, I have implemented an AuthenticationGuard and an AuthenticationService to manage security. These components are from a separate branch of the project that is functioning perfectly. This is how the process should occur: Go to ...

Mapping Selector Types in Ngrx

Here is the structure of my IStore: export interface IStore { plans: IPlanRedux; } The definition of IPlanRedux is as follows: export interface IPlanRedux { entities: { [key: string]: IPlan }; ids: Array<string>; } export interface IPla ...

trpc - Invoking a route from within its own code

After reviewing the information on this page, it appears that you can invoke another route on the server side by utilizing the const caller = route.createCaller({}) method. However, if the route is nested within itself, is it feasible to achieve this by ...

SQL Regular Expression function that mimics the functionality of the REGEX function in MySql

Currently, I am searching for a function that can perform similar tasks as the MySQL REGEX function in TSQL. Essentially, I want my Query to resemble the one below: SELECT * FROM Routing WHERE (@Message REGEX RouteRegex); For now, I do not prefer using C ...

Instructions on resolving the issue: The type 'string | ChatCompletionContentPart[] | null' cannot be assigned to type 'ReactNode'

I've been working on my first Saas App, similar to a ChatGPT, using NextJs with the OpenAI Api. Most of the development was based on a YouTube tutorial until I encountered two errors caused by an update in the OpenAI version. Despite trying various so ...

Transferring information via Segments in Ionic 3

I'm facing a challenge where I need to transfer a single ion-card from the "drafts" segment to the "sent" segment by simply clicking a button. However, I am unsure of how to achieve this task seamlessly. Check out this image for reference. ...

Assign the private members of the class to the arguments of the constructor

class Bar { #one #two #three #four #five #six #seven #eight #nine #ten #eleven #twelve #thirteen #fourteen #fifteen #sixteen constructor( one, two, three, four, five, six, seven, eight, ...

In Angular 9, there seems to be an issue with the initialization of @ContentChildren

My directive, named "VerticalTabsDirective," has the following properties- @ContentChildren(MatTabLink) contentChildren: QueryList<MatTabLink>; @Input() exlVerticalTabs In my component, I am utilizing this directive with a recursive ng-template in ...

Tips for refreshing the value of a dependency injection token

When using Angular dependency injection, you have the ability to inject a string, function, or object by using a token instead of a service class. To declare it in my module, I do this: providers: [{ provide: MyValueToken, useValue: 'my title value& ...

"In the realm of RxJS, there are two potent events that hold the power to

In my current situation, I encountered the following scenario: I have a service that makes Http calls to an API and requires access to user data to set the authentication header. Below is the function that returns the observable used in the template: get ...

Error: Attempting to access the 'EventEmitter' property of an undefined variable in a Node.js TypeScript environment

I have a Node.js application written in TypeScript. In my code, I am utilizing the 'EventEmitter' class to trigger a change in a variable's value. Here is the relevant snippet: import events from 'events'; public async updateSt ...

Assign a value to a date field in Aurelia

<input class="" type="date" id="Broken" value.bind="dateval"> The current value of dateval is 2021-04-08T10:05:19.988Z. Is there a way to set a default date for the date input field above? ...

Utilize the Lifecycle Interface within Angular 2 framework for enhanced application development

Can you explain the impact of this rule? "use-lifecycle-interface": true, ...

Using an object as an Input argument in GraphQL queries with Vue Apollo: What's the best approach?

I am looking to utilize the GraphQL API provided by the Saleor eCommerce platform to create a checkout object. After consulting the gql playground, I discovered that there is a mutation specifically for creating a checkout object, which requires a Checkou ...

Error: Unable to attach the "identity" property as the object does not support extension

I encountered a simple TypeError while attempting to format my POST body. Below is the function I am using for handleSubmit : const handleSubmit = (values: any, formikHelpers: FormikHelpers<any>) => { const prepareBody = { ...values.customerC ...

A method in TypeScript for defining a type as a combination of interfaces within a union, specified as [one of union of interfaces] & {//attributes}

// Here's a way to define types in TypeScript: interface SudoA { foo: string; } interface SudoB { bar: string; } type Sudo = SudoA | SudoB; type SuperSudo = Sudo & { super: boolean; } const baz: SuperSudo = { } // TypeScript (3. ...

Encountered an issue while trying to build Angular 6 with the --prod flag. The error message states: "ERROR Error: ngIfElse was expecting a TemplateRef, but received 'true' instead

ERROR Error: ngIfElse must be a TemplateRef, but received 'true' HTML File <select class="form-control"> <option selected value="0">Select Manufacturer</option> <option *ngFor="let brand of allMa ...

TypeScript versions 2.3 and 2.4 experiencing issues with generic overloads

After upgrading from typescript 2.2, I encountered an issue with the following example. interface ILayoutResult { id: string; data: any; } interface ILayout{ getResult<T extends ILayoutResult | ILayoutResult[] | void>() :T; } class te ...