crystal icon indicating copy to clipboard operation
crystal copied to clipboard

@graphile/simplify-inflection not using _schemaPrefix

Open danzho opened this issue 10 months ago • 1 comments

Summary

(for v5)

@graphile/simplify-inflection seems to ignore _schemaPrefix.

Steps to reproduce

Here's a plugin that prefixes anything in the foo pg schema with foo_: https://gist.githubusercontent.com/danzho/fce5e8905c06745fb434e1f3a7530ba3/raw/6814300c61d20729af668c9803b5fb0155ed797a/foo-prefix-plugin.ts

With vanilla v5, this works as expected: foo.user -> FooUser. allUsers -> allFooUsers.

However, when you then add the @graphile/simplify-inflection inflector, single-/many-relation queries lose their schema prefix.

Expected results

fooUser {
    fooKids
    fooEmployer
}

Actual results

fooUser {
    kids
    employer
}

Additional context

I could fix this for my needs by overriding singleRelation and _manyRelation to return this.camelCase(relation.remoteResource.name) since relation.remoteResource.name returns schema-prefixed values like "foo_user".

Also, interestingly some relationships are correctly prefixed. In this case, a compound (currency_id, store_id) fk relation:

fooUser {
    fooCurrencyByCurrencyIdAndStoreId # <-- 
    fooKidsByUserId
    fooEmployerByEmployerId
}

Became this when using @graphile/simplify-inflection:

fooUser {
    fooCurrency # <--
    kids
    employer
}

(It stands out since it's the only one with the correct behavior, so there might be a special case that's accidentally working in the current impl)

Also I was sent here from discord: https://discord.com/channels/489127045289476126/498852330754801666/1349098001343189043

danzho avatar Mar 11 '25 19:03 danzho

Simplify inflection plugin does indeed not factor in _schemaPrefix. Doing so would need a major version bump of that plugin, and integration into the tests. I'd be happy for someone to take that on, but I don't see it as a bug and I'm removing it from the V5 milestone.

benjie avatar Aug 25 '25 17:08 benjie