dotansimha / dotansimha/graphql-code-generator-community

[near-operation-file-preset] Ability to customize file name pattern

Open
#478 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
137
Forks
195
Avg merge
6h 20m
Merged PRs (30d)
16

Description

I'm working on integrating near-operation-file-preset for a SvelteKit project. In SvelteKit's filesystem-based router, file names starting with `+` are reserver for `+page.ts` and `+page.svelte` files, which have special meaning.

My goal is that I can use `gql` tags in `+page.ts` and `+page.svelte` files, and have the respective types be generated in an adjacent `__generated__` folder. The issue: If I configure the near-operation-file-preset to set an `extension` like `.generated.ts`, it creates files named like `+page.generated.ts`. This causes an error in SvelteKit complaining about `+` being a reserved character.

If I set `filename` in the plugin config, I can create a single generated file, but when there are multiple different files with `gql` tags in the same directory, it only creates a single types file with only one of the original file's operations contained within. It looks like during the generation process, it generates types for all the files in the directory, but overwrites the output each time, resulting in only having type definitions for one of the source files.

What I'm looking for is some way to customize the file name of generated files beyond `extension`. Either a `prefix` key, or perhaps even the ability to set a custom JS function for transforming names akin to `namingConvention` would do.

Or maybe I'm just missing an existing way around this issue?

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reading the near-operation-file-preset configuration handling for extension and filename, then reproduce the case with +page.ts, +page.svelte, and multiple files containing gql tags. Done means generated filenames can avoid SvelteKit's reserved + names while preserving operations from every source file instead of overwriting them.

Written by the indexing model from the issue text.

Assessment

Tech stack
graphql, typescript
Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.