Create specific operation types using typescript-mock-data package

Currently involved in a TypeScript project that utilizes typescript-mock-data for mock data generation. Within my codegen.ts file, I have configured the onlyOperationTypes: true setting to specifically generate mock data for operation types.

However, upon executing the code generation process, the desired outcome is not achieved. It appears that while onlyOperationTypes functions properly for graphql.ts files, it ends up removing all values from the mockers file. Despite confirming that other configuration options are functioning as intended.

I have referred to the documentation for typescript-mock-data, yet there seems to be a lack of specific information regarding the utilization of onlyOperationTypes. Has anyone effectively implemented onlyOperationTypes with typescript-mock-data in a TypeScript project? If so, could you offer guidance on how to correctly set up this feature?

const config: CodegenConfig = {
overwrite: true,
hooks: {
    afterAllFileWrite: ['prettier --write'],
},
generates: {
    [TYPES_FILE]: {
        schema: graphQLEndpoint,
        documents: GRAPHQL_DOCUMENT_LOCATIONS,
        plugins: [
            {
                add: {
                    content: [autoGeneratedHeader],
                },
            },
            'typescript',
            'typescript-operations',
            'typescript-react-apollo',
        ],
        config: {
            avoidOptionals: {
                field: true,
                object: true,
                defaultValue: true,
            },
            namingConvention: {
                typeNames: 'keep',
                enumValues: 'change-case-all#upperCase',
            },
            exportFragmentSpreadSubTypes: true,
            preResolveTypes: true,
            // onlyOperationTypes: true,
        },
    },
    [MOCKERS_FILE]: {
        schema: graphQLEndpoint,
        documents: GRAPHQL_DOCUMENT_LOCATIONS,
        plugins: [
            {
                add: {
                    content: [autoGeneratedHeader],
                },
            },
            {
                'typescript-mock-data': {
                    typeNames: 'keep',
                    enumValues: 'change-case-all#upperCase',
                    terminateCircularRelationships: true,
                },
            },
        ],
        config: {
            withHooks: false,
            withComponent: false,
            scalars: {
                Time: 'string',
            },
            typesFile: 'src/services/graphql/generated/graphql.ts',
            avoidOptionals: {
                field: true,
                object: true,
                defaultValue: true,
            },
            namingConvention: {
                typeNames: 'keep',
                enumValues: 'change-case-all#upperCase',
            },
            defaultScalarType: 'unknown',
            preResolveTypes: true,
            // onlyOperationTypes: false,

        },
    },
},
};

Answer №1

For creating simulated online data that aligns with your typescript types, consider utilizing typemocker.tech. It offers a convenient solution for generating mock data.

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

The angular build prod function was expecting 2 arguments, but only 1 argument was provided

When I serve my Angular app normally, everything works fine. But when I try to serve it in production mode, I encounter this error that is leaving me quite perplexed. //error on build: Expected 2 arguments, but got 1. <ion-col class="ion-no-paddin ...

Can anyone help me with coloring Devanagiri diacritics in ReactJS?

I am currently working on a ReactJS project and I have come across an issue. I would like for the diacritic of a Devanagiri letter to be displayed in a different color than the letter it is attached to. For example: क + ी make की I was wondering ...

Is there a way for me to change the value and placeholder attributes on the Clerk's SignIn component?

Within Clerk's documentation, there is guidance on accessing the input field using the appearance prop as demonstrated below: <SignIn appearance={{ elements: { formFieldInput: 'bg-zinc-300/30' } }}/& ...

Using JavaScript to retrieve comma-separated values depending on a specific condition

