Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changing the houdini output folder #391

Closed
Nukiloco opened this issue Jul 9, 2022 · 16 comments · Fixed by #1386
Closed

Changing the houdini output folder #391

Nukiloco opened this issue Jul 9, 2022 · 16 comments · Fixed by #1386
Labels
Enhancement A new feature or improvement to Houdini's public API 🍎 Low Hanging Fruit

Comments

@Nukiloco
Copy link

Nukiloco commented Jul 9, 2022

I'm currently reading https://www.houdinigraphql.com/api/config and I can't seem to find the field that changes the path or name of the $houdini folder.

@AlecAivazis
Copy link
Collaborator

It's not currently possible to change that path but I would gladly review a PR that adds a runtimePath option if you wanted to give it a shot. We also will want to add another config value for customizing the alias that the generator uses to import things, maybe something like runtimeAlias?

@AlecAivazis AlecAivazis added the Enhancement A new feature or improvement to Houdini's public API label Jul 9, 2022
@Nukiloco
Copy link
Author

Nukiloco commented Jul 9, 2022

I have never worked or contributed on a npm repo before so if I did it would be my first time.
Also I think this is where the $houdini folder comes from.

this.rootDir =
framework === 'sapper'
? path.join(this.projectRoot, 'src', 'node_modules', '$houdini')
: path.join(this.projectRoot, '$houdini')

A lot places in the source code uses the rootDir.
I'm not sure what you mean by runtimeAlias. Do you mean the alias for each import on generated files like import stuff from customAlias?

Also to note, it doesn't seem like the rootDir in the config is exposed in the houdini.config.js file. Or the vsode intellisense doesn't recognize it?

@david-plugge
Copy link
Contributor

@AlecAivazis is there any reason the $houdini folder is created in the project root? If it could be placed anywhere in the src dir we can skip configuring vite to serve the root directory.

allow: ['.'],

@AlecAivazis
Copy link
Collaborator

@Nukiloco That's no problem at all! If you are up for it, I'll help you any way I can. Basically there are two parts to this feature. One part is where the actual ./$houdini directory is written. The actual import resolves using a vite alias so we can leave it up to the user to make sure that $houdini resolves to the custom place they have set. The second part of this feature is the actual text for the alias to use. A user might want to change this to $lib/houdini for example if they don't want to have extra alias in their config and they want to take advantage of the existing $lib alias that SvelteKit. This was a lot of info so feel free to reach out to me on discord if you want a more direct way of talking.

@david-plugge the convention of putting it in root pre-dates SvelteKit requiring the extra vite config to resolve the import. I think the best solution to this problem is to change the way users install houdini to use a SvelteKit/Vite plugin which should let us do the ugly allow stuff behind the scenes

@Nukiloco
Copy link
Author

Nukiloco commented Jul 9, 2022

After reading this, I'm still confused on why there would be two config options here instead of one which should just be a path.

@AlecAivazis
Copy link
Collaborator

Unforuntately we can't have one path that works in both situations because the file system is only accessible through vite aliases ($lib only resolves to ./src/lib because it has been explicitly set up). This means that if we want to be able to support any situation we need to let the user customize both sides of the problem: the actual filepath where things end up and the alias that can be used to import that path. This let's someone configure their setup however they want as long as they are willing to own the alias definition

@david-plugge
Copy link
Contributor

it may work:

// houdini.config.js
/** @type {import('houdini').ConfigFile} \*/
const config = {
	runtimePath: './src/houdini',
	...
};
export default config;
// svelte.config.js
import houdiniConfig from './houdini.config.js'

/** @type {import('@sveltejs/kit').Config} */
const config = {
	preprocess: [
		preprocess(),
		houdini(houdiniConfig)
	],
	kit: {
		alias: houdiniConfig.runtimePath
	}
};
export default config;

That way we could even pass the config to the preprocessor without having to specify the config path (#395)

@jycouet jycouet self-assigned this Jul 15, 2022
@jycouet jycouet removed their assignment Jul 23, 2022
@endigma
Copy link
Contributor

endigma commented Aug 5, 2022

additionally, customizing GQL_ would be nice, some projects have case conventions.

@jycouet
Copy link
Contributor

jycouet commented Aug 5, 2022

You mean to have it lowercase? Or being able to customize "what you want"? 👀

@endigma
Copy link
Contributor

endigma commented Aug 5, 2022

maybe a format string? an option with prefix and case would be good enough

@endigma
Copy link
Contributor

endigma commented Aug 5, 2022

prefix_query_title in snake_case
PREFIX_QUERY_TITLE in MACRO_CASE
prefixQueryTitle in camel
PrefixQueryTitle in Pascal (these two would be the same if prefix was ignored by the case-transformer
prefixquerytitle in flatcase (don't think this is necessary)

would fit into

{
    prefix: string,
    case: "camel" | "snake" | "pascal" | "spinal" ... etc
}

@AlecAivazis
Copy link
Collaborator

prefix_query_title in snake_case

PREFIX_QUERY_TITLE in MACRO_CASE

prefixQueryTitle in camel

PrefixQueryTitle in Pascal (these two would be the same if prefix was ignored by the case-transformer

prefixquerytitle in flatcase (don't think this is necessary)

Would it be crazy to use the examples as the pattern? At least that way it's more descriptive of what will be generated.

I imagine it'd look something like:

{
    pattern: "QueryName",
    // or
    pattern: "GQL_Query_Name"
}

@david-plugge
Copy link
Contributor

Isn´t it sufficient to just add a prefix config option? I´m not sure but is the name is extracted from the Graphql query/mutation... ? If so the prefix should be enough right?

@endigma
Copy link
Contributor

endigma commented Aug 6, 2022

Isn´t it sufficient to just add a prefix config option? I´m not sure but is the name is extracted from the Graphql query/mutation... ? If so the prefix should be enough right?

not sure how this works internally, if the query portion is derived from the query text then yeah just prefix would be good

@endigma
Copy link
Contributor

endigma commented Aug 25, 2022

Now that the #460 tangent is closed, is this planned as well?

@SeppahBaws
Copy link
Collaborator

We'll add this as part of the Houdini 2.0 release

We'll also be changing the default output folder to .houdini/ instead, so that it's next to .svelte-kit/, hidden on posix by default, and it indicates that it's not really something that needs to be committed to git.

For this feature, upgrading an old repo to the new one would either just be updating the type alias in the tsconfig, or adding one line in the houdini config to point to the old $houdini/ directory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement A new feature or improvement to Houdini's public API 🍎 Low Hanging Fruit
Projects
None yet
6 participants