Hey there, I am encountering a problem with filtering out values from an array of objects. Essentially, I have an array of objects const arr = [ { "id": null, "name": null, "role": "Authorized ...

This type does not possess the designated property

I've encountered a puzzling issue with my code. It seems that the authenticateUser function returns an array structured like this: { success: false, msg: "invalid password" } However, when I attempt to verify if success == false, I receive an er ...

Getting Session from Next-Auth in API Route: A Step-by-Step Guide

When printing my session from Next Auth in a component like this, I can easily see all of its data. const session = useSession(); // ... <p>{JSON.stringify(session)}</p> I am facing an issue where I need to access the content of the session i ...

What mistakes am I making with Typescript and jquery-ui?

Having some difficulty integrating jquery, jquery-ui, and typescript in my project. I used npm to install both jquery and jquery-ui with the following commands: npm install --save jquery npm install --save jquery-ui On my typescript file, I included them ...

The PropTyped property is of an undefined data type

My goal is to create a custom type for an object property, but I am encountering some issues with the connection. Any suggestions on how to resolve this would be greatly appreciated :-) import { defineComponent, PropType } from 'vue' int ...

Does Apollo Federation provide support for a code-first development approach?

I have declarations using 'code-first' approach in my project, but now I want to utilize them as microservices. How can I separate my 'typeDefs' and 'resolvers' following Apollo's 'schema-first' methodology? Is ...

What steps do I need to take to activate the second block in the chain?

I've been working on some code to upload multiple photos to a server. The code can be broken down into three main parts: First, capturing images from the input file and storing them in a variable until the uploadPictures() method is called. Nex ...

How to Utilize FormData in IE9 with Angular 5 and TypeScript Without Ajax or jQuery

Within my Angular 5/Typescript application, there is an UploadFile component structured as follows: component.html .... <form #formUpload id="formUpload"> <input type="file" class="input-file-ghost" (change)="onChangeFile($event.target.files) ...

Guide to integrating a native web component into Vue3

After creating the renderComponent method to display a webcomponent, I attempted to use it in my componentView.vue file. export function renderComponent(el: Element, component: Component,props: VNodeProps,appContext: AppContext){ let vnode: VNode | undefin ...

What is the most efficient way to perform an inline property check and return a boolean value

Can someone help me with optimizing my TypeScript code for a function I have? function test(obj?: { someProperty: string}) { return obj && obj.someProperty; } Although WebStorm indicates that the return value should be a boolean, the TypeScript compil ...

Determine Toggle State in Multiple Ng-Bootstrap Dropdowns in Angular

After receiving a helpful response to my recent question, I have encountered another issue. This time, I am wondering: How can I determine the toggle status in an ng-bootstrap dropdown when multiple dropdowns are present? Attempting to do so only provide ...

Struggling to locate the module in React Native with TypeScript configuration

Currently, I am in the middle of transitioning our react-native project from JavaScript to TypeScript. As I attempt to import old modules, I keep encountering the following error: Cannot find module 'numeral' Oddly enough, the 'numeral&apo ...

Using Typescript and React to render `<span>Text</span>` will only display the text content and not the actual HTML element

My function is a simple one that splits a string and places it inside a styled span in the middle. Here's how it works: splitAndApplyStyledContent(content: string, textType: string, separator: string) { const splittedContent = content.split(separat ...

Tips for retaining the value of a variable when the page is reloaded

I need to store the value of the variable loggedIn, as it determines the behavior of a function in appComponent.html. Can you explain how I can achieve this? Template of app component: <li class="nav-item"> <a class ...

One cannot use a type alias as the parameter type for an index signature. It is recommended to use `[key: string]:` instead

I encountered this issue in my Angular application with the following code snippet: getLocalStreams: () => { [key: Stream['key']]: Stream; }; During compilation, I received the error message: An index signature parameter typ ...

Using Next.js and TypeScript to Send Props to Dynamically Typed Objects

I am in the process of developing an application using Next.js with TypeScript. I have encountered an error message stating Type 'VoidFunctionComponent<ShirtDetailProps>' is missing the following properties when passing props to a component ...

How can I incorporate multiple quality sources into a flowplayer using Angular?

Is there a way to add multiple sources with different qualities like 1080p, 720p etc.? Thank you in advance. flowplayer('#my_player', { src: '../assets/videos/video_1080p.mp4', // title: 'This is just demo&apo ...